test: add TREE_SITTER_DUMP_EDITS env var to dump corpus edits
It dumps edits to the `target/scratch` folder in a format like `<SEED>.edit`
This commit is contained in:
parent
e0e0763d29
commit
caaa533b8d
2 changed files with 17 additions and 7 deletions
|
|
@ -1,7 +1,7 @@
|
||||||
use super::helpers::{
|
use super::helpers::{
|
||||||
allocations,
|
allocations,
|
||||||
edits::{get_random_edit, invert_edit},
|
edits::{get_random_edit, invert_edit},
|
||||||
fixtures::{fixtures_dir, get_language, get_test_language},
|
fixtures::{fixtures_dir, get_language, get_test_language, SCRATCH_BASE_DIR},
|
||||||
new_seed,
|
new_seed,
|
||||||
random::Rand,
|
random::Rand,
|
||||||
scope_sequence::ScopeSequence,
|
scope_sequence::ScopeSequence,
|
||||||
|
|
@ -104,6 +104,7 @@ fn test_language_corpus(start_seed: usize, language_name: &str) {
|
||||||
let mut failure_count = 0;
|
let mut failure_count = 0;
|
||||||
|
|
||||||
let log_seed = env::var("TREE_SITTER_LOG_SEED").is_ok();
|
let log_seed = env::var("TREE_SITTER_LOG_SEED").is_ok();
|
||||||
|
let dump_edits = env::var("TREE_SITTER_DUMP_EDITS").is_ok();
|
||||||
|
|
||||||
if log_seed {
|
if log_seed {
|
||||||
println!(" start seed: {}", start_seed);
|
println!(" start seed: {}", start_seed);
|
||||||
|
|
@ -175,6 +176,10 @@ fn test_language_corpus(start_seed: usize, language_name: &str) {
|
||||||
println!(" seed: {}", seed);
|
println!(" seed: {}", seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if dump_edits {
|
||||||
|
fs::write(SCRATCH_BASE_DIR.join(format!("{seed}.edit")), &input).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
if *LOG_GRAPH_ENABLED {
|
if *LOG_GRAPH_ENABLED {
|
||||||
eprintln!("{}\n", String::from_utf8_lossy(&input));
|
eprintln!("{}\n", String::from_utf8_lossy(&input));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,14 @@
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref ROOT_DIR: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")).parent().unwrap().to_owned();
|
pub static ref ROOT_DIR: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")).parent().unwrap().to_owned();
|
||||||
static ref FIXTURES_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures");
|
pub static ref FIXTURES_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures");
|
||||||
static ref HEADER_DIR: PathBuf = ROOT_DIR.join("lib").join("include");
|
pub static ref HEADER_DIR: PathBuf = ROOT_DIR.join("lib").join("include");
|
||||||
static ref GRAMMARS_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures").join("grammars");
|
pub static ref GRAMMARS_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures").join("grammars");
|
||||||
static ref SCRATCH_DIR: PathBuf = {
|
pub static ref SCRATCH_BASE_DIR: PathBuf = {
|
||||||
|
let result = ROOT_DIR.join("target").join("scratch");
|
||||||
|
fs::create_dir_all(&result).unwrap();
|
||||||
|
result
|
||||||
|
};
|
||||||
|
pub static ref SCRATCH_DIR: PathBuf = {
|
||||||
// https://doc.rust-lang.org/reference/conditional-compilation.html
|
// https://doc.rust-lang.org/reference/conditional-compilation.html
|
||||||
let vendor = if cfg!(target_vendor = "apple") {
|
let vendor = if cfg!(target_vendor = "apple") {
|
||||||
"apple"
|
"apple"
|
||||||
|
|
@ -34,7 +39,7 @@ lazy_static! {
|
||||||
};
|
};
|
||||||
|
|
||||||
let machine = format!("{}-{}-{}-{}-{}", std::env::consts::ARCH, std::env::consts::OS, vendor, env, endian);
|
let machine = format!("{}-{}-{}-{}-{}", std::env::consts::ARCH, std::env::consts::OS, vendor, env, endian);
|
||||||
let result = ROOT_DIR.join("target").join("scratch").join(machine);
|
let result = SCRATCH_BASE_DIR.join(machine);
|
||||||
fs::create_dir_all(&result).unwrap();
|
fs::create_dir_all(&result).unwrap();
|
||||||
result
|
result
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue