Write a function to compare all org-mode files in a directory.
This commit is contained in:
@@ -10,6 +10,7 @@ use organic::compare::run_anonymous_compare;
|
||||
use organic::compare::run_compare_on_file;
|
||||
use tokio::sync::Semaphore;
|
||||
use tokio::task::JoinError;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
#[cfg(feature = "tracing")]
|
||||
use crate::init_tracing::init_telemetry;
|
||||
@@ -43,6 +44,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
#[cfg_attr(feature = "tracing", tracing::instrument(ret, level = "debug"))]
|
||||
async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let single_file = TestConfig::SingleFile(SingleFile {
|
||||
name: "foo".to_owned(),
|
||||
file_path: PathBuf::from("/tmp/test.org"),
|
||||
});
|
||||
// let result = single_file.run_test().await;
|
||||
@@ -57,6 +59,32 @@ async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compare_all_org_document<P: AsRef<Path>>(root_dir: P) -> impl Iterator<Item = TestConfig> {
|
||||
let root_dir = root_dir.as_ref();
|
||||
let test_files = WalkDir::new(root_dir)
|
||||
.into_iter()
|
||||
.filter(|e| match e {
|
||||
Ok(dir_entry) => {
|
||||
dir_entry.file_type().is_file()
|
||||
&& Path::new(dir_entry.file_name())
|
||||
.extension()
|
||||
.map(|ext| ext.to_ascii_lowercase() == "org")
|
||||
.unwrap_or(false)
|
||||
}
|
||||
Err(_) => true,
|
||||
})
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.unwrap();
|
||||
let test_configs = test_files.into_iter().map(|test_file| {
|
||||
let name = test_file.path().as_os_str().to_string_lossy().into_owned();
|
||||
TestConfig::SingleFile(SingleFile {
|
||||
name,
|
||||
file_path: test_file.into_path(),
|
||||
})
|
||||
});
|
||||
test_configs
|
||||
}
|
||||
|
||||
static TEST_PERMITS: Semaphore = Semaphore::const_new(8);
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -73,6 +101,7 @@ struct TestLayer {
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SingleFile {
|
||||
name: String,
|
||||
file_path: PathBuf,
|
||||
}
|
||||
|
||||
@@ -90,6 +119,7 @@ struct ResultLayer {
|
||||
|
||||
#[derive(Debug)]
|
||||
struct SingleFileResult {
|
||||
name: String,
|
||||
file_path: PathBuf,
|
||||
status: TestStatus,
|
||||
}
|
||||
@@ -119,6 +149,7 @@ impl SingleFile {
|
||||
let _permit = TEST_PERMITS.acquire().await.unwrap();
|
||||
let result = run_compare_on_file(&self.file_path);
|
||||
Ok(SingleFileResult {
|
||||
name: self.name,
|
||||
file_path: self.file_path,
|
||||
status: if result.is_ok() {
|
||||
TestStatus::Pass
|
||||
|
||||
Reference in New Issue
Block a user