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

Allow the passing of flags to expand #43

Closed
Emoun opened this issue Jul 1, 2020 · 3 comments · Fixed by #46
Closed

Allow the passing of flags to expand #43

Emoun opened this issue Jul 1, 2020 · 3 comments · Fixed by #46
Assignees
Labels
enhancement New feature or request

Comments

@Emoun
Copy link
Contributor

Emoun commented Jul 1, 2020

I would like the possibility of passing flags to cargo in macrotest::expand_without_refresh.

My use case is that I would like to test my expansion with different crate features. It seems to me that macrotest::expand_without_refresh simply calls cargo expand, which means the default features of the crate under test are used.
I would like to be able to disable the default features and enable other features in a granular fashion:

// Test expansion without any features
macrotest::expand_without_refresh("some_test_file.rs", "--no-default-features"); 

// Test expansion with only feature "some_feature" enabled
macrotest::expand_without_refresh("some_test_file.rs", "--features some_feature"); 

Of course the exact API doesn't have to look like the above.

@eupn eupn self-assigned this Jul 1, 2020
@eupn eupn added the enhancement New feature or request label Jul 1, 2020
@eupn eupn mentioned this issue Jul 10, 2020
@eupn
Copy link
Owner

eupn commented Jul 10, 2020

@Emoun this feature was implemented in #46. Feel free to pull this branch and test the new API against your requirements.

Example from tests that enables test-feature during macro expansion:

#[test]
pub fn pass_args() {
    macrotest::expand_args("tests/expand_args/*.rs", &["--features", "test-feature"]);
}

#[test]
pub fn pass_expect_expanded_args() {
    // If you delete one of the `.expanded.rs` files, this test will fail.
    macrotest::expand_args("tests/expand_args/*.rs", &["--features", "test-feature"]);
}

#[test]
#[should_panic]
pub fn fail_expect_expanded_args() {
    // This directory doesn't have expanded files but since they're expected, the test will fail.
    macrotest::expand_without_refresh_args("tests/no_expanded_args/*.rs", &["--features", "test-feature"]);
}

@Emoun
Copy link
Contributor Author

Emoun commented Jul 10, 2020

@eupn I have tested the branch and it seems to work as I expected. Note that I have only tested macrotest::expand_without_refresh_args, as that is the only one I can make use of.

I look forward to seeing this in a future release.

@eupn
Copy link
Owner

eupn commented Jul 10, 2020

@Emoun good! Will release a new version ASAP.

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

Successfully merging a pull request may close this issue.

2 participants