From 3e15ff9a8d1b0f0c54bd14101e6cde677d4aecda Mon Sep 17 00:00:00 2001 From: Jan Ferdinand Sauer Date: Wed, 5 Jun 2024 19:27:39 +0200 Subject: [PATCH] refactor(test): Fail if spec needs updating While the previous chain of commits eliminates the need to copy-&-paste the generated specification, it is important to enforce an up-to-date specification even if the test suite runs in CI. --- triton-vm/src/table/master_table.rs | 46 ++++++++++++++++------------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/triton-vm/src/table/master_table.rs b/triton-vm/src/table/master_table.rs index 4f1cc4342..6d1009e6f 100644 --- a/triton-vm/src/table/master_table.rs +++ b/triton-vm/src/table/master_table.rs @@ -1529,29 +1529,33 @@ mod tests { #[test] fn update_arithmetization_overview() { - let table_overview = generate_table_overview(); - let constraint_overview = generate_constraints_overview(); - let tasm_air_overview = generate_tasm_air_evaluation_cost_overview(); + let spec_snippets = [ + generate_table_overview(), + generate_constraints_overview(), + generate_tasm_air_evaluation_cost_overview(), + ]; // current directory is triton-vm/triton-vm/ - let file_path = Path::new("../specification/src/arithmetization-overview.md"); - update_spec_with(file_path, table_overview); - update_spec_with(file_path, constraint_overview); - update_spec_with(file_path, tasm_air_overview); - } - - fn update_spec_with(spec_path: &Path, snippet: SpecSnippet) { - let spec = fs::read_to_string(spec_path).unwrap().replace("\r\n", "\n"); - let start = spec.find(snippet.start_marker).unwrap(); - let stop = spec.find(snippet.stop_marker).unwrap(); - let new_contents = format!( - "{}{}\n{}{}", - &spec[..start], - snippet.start_marker, - snippet.snippet, - &spec[stop..] - ); - fs::write(spec_path, new_contents).unwrap(); + let spec_path = Path::new("../specification/src/arithmetization-overview.md"); + let current_spec = fs::read_to_string(spec_path).unwrap().replace("\r\n", "\n"); + let mut new_spec = current_spec.clone(); + for snippet in spec_snippets { + let start = new_spec.find(snippet.start_marker).unwrap(); + let stop = new_spec.find(snippet.stop_marker).unwrap(); + new_spec = format!( + "{}{}\n{}{}", + &new_spec[..start], + snippet.start_marker, + snippet.snippet, + &new_spec[stop..] + ); + } + fs::write(spec_path, new_spec.clone()).unwrap(); + + if current_spec != new_spec { + println!("Updated arithmetization overview to be:\n\n{new_spec}"); + panic!("The arithmetization overview was updated. Please commit the changes."); + } } fn generate_table_overview() -> SpecSnippet {