Skip to content

Commit

Permalink
[nextest-metadata] treat proc-macro as lib for binary ID
Browse files Browse the repository at this point in the history
Currently, we generate something like `derive::proc-macro/derive`. A proc-macro
is a kind of library, so just collapse that down to `derive`.
  • Loading branch information
sunshowers committed Nov 27, 2023
1 parent 4026d6d commit c48edfc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions integration-tests/tests/integration/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub static EXPECTED_LIST: Lazy<Vec<TestInfo>> = Lazy::new(|| {
],
),
TestInfo::new(
"nextest-derive::proc-macro/nextest-derive",
"nextest-derive",
BuildPlatform::Host,
vec![("it_works", false)],
),
Expand Down Expand Up @@ -419,7 +419,7 @@ pub fn check_run_output(stderr: &[u8], relocated: bool) {
(true, "nextest-tests::other other_test_success"),
(true, "nextest-tests::basic test_success"),
(false, "nextest-tests::segfault test_segfault"),
(true, "nextest-derive::proc-macro/nextest-derive it_works"),
(true, "nextest-derive it_works"),
(
true,
"nextest-tests::example/other tests::other_example_success",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ group: @global
tests::test_multiply_two_cdylib
cdylib-link:
test_multiply_two
nextest-derive::proc-macro/nextest-derive:
nextest-derive:
it_works
nextest-tests:
tests::call_dylib_add_two
Expand Down Expand Up @@ -46,4 +46,3 @@ group: @global
tests::example_success
nextest-tests::example/other:
tests::other_example_success

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ group: @global
tests::test_multiply_two_cdylib
cdylib-link:
test_multiply_two
nextest-derive::proc-macro/nextest-derive:
nextest-derive:
it_works
nextest-tests:
tests::call_dylib_add_two
Expand Down Expand Up @@ -47,4 +47,3 @@ group: @global
tests::example_success
nextest-tests::example/other:
tests::other_example_success

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ group: @global
tests::test_multiply_two_cdylib
cdylib-link:
test_multiply_two
nextest-derive::proc-macro/nextest-derive:
nextest-derive:
it_works
nextest-tests:
tests::call_dylib_add_two
Expand Down Expand Up @@ -48,4 +48,3 @@ group: @global
tests::example_success
nextest-tests::example/other:
tests::other_example_success

27 changes: 17 additions & 10 deletions nextest-metadata/src/test_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ pub struct RustTestBinarySummary {

/// Information about the kind of a Rust test binary.
///
/// Kinds are used to generate binary IDs and to figure out whether some environment variables
/// should be set.
/// Kinds are used to generate [`RustBinaryId`] instances, and to figure out whether some
/// environment variables should be set.
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Deserialize, Serialize)]
#[serde(transparent)]
pub struct RustTestBinaryKind(pub Cow<'static, str>);
Expand Down Expand Up @@ -287,8 +287,9 @@ impl RustBinaryId {
///
/// The algorithm is as follows:
///
/// 1. If the target is the `lib` target (for unit tests), the binary ID is the same as the
/// package name. There can only be one library per package, so this will always be unique.
/// 1. If the kind is `lib` or `proc-macro` (i.e. for unit tests), the binary ID is the same as
/// the package name. There can only be one library per package, so this will always be
/// unique.
/// 2. If the target is an integration test, the binary ID is `package_name::target_name`.
/// 3. Otherwise, the binary ID is `package_name::{kind}/{target_name}`.
///
Expand All @@ -299,36 +300,42 @@ impl RustBinaryId {
/// ```
/// use nextest_metadata::{RustBinaryId, RustTestBinaryKind};
///
/// // The lib and proc-macro kinds.
/// assert_eq!(
/// RustBinaryId::from_parts("foo-lib", &RustTestBinaryKind::LIB, "foo_lib"),
/// RustBinaryId::new("foo-lib"),
/// );
/// assert_eq!(
/// RustBinaryId::from_parts("foo-derive", &RustTestBinaryKind::PROC_MACRO, "derive"),
/// RustBinaryId::new("foo-derive"),
/// );
///
/// // Integration tests.
/// assert_eq!(
/// RustBinaryId::from_parts("foo-lib", &RustTestBinaryKind::TEST, "foo_test"),
/// RustBinaryId::new("foo-lib::foo_test"),
/// );
///
/// // Other kinds.
/// assert_eq!(
/// RustBinaryId::from_parts("foo-lib", &RustTestBinaryKind::BIN, "foo_bin"),
/// RustBinaryId::new("foo-lib::foo_bin"),
/// RustBinaryId::new("foo-lib::bin/foo_bin"),
/// );
/// ```
pub fn from_parts(package_name: &str, kind: &RustTestBinaryKind, target_name: &str) -> Self {
let mut id = package_name.to_owned();
// To ensure unique binary IDs, we use the following scheme:
if kind == &RustTestBinaryKind::LIB {
// 1. If the target is a lib, use the package name. There can only be one
// lib per package, so this will always be unique.
if kind == &RustTestBinaryKind::LIB || kind == &RustTestBinaryKind::PROC_MACRO {
// 1. The binary ID is the same as the package name.
} else if kind == &RustTestBinaryKind::TEST {
// 2. For integration tests, use package_name::target_name. Cargo enforces unique names
// for the same kind of targets in a package, so these will always be unique.
id.push_str("::");
id.push_str(target_name);
} else {
// 3. For all other target kinds, use a combination of the target kind and
// the target name. For the same reason as above, these will always be
// unique.
// the target name. For the same reason as above, these will always be
// unique.
write!(id, "::{kind}/{target_name}").unwrap();
}

Expand Down
8 changes: 2 additions & 6 deletions nextest-runner/tests/integration/fixtures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub(crate) static EXPECTED_TESTS: Lazy<BTreeMap<RustBinaryId, Vec<TestFixture>>>
TestFixture { name: "tests::test_execute_bin", status: FixtureStatus::Pass },
],
// Proc-macro tests
"nextest-derive::proc-macro/nextest-derive".into() => vec![
"nextest-derive".into() => vec![
TestFixture { name: "it_works", status: FixtureStatus::Pass },
],
// Dynamic library tests
Expand All @@ -182,11 +182,7 @@ pub(crate) fn get_expected_test(binary_id: &RustBinaryId, test_name: &str) -> &'
}

pub(crate) static EXPECTED_BINARY_LIST: [(&str, &str, bool); 8] = [
(
"nextest-derive::proc-macro/nextest-derive",
"nextest-derive",
false,
),
("nextest-derive", "nextest-derive", false),
("nextest-tests", "nextest-tests", true),
("nextest-tests::basic", "basic", true),
("nextest-tests::bin/nextest-tests", "nextest-tests", true),
Expand Down

0 comments on commit c48edfc

Please sign in to comment.