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

The :path designator is too restrictive in the $name parameter #4

Closed
badicsalex opened this issue Jul 10, 2022 · 2 comments
Closed

Comments

@badicsalex
Copy link
Contributor

Hi,

I have been using this harness with Great Success (tm), apart from a minor inconvenience.

Background:

To reduce boilerplate with tests separated into modules, I made the following wrapper:

macro_rules! generate_harness{
    ($($test:ident),*) => {
        datatest_stable::harness!(
            $(
                $test::run_test,
                $test::test_dir(),
                $test::FILE_PATTERN,
            )*
        );
    }
}

generate_harness!(test_pdf_parser, test_structure_parser, test_reference_parsing);

Problem

Unfortunately if I modify the wrapper to use paths:

macro_rules! generate_harness{
    ($($test:path),*) => {
        datatest_stable::harness!(
            $(
                $test::run_test,
                $test::test_dir(),
                $test::FILE_PATTERN,
            )*
        );
    }
}

generate_harness!(pdf::test_pdf_parser, structure::test_structure_parser, grammar::test_reference_parsing);

Cause

It suddenly doesn't work, because rustc cannot properly comprehend $test::run_test if $test a path and not an ident.

This is due to rust-lang/rust#48067.

Solution?

Apparently, one possible workaround is using $Va : ident $( :: $Vb : ident )* instead of path, but I have not tested this.

Loosening $name to expr would also solve the problem I think.

I'd also be happy with any other idea. What I currently do is just import everything into the crate namespace, but that's going to be problematic sooner or later.

@badicsalex badicsalex changed the title The :path designator does not play well when encompassed in other macros The :path designator is too restrictive Jul 10, 2022
@badicsalex badicsalex changed the title The :path designator is too restrictive The :path designator is too restrictive in the $name parameter Jul 10, 2022
@sunshowers
Copy link
Member

sunshowers commented Jul 12, 2022

Thanks for the report! Could you try the use as workaround listed in the issue and see if that works? If so, I'd love a PR. Thanks!

@badicsalex
Copy link
Contributor Author

I've been playing around with it since the report, and this worked without touching the harness macro itself:

macro_rules! generate_harness{
    ($($first:ident$(::$rest:ident)*),*) => {
        datatest_stable::harness!(
            $(
                $first$(::$rest)*::run_test,
                $first$(::$rest)*::test_dir(),
                $first$(::$rest)*::FILE_PATTERN,
            )*
        );
    }
}

generate_harness!(
    fast::test_pdf_parser,
    fast::structure::test_structure_parser,
    slow::grammar::test_reference_parsing
);

It would be nice to be able to put an expr in the $name field too though, because it was very convenient to use a function returning a string in the directory field, and I'd imagine a function returning a function or similar would be a valid use-case for the test function too.

But since the original problem could be solved without modifying the datatest library, I guess the issue can be closed.

badicsalex added a commit to badicsalex/hun_law_rs that referenced this issue Jul 12, 2022
For some reason $path::whatever is not a valid `path` according to rustc.

See:
- nextest-rs/datatest-stable#4
- rust-lang/rust#48067
@badicsalex badicsalex closed this as not planned Won't fix, can't repro, duplicate, stale Aug 16, 2022
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

No branches or pull requests

2 participants