Skip to content

Commit 75f6e57

Browse files
committed
[nextest-runner] set NEXTEST_TEST_GROUP
Expose the group name that the test is running under, if any.
1 parent 815be98 commit 75f6e57

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

fixtures/nextest-tests/tests/basic.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,17 @@ fn test_stdin_closed() {
383383
/// This should be called if and only if the test-group is serial.
384384
fn assert_with_retries_serial() {
385385
let profile = std::env::var("NEXTEST_PROFILE").expect("NEXTEST_PROFILE should be set");
386+
let group = std::env::var("NEXTEST_TEST_GROUP").expect("NEXTEST_TEST_GROUP should be set");
386387
let group_slot =
387388
std::env::var("NEXTEST_TEST_GROUP_SLOT").expect("NEXTEST_TEST_GROUP_SLOT should be set");
389+
println!("NEXTEST_TEST_GROUP = {group}, NEXTEST_TEST_GROUP_SLOT = {group_slot}");
390+
388391
if profile == "with-retries" {
389-
// Check that NEXTEST_TEST_GROUP_SLOT is set.
392+
assert_eq!(group, "serial", "NEXTEST_TEST_GROUP should be serial");
390393
// This test is in a serial group, so the group slot should be 0.
391394
assert_eq!(group_slot, "0", "NEXTEST_TEST_GROUP_SLOT should be 0");
392395
} else {
396+
assert_eq!(group, "@global", "NEXTEST_TEST_GROUP should be @global");
393397
assert_eq!(group_slot, "none", "NEXTEST_TEST_GROUP_SLOT should be none");
394398
}
395399
}

nextest-runner/src/runner/executor.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use super::HandleSignalResult;
1515
use crate::{
1616
config::{
1717
EvaluatableProfile, RetryPolicy, ScriptConfig, ScriptId, SetupScriptCommand,
18-
SetupScriptExecuteData, SlowTimeout, TestSettings,
18+
SetupScriptExecuteData, SlowTimeout, TestGroup, TestSettings,
1919
},
2020
double_spawn::DoubleSpawnInfo,
2121
errors::{ChildError, ChildFdError, ChildStartError, ErrorList},
@@ -628,15 +628,34 @@ impl<'a> ExecutorContext<'a> {
628628
command_mut.env("__NEXTEST_ATTEMPT", format!("{}", test.retry_data.attempt));
629629

630630
command_mut.env("NEXTEST_RUN_ID", format!("{}", self.run_id));
631+
632+
// Set group and slot environment variables.
631633
command_mut.env(
632634
"NEXTEST_TEST_GLOBAL_SLOT",
633635
test.cx.global_slot().to_string(),
634636
);
637+
match test.settings.test_group() {
638+
TestGroup::Custom(name) => {
639+
debug_assert!(
640+
test.cx.group_slot().is_some(),
641+
"test_group being set implies group_slot is set"
642+
);
643+
command_mut.env("NEXTEST_TEST_GROUP", name.as_str());
644+
}
645+
TestGroup::Global => {
646+
debug_assert!(
647+
test.cx.group_slot().is_none(),
648+
"test_group being unset implies group_slot is unset"
649+
);
650+
command_mut.env("NEXTEST_TEST_GROUP", TestGroup::GLOBAL_STR);
651+
}
652+
}
635653
if let Some(group_slot) = test.cx.group_slot() {
636654
command_mut.env("NEXTEST_TEST_GROUP_SLOT", group_slot.to_string());
637655
} else {
638656
command_mut.env("NEXTEST_TEST_GROUP_SLOT", "none");
639657
}
658+
640659
command_mut.stdin(Stdio::null());
641660
test.setup_script_data.apply(
642661
&test.test_instance.to_test_query(),

0 commit comments

Comments
 (0)