Macro output_cmp

Source
macro_rules! output_cmp {
    ($path:expr, $out_str:expr) => { ... };
}
Expand description

Used in tests for storing and comparing string representations in files.

§Example

let states = lr_states_for_grammar(&grammar, &settings);
output_cmp!("grammar.expected.txt", format!("{states:#?}"));

If the file grammar.expected.txt exists its content will be compared to the string of the second parameter. If the file doesn’t exist it will be created with the content of the second parameter. The idea is to check manually the content first time it is created and commit to git repo. Whenever the file is changed the assert will fail. In that case we delete output file, run the test to produce the new version and investigate the diff with git. If everything is expected we commit the new version of the output file.

This is helpful for testing the content of larger structures.