Skip to content

Commit

Permalink
refactor(test): Fail if spec needs updating
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jan-ferdinand committed Jun 5, 2024
1 parent 81e2a73 commit 3e15ff9
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions triton-vm/src/table/master_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 3e15ff9

Please sign in to comment.