Working on invoking the tests.

This commit is contained in:
Tom Alexander 2023-10-08 17:17:32 -04:00
parent d7e870cba1
commit a1f8cbe079
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -37,31 +37,19 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))] #[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
async fn main_body() -> Result<(), Box<dyn std::error::Error>> { async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
let args = std::env::args().skip(1); let test_config = TestConfig::TestLayer(TestLayer {
if args.is_empty() { name: "foo",
let org_contents = read_stdin_to_string()?; children: vec![TestConfig::SingleFile(SingleFile {
run_anonymous_compare(org_contents) file_path: Path::new("/tmp/test.org"),
} else { })],
for arg in args { });
run_compare_on_file(arg)? Ok(())
}
Ok(())
}
}
fn read_stdin_to_string() -> Result<String, Box<dyn std::error::Error>> {
let mut stdin_contents = String::new();
std::io::stdin()
.lock()
.read_to_string(&mut stdin_contents)?;
Ok(stdin_contents)
} }
#[derive(Debug)] #[derive(Debug)]
enum TestConfig<'s> { enum TestConfig<'s> {
TestLayer(TestLayer<'s>), TestLayer(TestLayer<'s>),
SingleFile(SingleFile<'s>), SingleFile(SingleFile<'s>),
AnonymousFile(AnonymousFile),
} }
#[derive(Debug)] #[derive(Debug)]
@ -72,19 +60,13 @@ struct TestLayer<'s> {
#[derive(Debug)] #[derive(Debug)]
struct SingleFile<'s> { struct SingleFile<'s> {
file_path: &'s str, file_path: &'s Path,
}
#[derive(Debug)]
struct AnonymousFile {
name: String,
} }
#[derive(Debug)] #[derive(Debug)]
enum TestResult<'s> { enum TestResult<'s> {
ResultLayer(ResultLayer<'s>), ResultLayer(ResultLayer<'s>),
SingleFileResult(SingleFileResult<'s>), SingleFileResult(SingleFileResult<'s>),
AnonymousFileResult(AnonymousFileResult),
} }
#[derive(Debug)] #[derive(Debug)]
@ -95,18 +77,41 @@ struct ResultLayer<'s> {
#[derive(Debug)] #[derive(Debug)]
struct SingleFileResult<'s> { struct SingleFileResult<'s> {
name: &'s str, file_path: &'s Path,
status: TestStatus,
} }
#[derive(Debug)] #[derive(Debug)]
struct AnonymousFileResult { pub(crate) enum TestStatus {
name: String, Good,
Bad,
}
impl<'s> TestConfig<'s> {
async fn run_test(&self) -> TestResult<'s> {
match self {
TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await),
TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await),
}
}
} }
impl<'s> SingleFile<'s> { impl<'s> SingleFile<'s> {
fn run_test(&self) -> SingleFileResult<'s> { async fn run_test(&self) -> SingleFileResult<'s> {
let result = run_compare_on_file(self.file_path); let result = run_compare_on_file(self.file_path);
// foo SingleFileResult {
file_path: self.file_path,
status: if result.is_ok() {
TestStatus::Good
} else {
TestStatus::Bad
},
}
}
}
impl<'s> TestLayer<'s> {
async fn run_test(&self) -> ResultLayer<'s> {
todo!() todo!()
} }
} }