Write a function to compare all org-mode files in a directory.
This commit is contained in:
parent
3927889e66
commit
8a26965e14
@ -47,6 +47,7 @@ tokio = { version = "1.30.0", optional = true, default-features = false, feature
|
||||
tracing = { version = "0.1.37", optional = true }
|
||||
tracing-opentelemetry = { version = "0.20.0", optional = true }
|
||||
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
|
||||
walkdir = { version = "2.3.3", optional = true }
|
||||
|
||||
[build-dependencies]
|
||||
walkdir = "2.3.3"
|
||||
@ -54,7 +55,7 @@ walkdir = "2.3.3"
|
||||
[features]
|
||||
default = ["compare", "foreign_document_test"]
|
||||
compare = []
|
||||
foreign_document_test = ["compare", "dep:tokio", "dep:futures", "tokio/sync"]
|
||||
foreign_document_test = ["compare", "dep:tokio", "dep:futures", "tokio/sync", "dep:walkdir"]
|
||||
tracing = ["dep:opentelemetry", "dep:opentelemetry-otlp", "dep:opentelemetry-semantic-conventions", "dep:tokio", "dep:tracing", "dep:tracing-opentelemetry", "dep:tracing-subscriber"]
|
||||
|
||||
# Optimized build for any sort of release.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user