Skip to content

Commit

Permalink
chore(core): change tests organisation
Browse files Browse the repository at this point in the history
  • Loading branch information
0xLucqs committed Aug 12, 2024
1 parent 07a0c46 commit 7d2cb0a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
5 changes: 3 additions & 2 deletions crates/cairo-lint-core/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ use paste::paste;
use pretty_assertions::assert_eq;
use test_case::test_case;

test_file!(unused_variables, "one unused variable", "two unused variable", "plenty unused variables");
test_file!(unused_variables, unused_variables, "one unused variable", "two unused variable", "plenty unused variables");

test_file!(
destruct_if_let,
single_match,
destructuring_match,
"simple destructuring match",
"simple destructuring match second arm",
"simple destructuring match with scope",
Expand Down
8 changes: 4 additions & 4 deletions crates/cairo-lint-test-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ pub fn get_diags(crate_id: CrateId, db: &mut AnalysisDatabase) -> Vec<Diagnostic
}
#[macro_export]
macro_rules! test_file {
($file_path:ident, $($test_name:expr),*) => {
($lint_group: ident, $file_path:ident, $($test_name:expr),*) => {

paste ! {

const [<TEST_FILENAME_ $file_path:upper>]: &str = concat!("tests/test_files/", stringify!($file_path));
const [<TEST_FILENAME_ $file_path:upper>]: &str = concat!("tests/test_files/", stringify!($lint_group), "/", stringify!($file_path));
static [<PARSED_TEST_FILE_ $file_path:upper>]: LazyLock<OrderedHashMap<String, Test>> =
LazyLock::new(|| parse_test_file(Path::new([<TEST_FILENAME_ $file_path:upper>])).unwrap());
static [<FIXED_TEST_FILE_ $file_path:upper>]: LazyLock<Mutex<Tests>> =
LazyLock::new(|| Mutex::new(Tests { tests: OrderedHashMap::default(), should_fix: false }));


#[dtor]
fn [<fix_ $file_path _test_file>]() {
fn [<fix_ $lint_group $file_path _test_file>]() {
let val = [<FIXED_TEST_FILE_ $file_path:upper>].lock().unwrap();
let res = OrderedHashMap::<String, Test>::from_iter(val.tests.clone().into_iter().sorted_by_key(|kv| kv.0.clone()));
if val.should_fix {
Expand All @@ -55,7 +55,7 @@ macro_rules! test_file {
}

$(#[test_case($test_name; $test_name)])*
fn $file_path(test_name: &str) {
fn [<$lint_group _ $file_path>](test_name: &str) {
let test = & [<PARSED_TEST_FILE_ $file_path:upper>][test_name];
let is_fix_mode = std::env::var("FIX_TESTS") == Ok("1".into());
let mut file = test.attributes["cairo_code"].clone();
Expand Down

0 comments on commit 7d2cb0a

Please sign in to comment.