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

proc-macro for generating separate test cases for each generated output sample #37

Open
mersinvald opened this issue Nov 4, 2019 · 2 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@mersinvald
Copy link

It would be awesome to have a macro for generating separate test cases for each generated sample in the expanded/ directory.

Motivation for that is having more granular test results, which would show a test failure for a specific macro or specific macro invocation.

The ideal API, IMHO, would be something like

#[macrotest::tests("expanded/*")]
mod macro_tests;
@eupn eupn added enhancement New feature or request good first issue Good for newcomers labels Nov 4, 2019
@eupn
Copy link
Owner

eupn commented Nov 5, 2019

@mersinvald pls correct me if I wrong.

An example of how the expansion of this procedural macro will probably look like:

Suppose we have 3 test cases in tests/expand/ directory: a.rs, b.rs, and c.rs.

In our tests/expand.rs we have the following code:

#[macrotest:tests("tests/expand/*.rs");
mod expansion_tests;

This should probably expand to something like this:

mod macro_tests {
    #[test]
    pub fn test_expand_a() {
        macrotest::expand("tests/expand/a.rs");
    }

    #[test]
    pub fn test_expand_b() {
        macrotest::expand("tests/expand/b.rs");
    }

    #[test]
    pub fn test_expand_c() {
        macrotest::expand("tests/expand/c.rs");
    }
}

NB: the #[macrotest:tests("glob-pattern")] must ignore the *.expanded.rs files in the directory specified. Otherwise, the macro will generate test cases for expanded code.

@mersinvald
Copy link
Author

@eupn sorry I missed your response. Yes, that’s exactly the expansion I have had in mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants