From 5f93cabff55858e741c579b0a4ed2fbc1d54ff00 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Wed, 11 Oct 2023 19:41:32 -0400 Subject: [PATCH] Hit recursive async. --- src/bin_foreign_document_test.rs | 73 +++++++++++++++++++------------- 1 file changed, 44 insertions(+), 29 deletions(-) diff --git a/src/bin_foreign_document_test.rs b/src/bin_foreign_document_test.rs index fda831e3..44e76ba3 100644 --- a/src/bin_foreign_document_test.rs +++ b/src/bin_foreign_document_test.rs @@ -2,6 +2,7 @@ #![feature(exact_size_is_empty)] use std::io::Read; use std::path::Path; +use std::path::PathBuf; use organic::compare::run_anonymous_compare; use organic::compare::run_compare_on_file; @@ -37,47 +38,53 @@ fn main() -> Result<(), Box> { #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] async fn main_body() -> Result<(), Box> { - let test_config = TestConfig::TestLayer(TestLayer { - name: "foo", - children: vec![TestConfig::SingleFile(SingleFile { - file_path: Path::new("/tmp/test.org"), - })], + let single_file = TestConfig::SingleFile(SingleFile { + file_path: PathBuf::from("/tmp/test.org"), }); + // let result = single_file.run_test().await; + let result = tokio::spawn(single_file.run_test()); + println!("{:?}", result); + // let test_config = TestConfig::TestLayer(TestLayer { + // name: "foo", + // children: vec![TestConfig::SingleFile(SingleFile { + // file_path: Path::new("/tmp/test.org"), + // })], + // }); Ok(()) } #[derive(Debug)] -enum TestConfig<'s> { - TestLayer(TestLayer<'s>), - SingleFile(SingleFile<'s>), +enum TestConfig { + TestLayer(TestLayer), + SingleFile(SingleFile), } #[derive(Debug)] -struct TestLayer<'s> { - name: &'s str, - children: Vec>, +struct TestLayer { + name: String, + children: Vec, } #[derive(Debug)] -struct SingleFile<'s> { - file_path: &'s Path, +struct SingleFile { + file_path: PathBuf, } #[derive(Debug)] -enum TestResult<'s> { - ResultLayer(ResultLayer<'s>), - SingleFileResult(SingleFileResult<'s>), +enum TestResult { + ResultLayer(ResultLayer), + SingleFileResult(SingleFileResult), } #[derive(Debug)] -struct ResultLayer<'s> { - name: &'s str, - children: Vec>, +struct ResultLayer { + name: String, + children: Vec, } #[derive(Debug)] -struct SingleFileResult<'s> { - file_path: &'s Path, +struct SingleFileResult { + file_path: PathBuf, status: TestStatus, } @@ -87,8 +94,8 @@ pub(crate) enum TestStatus { Bad, } -impl<'s> TestConfig<'s> { - async fn run_test(&self) -> TestResult<'s> { +impl TestConfig { + async fn run_test(self) -> TestResult { match self { TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await), TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await), @@ -96,9 +103,9 @@ impl<'s> TestConfig<'s> { } } -impl<'s> SingleFile<'s> { - async fn run_test(&self) -> SingleFileResult<'s> { - let result = run_compare_on_file(self.file_path); +impl SingleFile { + async fn run_test(self) -> SingleFileResult { + let result = run_compare_on_file(&self.file_path); SingleFileResult { file_path: self.file_path, status: if result.is_ok() { @@ -110,8 +117,16 @@ impl<'s> SingleFile<'s> { } } -impl<'s> TestLayer<'s> { - async fn run_test(&self) -> ResultLayer<'s> { - todo!() +impl TestLayer { + async fn run_test(self) -> ResultLayer { + let mut children = Vec::with_capacity(self.children.len()); + for config in self.children { + let result = config.run_test().await; + children.push(result); + } + ResultLayer { + name: self.name, + children, + } } }