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

libtest: Index tests by a unique TestId #82300

Merged
merged 1 commit into from
Apr 12, 2021
Merged

Conversation

andersk
Copy link
Contributor

@andersk andersk commented Feb 19, 2021

This more robustly avoids problems with duplicate TestDesc. See #81852 and #82274.

Cc @Mark-Simulacrum.

@rust-highfive
Copy link
Collaborator

r? @KodrAus

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Feb 19, 2021
@rust-log-analyzer

This comment has been minimized.

@jyn514 jyn514 added the A-libtest Area: #[test] related label Feb 19, 2021
Copy link
Contributor

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @andersk!

I just had one comment about an alternative approach that could reduce a bit of churn through the codebase here, but otherwise this seems like a good fix to me.

library/test/src/lib.rs Show resolved Hide resolved
// The definition of a single test. A test runner will run a list of
// these.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess an alternative here could be to add an id field to TestDesc. If all we need is to guarantee that different tests with the same description don't equate that should even be enough to leave the derived equality and hashing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If we added id to TestDesc, the responsibility for generating it and ensuring its uniqueness would fall to the compiler (I’m not sure if this macro even can generate a unique ID):

cx.expr_struct(
sp,
test_path("TestDesc"),
vec![
// name: "path::to::test"
field(
"name",
cx.expr_call(
sp,
cx.expr_path(test_path("StaticTestName")),
vec![cx.expr_str(
sp,
Symbol::intern(&item_path(
// skip the name of the root module
&cx.current_expansion.module.mod_path[1..],
&item.ident,
)),
)],
),
),
// ignore: true | false
field(
"ignore",
cx.expr_bool(sp, should_ignore(&cx.sess, &item)),
),
// allow_fail: true | false
field(
"allow_fail",
cx.expr_bool(sp, should_fail(&cx.sess, &item)),
),
// should_panic: ...
field(
"should_panic",
match should_panic(cx, &item) {
// test::ShouldPanic::No
ShouldPanic::No => {
cx.expr_path(should_panic_path("No"))
}
// test::ShouldPanic::Yes
ShouldPanic::Yes(None) => {
cx.expr_path(should_panic_path("Yes"))
}
// test::ShouldPanic::YesWithMessage("...")
ShouldPanic::Yes(Some(sym)) => cx.expr_call(
sp,
cx.expr_path(should_panic_path("YesWithMessage")),
vec![cx.expr_str(sp, sym)],
),
},
),
// test_type: ...
field(
"test_type",
match test_type(cx) {
// test::TestType::UnitTest
TestType::UnitTest => {
cx.expr_path(test_type_path("UnitTest"))
}
// test::TestType::IntegrationTest
TestType::IntegrationTest => {
cx.expr_path(test_type_path("IntegrationTest"))
}
// test::TestPath::Unknown
TestType::Unknown => {
cx.expr_path(test_type_path("Unknown"))
}
},
),
// },
],
),

as well as librustdoc:

desc: testing::TestDesc {
name: testing::DynTestName(name),
ignore: match config.ignore {
Ignore::All => true,
Ignore::None => false,
Ignore::Some(ref ignores) => ignores.iter().any(|s| target_str.contains(s)),
},
// compiler failures are test failures
should_panic: testing::ShouldPanic::No,
allow_fail: config.allow_fail,
test_type: testing::TestType::DocTest,
},

and all the tests for libtest itself. Even if this is somehow possible, it wouldn’t reduce churn.

Another alternative would be to try using the address of the TestDesc as a unique identifier—but then instead of moving or cloning TestDesc we’d have to pass it by reference, which also at best wouldn’t reduce churn.

@andersk andersk requested a review from KodrAus February 21, 2021 19:36
@camelid camelid added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 12, 2021
@bors
Copy link
Contributor

bors commented Mar 25, 2021

☔ The latest upstream changes (presumably #83454) made this pull request unmergeable. Please resolve the merge conflicts.

This more robustly avoids problems with duplicate TestDesc.  See rust-lang#81852
and rust-lang#82274.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
@JohnCSimon JohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2021
@Dylan-DPC-zz
Copy link

r? @Amanieu

@rust-highfive rust-highfive assigned Amanieu and unassigned KodrAus Apr 12, 2021
@Amanieu
Copy link
Member

Amanieu commented Apr 12, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Apr 12, 2021

📌 Commit 3c42d9f has been approved by Amanieu

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 12, 2021
@bors
Copy link
Contributor

bors commented Apr 12, 2021

⌛ Testing commit 3c42d9f with merge 5e73bd1...

@bors
Copy link
Contributor

bors commented Apr 12, 2021

☀️ Test successful - checks-actions
Approved by: Amanieu
Pushing 5e73bd1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Apr 12, 2021
@bors bors merged commit 5e73bd1 into rust-lang:master Apr 12, 2021
@rustbot rustbot added this to the 1.53.0 milestone Apr 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-libtest Area: #[test] related merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.