diff options
author | Divy Srivastava <dj.srivastava23@gmail.com> | 2022-11-26 19:40:31 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-27 09:10:31 +0530 |
commit | 95fb4b886b6f8cb0c3805cd77b6c1359e967bd60 (patch) | |
tree | ab6466a1de5405ef6da3ea539550af40121c0ad2 /ops/lib.rs | |
parent | 28b5a7e2ec519e6c1ff928d57368c0d8741a8bb4 (diff) |
chore(ops): increase codegen tests coverage (#16834)
Upgrade fast_call tests to full (both tier) codegen tests.
Diffstat (limited to 'ops/lib.rs')
-rw-r--r-- | ops/lib.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/ops/lib.rs b/ops/lib.rs index 9b0cc6a8a..a5c196c04 100644 --- a/ops/lib.rs +++ b/ops/lib.rs @@ -725,3 +725,39 @@ fn exclude_lifetime_params( .cloned() .collect::<Punctuated<GenericParam, Comma>>() } + +#[cfg(test)] +mod tests { + use crate::{Attributes, Op}; + use std::path::PathBuf; + + #[testing_macros::fixture("optimizer_tests/**/*.rs")] + fn test_codegen(input: PathBuf) { + let update_expected = std::env::var("UPDATE_EXPECTED").is_ok(); + + let source = + std::fs::read_to_string(&input).expect("Failed to read test file"); + + let mut attrs = Attributes::default(); + if source.contains("// @test-attr:fast") { + attrs.must_be_fast = true; + } + + let item = syn::parse_str(&source).expect("Failed to parse test file"); + let op = Op::new(item, attrs); + + let expected = std::fs::read_to_string(input.with_extension("out")) + .expect("Failed to read expected output file"); + + let actual = op.gen(); + // Validate syntax tree. + let tree = syn::parse2(actual).unwrap(); + let actual = prettyplease::unparse(&tree); + if update_expected { + std::fs::write(input.with_extension("out"), actual) + .expect("Failed to write expected file"); + } else { + assert_eq!(actual, expected); + } + } +} |