2023-10-07 04:35:21 +00:00
|
|
|
#![feature(round_char_boundary)]
|
|
|
|
#![feature(exact_size_is_empty)]
|
|
|
|
use std::io::Read;
|
2023-10-08 11:54:21 +00:00
|
|
|
use std::path::Path;
|
2023-10-11 23:41:32 +00:00
|
|
|
use std::path::PathBuf;
|
2023-10-07 04:35:21 +00:00
|
|
|
|
2023-10-11 23:47:30 +00:00
|
|
|
use futures::future::BoxFuture;
|
|
|
|
use futures::future::FutureExt;
|
|
|
|
use futures::stream::FuturesUnordered;
|
2023-10-07 04:35:21 +00:00
|
|
|
use organic::compare::run_anonymous_compare;
|
|
|
|
use organic::compare::run_compare_on_file;
|
|
|
|
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
use crate::init_tracing::init_telemetry;
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
use crate::init_tracing::shutdown_telemetry;
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
mod init_tracing;
|
|
|
|
|
|
|
|
#[cfg(not(feature = "tracing"))]
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let rt = tokio::runtime::Runtime::new()?;
|
|
|
|
let result = rt.block_on(async {
|
2023-10-07 05:13:26 +00:00
|
|
|
let main_body_result = main_body().await;
|
2023-10-07 04:35:21 +00:00
|
|
|
main_body_result
|
|
|
|
});
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "tracing")]
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
let rt = tokio::runtime::Runtime::new()?;
|
|
|
|
let result = rt.block_on(async {
|
|
|
|
init_telemetry()?;
|
2023-10-07 05:13:26 +00:00
|
|
|
let main_body_result = main_body().await;
|
2023-10-07 04:35:21 +00:00
|
|
|
shutdown_telemetry()?;
|
|
|
|
main_body_result
|
|
|
|
});
|
|
|
|
result
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
2023-10-07 05:13:26 +00:00
|
|
|
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
2023-10-11 23:41:32 +00:00
|
|
|
let single_file = TestConfig::SingleFile(SingleFile {
|
|
|
|
file_path: PathBuf::from("/tmp/test.org"),
|
2023-10-08 21:17:32 +00:00
|
|
|
});
|
2023-10-11 23:47:30 +00:00
|
|
|
let mut futs = FuturesUnordered::new();
|
2023-10-11 23:41:32 +00:00
|
|
|
// let result = single_file.run_test().await;
|
2023-10-11 23:47:30 +00:00
|
|
|
let result = tokio::spawn(single_file.run_test()).await;
|
2023-10-11 23:41:32 +00:00
|
|
|
println!("{:?}", result);
|
|
|
|
// let test_config = TestConfig::TestLayer(TestLayer {
|
|
|
|
// name: "foo",
|
|
|
|
// children: vec![TestConfig::SingleFile(SingleFile {
|
|
|
|
// file_path: Path::new("/tmp/test.org"),
|
|
|
|
// })],
|
|
|
|
// });
|
2023-10-08 21:17:32 +00:00
|
|
|
Ok(())
|
2023-10-07 04:35:21 +00:00
|
|
|
}
|
2023-10-07 05:13:26 +00:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-10-11 23:41:32 +00:00
|
|
|
enum TestConfig {
|
|
|
|
TestLayer(TestLayer),
|
|
|
|
SingleFile(SingleFile),
|
2023-10-07 05:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-10-11 23:41:32 +00:00
|
|
|
struct TestLayer {
|
|
|
|
name: String,
|
|
|
|
children: Vec<TestConfig>,
|
2023-10-07 05:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-10-11 23:41:32 +00:00
|
|
|
struct SingleFile {
|
|
|
|
file_path: PathBuf,
|
2023-10-08 11:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-10-11 23:41:32 +00:00
|
|
|
enum TestResult {
|
|
|
|
ResultLayer(ResultLayer),
|
|
|
|
SingleFileResult(SingleFileResult),
|
2023-10-08 11:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-10-11 23:41:32 +00:00
|
|
|
struct ResultLayer {
|
|
|
|
name: String,
|
|
|
|
children: Vec<TestResult>,
|
2023-10-08 11:54:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-10-11 23:41:32 +00:00
|
|
|
struct SingleFileResult {
|
|
|
|
file_path: PathBuf,
|
2023-10-08 21:17:32 +00:00
|
|
|
status: TestStatus,
|
2023-10-07 05:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
2023-10-08 21:17:32 +00:00
|
|
|
pub(crate) enum TestStatus {
|
|
|
|
Good,
|
|
|
|
Bad,
|
|
|
|
}
|
|
|
|
|
2023-10-11 23:41:32 +00:00
|
|
|
impl TestConfig {
|
2023-10-11 23:47:30 +00:00
|
|
|
fn run_test(self) -> BoxFuture<'static, TestResult> {
|
|
|
|
async move {
|
|
|
|
match self {
|
|
|
|
TestConfig::TestLayer(test) => TestResult::ResultLayer(test.run_test().await),
|
|
|
|
TestConfig::SingleFile(test) => TestResult::SingleFileResult(test.run_test().await),
|
|
|
|
}
|
2023-10-08 21:17:32 +00:00
|
|
|
}
|
2023-10-11 23:47:30 +00:00
|
|
|
.boxed()
|
2023-10-08 21:17:32 +00:00
|
|
|
}
|
2023-10-07 05:13:26 +00:00
|
|
|
}
|
2023-10-08 11:54:21 +00:00
|
|
|
|
2023-10-11 23:41:32 +00:00
|
|
|
impl SingleFile {
|
|
|
|
async fn run_test(self) -> SingleFileResult {
|
|
|
|
let result = run_compare_on_file(&self.file_path);
|
2023-10-08 21:17:32 +00:00
|
|
|
SingleFileResult {
|
|
|
|
file_path: self.file_path,
|
|
|
|
status: if result.is_ok() {
|
|
|
|
TestStatus::Good
|
|
|
|
} else {
|
|
|
|
TestStatus::Bad
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-11 23:41:32 +00:00
|
|
|
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,
|
|
|
|
}
|
2023-10-08 11:54:21 +00:00
|
|
|
}
|
|
|
|
}
|