Skip to content

Conversation

skogseth
Copy link
Contributor

Prior to this change the static variable TESTS had to be declared in the root of the crate in which the #[libtest2::test] macros were used. This was automatically inserted by the #[libtest2::main] macro, but if the user did not include this an error would be shown.

A consequence of this is that the #[libtest2::test] macro could not be used on its own to collect tests, unless the user accessed the hidden, private API exposed in the _private module.

The obvious downside of this change is that the user will no longer receive an error message if they use the #[libtest2::test] macro without #[libtest2::main], and thus no tests will be run. The compiler will, however, still complain if the user is missing a main function.

Note: This does not have an open issue. I figured the conversation around whether or not this is a good change was better made with some code to look at.

Prior to this change the static variable `TESTS` had to be declared in
the root of the crate in which the `#[libtest2::test]` macros were used.
This was automatically inserted by the `#[libtest2::main]` macro, but
if the user did not include this an error would be shown.

A consequence of this is that the `#[libtest2::test]` macro could not be
used on its own to collect tests, unless the user accessed the hidden,
private API exposed in the `_private` module.

The obvious downside of this change is that the user will no longer
receive an error message if they use the `#[libtest2::test]` macro
without `#[libtest2::main]`, and thus no tests will be run. The compiler
will, however, still complain if the user is missing a `main` function.
@coveralls
Copy link

Pull Request Test Coverage Report for Build 18659596523

Details

  • 0 of 2 (0.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.04%) to 30.395%

Changes Missing Coverage Covered Lines Changed/Added Lines %
crates/libtest2/src/lib.rs 0 2 0.0%
Totals Coverage Status
Change from base Build 18571361864: -0.04%
Covered Lines: 500
Relevant Lines: 1645

💛 - Coveralls

@epage
Copy link
Collaborator

epage commented Oct 20, 2025

Thanks for your interest in this!

This, unfortunately, was an intentional choice that I forgot to document in #135 which has now been rectified. I need to transfer that information over into DESIGN.md.

Anything we do with ctor or linkme right now is a polyfill for eventually having that has a feature built-in to the language. Unfortunately, the discussion around the MVP is excluding cross-crate support, so I started without using cross-crate support to not have a reduction in capabilities when we can switch. This also lets us test it out to see how bad it is in practice. Granted, this means we aren't testing what cross-crate would be like and its pros and cons. See rust-lang/testing-devex-team#3.

@skogseth
Copy link
Contributor Author

Very fair! I'll read up on the motivations behind it 👍

@skogseth skogseth closed this Oct 20, 2025
@skogseth skogseth deleted the hidden-magic branch October 21, 2025 14:53
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