From 4d2fce7aa9cb3d3bd90b95fc5203dceb61f9deb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20Gir=C3=A1ldez?= Date: Wed, 17 Jul 2024 12:42:09 -0400 Subject: [PATCH] Use common generated VERSION_BREAKS for all generated test suites --- .../testing/src/bindings_assertions.rs | 9 +---- crates/codegen/testing/src/bindings_output.rs | 9 +---- crates/codegen/testing/src/common.rs | 35 ++---------------- crates/codegen/testing/src/cst_output.rs | 9 +---- crates/codegen/testing/src/lib.rs | 6 +-- .../src/bindings_assertions/generated/mod.rs | 37 ------------------- .../tests/src/bindings_assertions/runner.rs | 2 +- .../src/bindings_output/generated/mod.rs | 37 ------------------- .../cargo/tests/src/bindings_output/runner.rs | 2 +- .../tests/src/cst_output/generated/mod.rs | 37 ------------------- .../cargo/tests/src/cst_output/runner.rs | 2 +- .../solidity/outputs/cargo/tests/src/lib.rs | 1 + 12 files changed, 17 insertions(+), 169 deletions(-) diff --git a/crates/codegen/testing/src/bindings_assertions.rs b/crates/codegen/testing/src/bindings_assertions.rs index 49da7d68d..8ab25a18c 100644 --- a/crates/codegen/testing/src/bindings_assertions.rs +++ b/crates/codegen/testing/src/bindings_assertions.rs @@ -2,23 +2,18 @@ use std::collections::{BTreeMap, BTreeSet}; use std::path::Path; use anyhow::{bail, Result}; -use codegen_language_definition::model::Language; use inflector::Inflector; use infra_utils::codegen::CodegenFileSystem; use infra_utils::paths::FileWalker; use crate::common::{generate_mod_file, generate_unit_test_file}; -pub fn generate_bindings_assertions_tests( - language: &Language, - data_dir: &Path, - output_dir: &Path, -) -> Result<()> { +pub fn generate_bindings_assertions_tests(data_dir: &Path, output_dir: &Path) -> Result<()> { let tests = collect_assertion_tests(data_dir)?; let mut fs = CodegenFileSystem::new(data_dir)?; - generate_mod_file(language, &mut fs, &output_dir.join("mod.rs"), &tests)?; + generate_mod_file(&mut fs, &output_dir.join("mod.rs"), &tests)?; for (group_name, test_files) in &tests { generate_unit_test_file( diff --git a/crates/codegen/testing/src/bindings_output.rs b/crates/codegen/testing/src/bindings_output.rs index b203fdd02..a20e6c163 100644 --- a/crates/codegen/testing/src/bindings_output.rs +++ b/crates/codegen/testing/src/bindings_output.rs @@ -1,22 +1,17 @@ use std::path::Path; use anyhow::Result; -use codegen_language_definition::model::Language; use inflector::Inflector; use infra_utils::codegen::CodegenFileSystem; use crate::common::{collect_snapshot_tests, generate_mod_file, generate_unit_test_file}; -pub fn generate_bindings_output_tests( - language: &Language, - data_dir: &Path, - output_dir: &Path, -) -> Result<()> { +pub fn generate_bindings_output_tests(data_dir: &Path, output_dir: &Path) -> Result<()> { let tests = collect_snapshot_tests(data_dir)?; let mut fs = CodegenFileSystem::new(data_dir)?; - generate_mod_file(language, &mut fs, &output_dir.join("mod.rs"), &tests)?; + generate_mod_file(&mut fs, &output_dir.join("mod.rs"), &tests)?; for (group_name, test_names) in &tests { generate_unit_test_file( diff --git a/crates/codegen/testing/src/common.rs b/crates/codegen/testing/src/common.rs index bc551ccb0..bc4428d0e 100644 --- a/crates/codegen/testing/src/common.rs +++ b/crates/codegen/testing/src/common.rs @@ -50,44 +50,17 @@ pub(crate) fn collect_snapshot_tests( } pub(crate) fn generate_mod_file( - language: &Language, fs: &mut CodegenFileSystem, mod_file_path: &Path, parser_tests: &BTreeMap>, ) -> Result<()> { - let module_declarations_str = - parser_tests - .keys() - .fold(String::new(), |mut buffer, parser_name| { - writeln!(buffer, "mod {0};", parser_name.to_snake_case()).unwrap(); - buffer - }); - - let version_breaks = language.collect_breaking_versions(); - let version_breaks_len = version_breaks.len(); - let version_breaks_str = version_breaks - .iter() - .fold(String::new(), |mut buffer, version| { - writeln!( - buffer, - "Version::new({}, {}, {}),", - version.major, version.minor, version.patch - ) - .unwrap(); + let contents = parser_tests + .keys() + .fold(String::new(), |mut buffer, parser_name| { + writeln!(buffer, "mod {0};", parser_name.to_snake_case()).unwrap(); buffer }); - let contents = format!( - " - use semver::Version; - {module_declarations_str} - - pub const VERSION_BREAKS: [Version; {version_breaks_len}] = [ - {version_breaks_str} - ]; - ", - ); - fs.write_file(mod_file_path, contents) } diff --git a/crates/codegen/testing/src/cst_output.rs b/crates/codegen/testing/src/cst_output.rs index ee1a99ec8..b034a67a2 100644 --- a/crates/codegen/testing/src/cst_output.rs +++ b/crates/codegen/testing/src/cst_output.rs @@ -1,22 +1,17 @@ use std::path::Path; use anyhow::Result; -use codegen_language_definition::model::Language; use inflector::Inflector; use infra_utils::codegen::CodegenFileSystem; use crate::common::{collect_snapshot_tests, generate_mod_file, generate_unit_test_file}; -pub fn generate_cst_output_tests( - language: &Language, - data_dir: &Path, - output_dir: &Path, -) -> Result<()> { +pub fn generate_cst_output_tests(data_dir: &Path, output_dir: &Path) -> Result<()> { let parser_tests = collect_snapshot_tests(data_dir)?; let mut fs = CodegenFileSystem::new(data_dir)?; - generate_mod_file(language, &mut fs, &output_dir.join("mod.rs"), &parser_tests)?; + generate_mod_file(&mut fs, &output_dir.join("mod.rs"), &parser_tests)?; for (parser_name, test_names) in &parser_tests { generate_unit_test_file( diff --git a/crates/codegen/testing/src/lib.rs b/crates/codegen/testing/src/lib.rs index 9399d7419..28a618fcc 100644 --- a/crates/codegen/testing/src/lib.rs +++ b/crates/codegen/testing/src/lib.rs @@ -30,12 +30,12 @@ impl TestingGeneratorExtensions for Language { generate_version_breaks(self, lang_def_dir, output_dir) } fn generate_bindings_assertions_tests(&self, data_dir: &Path, output_dir: &Path) -> Result<()> { - generate_bindings_assertions_tests(self, data_dir, output_dir) + generate_bindings_assertions_tests(data_dir, output_dir) } fn generate_bindings_output_tests(&self, data_dir: &Path, output_dir: &Path) -> Result<()> { - generate_bindings_output_tests(self, data_dir, output_dir) + generate_bindings_output_tests(data_dir, output_dir) } fn generate_cst_output_tests(&self, data_dir: &Path, output_dir: &Path) -> Result<()> { - generate_cst_output_tests(self, data_dir, output_dir) + generate_cst_output_tests(data_dir, output_dir) } } diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/mod.rs b/crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/mod.rs index 9c1c25b55..600b5a0d5 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_assertions/generated/mod.rs @@ -1,41 +1,4 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use semver::Version; mod enums; mod lexical; - -pub const VERSION_BREAKS: [Version; 33] = [ - Version::new(0, 4, 11), - Version::new(0, 4, 12), - Version::new(0, 4, 14), - Version::new(0, 4, 16), - Version::new(0, 4, 21), - Version::new(0, 4, 22), - Version::new(0, 4, 25), - Version::new(0, 5, 0), - Version::new(0, 5, 3), - Version::new(0, 5, 5), - Version::new(0, 5, 8), - Version::new(0, 5, 10), - Version::new(0, 5, 12), - Version::new(0, 5, 14), - Version::new(0, 6, 0), - Version::new(0, 6, 2), - Version::new(0, 6, 5), - Version::new(0, 6, 7), - Version::new(0, 6, 8), - Version::new(0, 6, 11), - Version::new(0, 7, 0), - Version::new(0, 7, 1), - Version::new(0, 7, 4), - Version::new(0, 8, 0), - Version::new(0, 8, 4), - Version::new(0, 8, 7), - Version::new(0, 8, 8), - Version::new(0, 8, 10), - Version::new(0, 8, 13), - Version::new(0, 8, 18), - Version::new(0, 8, 19), - Version::new(0, 8, 22), - Version::new(0, 8, 24), -]; diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs b/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs index 689410d77..fe4f1f688 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_assertions/runner.rs @@ -7,7 +7,7 @@ use slang_solidity::language::Language; use slang_solidity::{bindings, diagnostic}; use super::assertions::{check_assertions, collect_assertions}; -use super::generated::VERSION_BREAKS; +use crate::generated::VERSION_BREAKS; pub fn run(group_name: &str, test_name: &str) -> Result<()> { let file_name = format!("{test_name}.sol"); diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/mod.rs b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/mod.rs index 170b22432..c8e5428d3 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_output/generated/mod.rs @@ -1,43 +1,6 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use semver::Version; mod enums; mod expressions; mod lexical; mod structs; - -pub const VERSION_BREAKS: [Version; 33] = [ - Version::new(0, 4, 11), - Version::new(0, 4, 12), - Version::new(0, 4, 14), - Version::new(0, 4, 16), - Version::new(0, 4, 21), - Version::new(0, 4, 22), - Version::new(0, 4, 25), - Version::new(0, 5, 0), - Version::new(0, 5, 3), - Version::new(0, 5, 5), - Version::new(0, 5, 8), - Version::new(0, 5, 10), - Version::new(0, 5, 12), - Version::new(0, 5, 14), - Version::new(0, 6, 0), - Version::new(0, 6, 2), - Version::new(0, 6, 5), - Version::new(0, 6, 7), - Version::new(0, 6, 8), - Version::new(0, 6, 11), - Version::new(0, 7, 0), - Version::new(0, 7, 1), - Version::new(0, 7, 4), - Version::new(0, 8, 0), - Version::new(0, 8, 4), - Version::new(0, 8, 7), - Version::new(0, 8, 8), - Version::new(0, 8, 10), - Version::new(0, 8, 13), - Version::new(0, 8, 18), - Version::new(0, 8, 19), - Version::new(0, 8, 22), - Version::new(0, 8, 24), -]; diff --git a/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs b/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs index 42c6674f6..25c18b1b1 100644 --- a/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/bindings_output/runner.rs @@ -18,7 +18,7 @@ use slang_solidity::cst::KindTypes; use slang_solidity::language::Language; use slang_solidity::parse_output::ParseOutput; -use super::generated::VERSION_BREAKS; +use crate::generated::VERSION_BREAKS; pub fn run(group_name: &str, test_name: &str) -> Result<()> { let test_dir = CargoWorkspace::locate_source_crate("solidity_testing_snapshots")? diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs index 410761f85..f8fa1b0e0 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/generated/mod.rs @@ -1,6 +1,5 @@ // This file is generated automatically by infrastructure scripts. Please don't edit by hand. -use semver::Version; mod assembly_statement; mod block; mod break_statement; @@ -55,39 +54,3 @@ mod yul_stack_assignment_statement; mod yul_statements; mod yul_variable_assignment_statement; mod yul_variable_declaration_statement; - -pub const VERSION_BREAKS: [Version; 33] = [ - Version::new(0, 4, 11), - Version::new(0, 4, 12), - Version::new(0, 4, 14), - Version::new(0, 4, 16), - Version::new(0, 4, 21), - Version::new(0, 4, 22), - Version::new(0, 4, 25), - Version::new(0, 5, 0), - Version::new(0, 5, 3), - Version::new(0, 5, 5), - Version::new(0, 5, 8), - Version::new(0, 5, 10), - Version::new(0, 5, 12), - Version::new(0, 5, 14), - Version::new(0, 6, 0), - Version::new(0, 6, 2), - Version::new(0, 6, 5), - Version::new(0, 6, 7), - Version::new(0, 6, 8), - Version::new(0, 6, 11), - Version::new(0, 7, 0), - Version::new(0, 7, 1), - Version::new(0, 7, 4), - Version::new(0, 8, 0), - Version::new(0, 8, 4), - Version::new(0, 8, 7), - Version::new(0, 8, 8), - Version::new(0, 8, 10), - Version::new(0, 8, 13), - Version::new(0, 8, 18), - Version::new(0, 8, 19), - Version::new(0, 8, 22), - Version::new(0, 8, 24), -]; diff --git a/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs b/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs index 50678c872..bbba01331 100644 --- a/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs +++ b/crates/solidity/outputs/cargo/tests/src/cst_output/runner.rs @@ -8,8 +8,8 @@ use slang_solidity::kinds::NonterminalKind; use slang_solidity::language::Language; use strum_macros::Display; -use crate::cst_output::generated::VERSION_BREAKS; use crate::cst_output::renderer::render; +use crate::generated::VERSION_BREAKS; #[derive(Display)] #[strum(serialize_all = "kebab_case")] diff --git a/crates/solidity/outputs/cargo/tests/src/lib.rs b/crates/solidity/outputs/cargo/tests/src/lib.rs index f6530a5c0..0655d34ce 100644 --- a/crates/solidity/outputs/cargo/tests/src/lib.rs +++ b/crates/solidity/outputs/cargo/tests/src/lib.rs @@ -5,4 +5,5 @@ mod bindings_output; mod bindings_rules; mod cst_output; mod doc_examples; +mod generated; mod trivia;