|
| 1 | +#![cfg(feature = "kevm-backend")] |
| 2 | + |
| 3 | +/// Checks if a contract spec is valid. |
| 4 | +macro_rules! test_spec { |
| 5 | + ($name:ident, $src_path:expr, $spec_path:expr) => { |
| 6 | + #[test] |
| 7 | + fn $name() { |
| 8 | + let src = fe_test_files::fixture(concat!("kspecs/", $src_path)); |
| 9 | + let spec = fe_test_files::fixture(concat!("kspecs/", $spec_path)); |
| 10 | + |
| 11 | + if let Err(output) = |
| 12 | + fv::run_spec(&stringify!($name).replace("_", "-"), $src_path, &src, &spec) |
| 13 | + { |
| 14 | + panic!("{}", output) |
| 15 | + } |
| 16 | + } |
| 17 | + }; |
| 18 | +} |
| 19 | + |
| 20 | +/// Checks if a contract spec is invalid. |
| 21 | +macro_rules! test_spec_invalid { |
| 22 | + ($name:ident, $src_path:expr, $spec_path:expr) => { |
| 23 | + #[test] |
| 24 | + fn $name() { |
| 25 | + let src = fe_test_files::fixture(concat!("kspecs/", $src_path)); |
| 26 | + let spec = fe_test_files::fixture(concat!("kspecs/", $spec_path)); |
| 27 | + |
| 28 | + match fv::run_spec(&stringify!($name).replace("_", "-"), $src_path, &src, &spec) { |
| 29 | + Ok(()) => panic!("spec is valid"), |
| 30 | + Err(output) => { |
| 31 | + // we want to make sure it didn't fail for some other reason |
| 32 | + if !output.contains("the claimed implication is not valid") { |
| 33 | + panic!("spec claim was not checked {}", output) |
| 34 | + } |
| 35 | + } |
| 36 | + } |
| 37 | + } |
| 38 | + }; |
| 39 | +} |
| 40 | + |
| 41 | +test_spec! { sanity_returns_42, "sanity/foo.fe", "sanity/returns_42.k" } |
| 42 | +test_spec! { sanity_returns_in, "sanity/foo.fe", "sanity/returns_in.k" } |
| 43 | +test_spec! { sanity_returns_in_cond1, "sanity/foo.fe", "sanity/returns_in_cond1.k" } |
| 44 | +test_spec! { sanity_returns_in_cond2, "sanity/foo.fe", "sanity/returns_in_cond2.k" } |
| 45 | + |
| 46 | +// these are just for extra sanity |
| 47 | +test_spec_invalid! { sanity_returns_42_invalid, "sanity/foo.fe", "sanity/returns_42_invalid.k" } |
| 48 | +test_spec_invalid! { sanity_returns_in_invalid, "sanity/foo.fe", "sanity/returns_in_invalid.k" } |
| 49 | +test_spec_invalid! { sanity_returns_in_cond2_invalid, "sanity/foo.fe", "sanity/returns_in_cond2_invalid.k" } |
0 commit comments