Skip to content

Conversation

@skogseth
Copy link
Contributor

@skogseth skogseth commented Feb 12, 2026

The standard test macro keeps the path for the test function the same, so you can also call it as a normal function. This behavior should probably be mimicked here.

Note: A nice little bonus is that the error messages for incorrect function argument types now correctly point at the function definition, and not the macro itself.

Design

We need a unique type to implement the Case trait on when adding a new test. Previously this used the unique identifier provided by the user in the function name, but this is now taken (by the function itself). We therefore make a new scope using a const-block, which we just assign to an anonymous constant of type (). In this scope we can now define a new type, which we can implement the trait for.

@coveralls
Copy link

coveralls commented Feb 12, 2026

Pull Request Test Coverage Report for Build 21962669234

Details

  • 0 of 0 changed or added relevant lines in 0 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 50.964%

Totals Coverage Status
Change from base Build 21554863907: 0.0%
Covered Lines: 1216
Relevant Lines: 2386

💛 - Coveralls

@skogseth skogseth force-pushed the dont-change-fn-path branch from de4ad2a to 2a338ae Compare February 12, 2026 20:01
(break: name=$name:ident body=[($($params:tt)*) $($item:tt)*] $(ignore=$ignore:tt)? $(should_panic=$should_panic:tt)?) => {
#[allow(non_camel_case_types)]
struct $name;
fn $name($($params)*) $($item)*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you also changed the structure?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. So since the name of the function is taken we need a unique path to whatever needs to implement the trait, so the only way I know to do that is to put it in a const block assigned to an anonymous constant. I'll write up a bit more about the design in the PR description

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I had misread what you meant with the title and thought this was #165 (forgot that was fixed).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do realize now that the Test type can conflict with a user defined type. Not sure what to do about that. I can sleep on it, maybe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, it's fine because the test function remains in the original scope, whilst the Test type is only accessible in the const-block scope.

@skogseth skogseth force-pushed the dont-change-fn-path branch from 2a338ae to 480f5b4 Compare February 12, 2026 20:15
@epage
Copy link
Collaborator

epage commented Feb 12, 2026

The standard test macro keeps the path for the test function the same, so you can also call it as a normal function. This behavior should probably be mimicked here.

What end-user impact does this have though?

btw I strongly prefer these kind of disucssions to happen in issues, not PRs. Maybe PRs come and go for a particular concern and that can split up design discussions. I'm also more likely to look into issues for these kinds of conversations.

See also https://github.com/assert-rs/libtest2/blob/main/CONTRIBUTING.md#pull-requests

btw this does move us closer to the shape of #148.

We therefore make a new scope using a const-block, which we just assign to an anonymous constant of type (). In this scope we can now define a new type, which we can implement the trait for.

Oh nice, the MSRV problem was addressed.

@skogseth
Copy link
Contributor Author

The standard test macro keeps the path for the test function the same, so you can also call it as a normal function. This behavior should probably be mimicked here.

What end-user impact does this have though?

Relatively small I would assume? I have done this once ... I think.

btw I strongly prefer these kind of disucssions to happen in issues, not PRs. Maybe PRs come and go for a particular concern and that can split up design discussions. I'm also more likely to look into issues for these kinds of conversations.

See also https://github.com/assert-rs/libtest2/blob/main/CONTRIBUTING.md#pull-requests

...right. Yeah, sorry, I should have remembered that. I will try to remember in the future 👍

btw this does move us closer to the shape of #148.

Yeah, seems like it

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.

3 participants