Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macros: fix invalid file paths #2042

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

macros: fix invalid file paths #2042

wants to merge 1 commit into from

Conversation

senekor
Copy link
Contributor

@senekor senekor commented Feb 25, 2025

This regression was introduced in:
88c13fb

[no important files changed]

Co-authored-by: yjhtry 860622588@qq.com

This regression was introduced in:
88c13fb

Co-authored-by: yjhtry <860622588@qq.com>
Copy link
Contributor

This PR touches files which potentially affect the outcome of the tests of an exercise. This will cause all students' solutions to affected exercises to be re-tested.

If this PR does not affect the result of the test (or, for example, adds an edge case that is not worth rerunning all tests for), please add the following to the merge-commit message which will stops student's tests from re-running. Please copy-paste to avoid typos.

[no important files changed]

For more information, refer to the documentation. If you are unsure whether to add the message or not, please ping @exercism/maintainers-admin in a comment. Thank you!

@senekor
Copy link
Contributor Author

senekor commented Feb 25, 2025

based on #2041

I made sure I could actually get some of the invalid tests to fail with an incorrect solution:

test output:

test single ... ok
test no_trailing_comma ... ok
test nested ... ok
test test::macro_out_of_scope ... ok
test empty ... ok
test test::type_not_in_scope ... ok
test trailing_comma ... ok
test type_override ... ok
test compile_fails_comma_sep ... ok
test compile_fails_two_arrows ... ok
test compile_fails_only_comma ... ok
test compile_fails_triple_arguments ... ok
test compile_fails_leading_comma ... ok
test compile_fails_missing_argument ... ok
test compile_fails_single_argument ... ok
test compile_fails_double_commas ... FAILED
test compile_fails_no_comma ... ok
test compile_fails_only_arrow ... ok

source of test double_commas:

fn main() {
    // a single trailing comma is okay, but two is not
    let _hm: HashMap<_, _> = hashmap!('a' => 2, ,);
}

incorrect solution that triggers the failure:

#[macro_export]
macro_rules! hashmap {
    ($($key:expr => $value:expr,)+) => { $crate::hashmap!($($key => $value),+) };
    ($($key:expr => $value:expr),*) => {
        {
            let mut _map = ::std::collections::HashMap::new();
            $(
                _map.insert($key, $value);
            )*
            _map
        }
    };
    ($key:expr => $value:expr , , ) => {
        {
            let mut _map = ::std::collections::HashMap::new();
            _map.insert($key, $value);
            _map
        }
    };
}

@senekor senekor requested a review from ellnix February 25, 2025 11:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant