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 = { version = "0.1.37", optional = true }
|
||||||
tracing-opentelemetry = { version = "0.20.0", optional = true }
|
tracing-opentelemetry = { version = "0.20.0", optional = true }
|
||||||
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
|
tracing-subscriber = { version = "0.3.17", optional = true, features = ["env-filter"] }
|
||||||
|
walkdir = { version = "2.3.3", optional = true }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
walkdir = "2.3.3"
|
walkdir = "2.3.3"
|
||||||
@ -54,7 +55,7 @@ walkdir = "2.3.3"
|
|||||||
[features]
|
[features]
|
||||||
default = ["compare", "foreign_document_test"]
|
default = ["compare", "foreign_document_test"]
|
||||||
compare = []
|
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"]
|
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.
|
# 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 organic::compare::run_compare_on_file;
|
||||||
use tokio::sync::Semaphore;
|
use tokio::sync::Semaphore;
|
||||||
use tokio::task::JoinError;
|
use tokio::task::JoinError;
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
#[cfg(feature = "tracing")]
|
#[cfg(feature = "tracing")]
|
||||||
use crate::init_tracing::init_telemetry;
|
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"))]
|
#[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 single_file = TestConfig::SingleFile(SingleFile {
|
let single_file = TestConfig::SingleFile(SingleFile {
|
||||||
|
name: "foo".to_owned(),
|
||||||
file_path: PathBuf::from("/tmp/test.org"),
|
file_path: PathBuf::from("/tmp/test.org"),
|
||||||
});
|
});
|
||||||
// let result = single_file.run_test().await;
|
// let result = single_file.run_test().await;
|
||||||
@ -57,6 +59,32 @@ async fn main_body() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
Ok(())
|
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);
|
static TEST_PERMITS: Semaphore = Semaphore::const_new(8);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -73,6 +101,7 @@ struct TestLayer {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct SingleFile {
|
struct SingleFile {
|
||||||
|
name: String,
|
||||||
file_path: PathBuf,
|
file_path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,6 +119,7 @@ struct ResultLayer {
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct SingleFileResult {
|
struct SingleFileResult {
|
||||||
|
name: String,
|
||||||
file_path: PathBuf,
|
file_path: PathBuf,
|
||||||
status: TestStatus,
|
status: TestStatus,
|
||||||
}
|
}
|
||||||
@ -119,6 +149,7 @@ impl SingleFile {
|
|||||||
let _permit = TEST_PERMITS.acquire().await.unwrap();
|
let _permit = TEST_PERMITS.acquire().await.unwrap();
|
||||||
let result = run_compare_on_file(&self.file_path);
|
let result = run_compare_on_file(&self.file_path);
|
||||||
Ok(SingleFileResult {
|
Ok(SingleFileResult {
|
||||||
|
name: self.name,
|
||||||
file_path: self.file_path,
|
file_path: self.file_path,
|
||||||
status: if result.is_ok() {
|
status: if result.is_ok() {
|
||||||
TestStatus::Pass
|
TestStatus::Pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user