diff --git a/cli/src/tests/corpus_test.rs b/cli/src/tests/corpus_test.rs index f7b4815b..9e4729d3 100644 --- a/cli/src/tests/corpus_test.rs +++ b/cli/src/tests/corpus_test.rs @@ -1,7 +1,7 @@ use super::helpers::{ allocations, 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, random::Rand, scope_sequence::ScopeSequence, @@ -104,6 +104,7 @@ fn test_language_corpus(start_seed: usize, language_name: &str) { let mut failure_count = 0; 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 { println!(" start seed: {}", start_seed); @@ -175,6 +176,10 @@ fn test_language_corpus(start_seed: usize, language_name: &str) { println!(" seed: {}", seed); } + if dump_edits { + fs::write(SCRATCH_BASE_DIR.join(format!("{seed}.edit")), &input).unwrap(); + } + if *LOG_GRAPH_ENABLED { eprintln!("{}\n", String::from_utf8_lossy(&input)); } diff --git a/cli/src/tests/helpers/dirs.rs b/cli/src/tests/helpers/dirs.rs index e4f220ea..7ff48ab7 100644 --- a/cli/src/tests/helpers/dirs.rs +++ b/cli/src/tests/helpers/dirs.rs @@ -1,9 +1,14 @@ lazy_static! { - 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"); - static ref HEADER_DIR: PathBuf = ROOT_DIR.join("lib").join("include"); - static ref GRAMMARS_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures").join("grammars"); - static ref SCRATCH_DIR: PathBuf = { + pub static ref ROOT_DIR: PathBuf = PathBuf::from(env!("CARGO_MANIFEST_DIR")).parent().unwrap().to_owned(); + pub static ref FIXTURES_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures"); + pub static ref HEADER_DIR: PathBuf = ROOT_DIR.join("lib").join("include"); + pub static ref GRAMMARS_DIR: PathBuf = ROOT_DIR.join("test").join("fixtures").join("grammars"); + 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 let vendor = if cfg!(target_vendor = "apple") { "apple" @@ -34,7 +39,7 @@ lazy_static! { }; 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(); result };