Merge branch 'integration_tests'
This commit is contained in:
commit
cb38ffc520
@ -5,6 +5,10 @@ edition = "2021"
|
|||||||
license = "0BSD"
|
license = "0BSD"
|
||||||
default-run = "toy"
|
default-run = "toy"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "organic"
|
||||||
|
path = "src/lib.rs"
|
||||||
|
|
||||||
[[bin]]
|
[[bin]]
|
||||||
name = "toy"
|
name = "toy"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
@ -23,6 +27,9 @@ tracing = "0.1.37"
|
|||||||
tracing-opentelemetry = "0.17.2"
|
tracing-opentelemetry = "0.17.2"
|
||||||
tracing-subscriber = {version="0.3.16", features=["env-filter"]}
|
tracing-subscriber = {version="0.3.16", features=["env-filter"]}
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
walkdir = "2.3.3"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["compare"]
|
default = ["compare"]
|
||||||
compare = []
|
compare = []
|
||||||
|
6
Makefile
6
Makefile
@ -20,7 +20,11 @@ clean:
|
|||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
> cargo test --bin toy
|
> cargo test --lib
|
||||||
|
|
||||||
|
.PHONY: integrationtest
|
||||||
|
integrationtest:
|
||||||
|
> cargo test --no-fail-fast --test test_loader
|
||||||
|
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run:
|
run:
|
||||||
|
58
build.rs
Normal file
58
build.rs
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
use std::env;
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Write;
|
||||||
|
use std::path::Path;
|
||||||
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let out_dir = env::var("OUT_DIR").unwrap();
|
||||||
|
let destination = Path::new(&out_dir).join("tests.rs");
|
||||||
|
let mut test_file = File::create(&destination).unwrap();
|
||||||
|
|
||||||
|
write_header(&mut test_file);
|
||||||
|
|
||||||
|
let test_files = WalkDir::new("org_mode_samples")
|
||||||
|
.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();
|
||||||
|
for test in test_files {
|
||||||
|
write_test(&mut test_file, &test);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_test(test_file: &mut File, test: &walkdir::DirEntry) {
|
||||||
|
let test_name = test.path().strip_prefix("org_mode_samples/").expect("Paths should be under org_mode_samples/").to_string_lossy().to_lowercase().strip_suffix(".org").expect("Should have .org extension").replace("/", "_");
|
||||||
|
|
||||||
|
|
||||||
|
write!(
|
||||||
|
test_file,
|
||||||
|
include_str!("./tests/test_template"),
|
||||||
|
name = test_name,
|
||||||
|
path = test.path().display()
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
fn write_header(test_file: &mut File) {
|
||||||
|
write!(
|
||||||
|
test_file,
|
||||||
|
r#"
|
||||||
|
#[feature(exit_status_error)]
|
||||||
|
use organic::compare_document;
|
||||||
|
use organic::document;
|
||||||
|
use organic::emacs_parse_org_document;
|
||||||
|
use organic::sexp;
|
||||||
|
|
||||||
|
"#
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
@ -1,36 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
#
|
|
||||||
# Check that the official org-mode parser and this implementation of an org-mode parser agree on how the sample org-mode documents should be parsed.
|
|
||||||
set -euo pipefail
|
|
||||||
IFS=$'\n\t'
|
|
||||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
||||||
cd "$DIR"
|
|
||||||
|
|
||||||
: ${org_dir:="$DIR/../org_mode_samples"}
|
|
||||||
: ${compare_bin:="$DIR/../target/debug/org_compare"}
|
|
||||||
|
|
||||||
test_files=$(find $org_dir -type f -name '*.org' | sort)
|
|
||||||
|
|
||||||
cargo build --bin org_compare
|
|
||||||
|
|
||||||
pass=0
|
|
||||||
fail=0
|
|
||||||
|
|
||||||
|
|
||||||
while read test_file; do
|
|
||||||
print_path=$(realpath --relative-to="$org_dir" "$test_file")
|
|
||||||
set +e
|
|
||||||
diff_results=$("$compare_bin" "$test_file")
|
|
||||||
diff_status=$?
|
|
||||||
set -e
|
|
||||||
if [ $diff_status -eq 0 ]; then
|
|
||||||
echo "GOOD $print_path"
|
|
||||||
pass=$((pass + 1))
|
|
||||||
else
|
|
||||||
echo "BAD $print_path"
|
|
||||||
fail=$((fail + 1))
|
|
||||||
fi
|
|
||||||
done<<<"$test_files"
|
|
||||||
|
|
||||||
total=$((pass + fail))
|
|
||||||
(>&2 echo "Tests passed: $pass/$total")
|
|
8
src/lib.rs
Normal file
8
src/lib.rs
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#![feature(round_char_boundary)]
|
||||||
|
#![feature(exit_status_error)]
|
||||||
|
mod parser;
|
||||||
|
mod compare;
|
||||||
|
pub use parser::*;
|
||||||
|
pub use compare::emacs_parse_org_document;
|
||||||
|
pub use compare::sexp;
|
||||||
|
pub use compare::compare_document;
|
1
tests/test_loader.rs
Normal file
1
tests/test_loader.rs
Normal file
@ -0,0 +1 @@
|
|||||||
|
include!(concat!(env!("OUT_DIR"), "/tests.rs"));
|
17
tests/test_template
Normal file
17
tests/test_template
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#[test]
|
||||||
|
fn {name}() {{
|
||||||
|
let todo_org_path = "{path}";
|
||||||
|
let org_contents = std::fs::read_to_string(todo_org_path).expect("Read org file.");
|
||||||
|
let org_sexp = emacs_parse_org_document(todo_org_path).expect("Use emacs to parse org file.");
|
||||||
|
println!("{{}}", org_sexp);
|
||||||
|
let (_remaining, parsed_sexp) = sexp(org_sexp.as_str()).expect("Sexp Parse failure");
|
||||||
|
let (remaining, rust_parsed) = document(org_contents.as_str()).expect("Org Parse failure");
|
||||||
|
println!("{{:#?}}", rust_parsed);
|
||||||
|
let diff_result =
|
||||||
|
compare_document(&parsed_sexp, &rust_parsed).expect("Compare parsed documents.");
|
||||||
|
diff_result
|
||||||
|
.print()
|
||||||
|
.expect("Print document parse tree diff.");
|
||||||
|
assert!(!diff_result.is_bad());
|
||||||
|
assert_eq!(remaining, "");
|
||||||
|
}}
|
Loading…
Reference in New Issue
Block a user