Skip to content

Commit 92522ce

Browse files
committed
[nextest-runner] store CLI args
We're going to use this in the run recorder.
1 parent bc27ad9 commit 92522ce

File tree

7 files changed

+37
-7
lines changed

7 files changed

+37
-7
lines changed

cargo-nextest/src/dispatch.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ pub struct CargoNextestApp {
6060

6161
impl CargoNextestApp {
6262
/// Executes the app.
63-
pub fn exec(self, output_writer: &mut OutputWriter) -> Result<i32> {
63+
pub fn exec(self, cli_args: Vec<String>, output_writer: &mut OutputWriter) -> Result<i32> {
6464
#[cfg(feature = "experimental-tokio-console")]
6565
nextest_runner::console::init();
6666

6767
match self.subcommand {
68-
NextestSubcommand::Nextest(app) => app.exec(output_writer),
69-
NextestSubcommand::Ntr(opts) => opts.exec(output_writer),
68+
NextestSubcommand::Nextest(app) => app.exec(cli_args, output_writer),
69+
NextestSubcommand::Ntr(opts) => opts.exec(cli_args, output_writer),
7070
#[cfg(unix)]
7171
NextestSubcommand::DoubleSpawn(opts) => opts.exec(),
7272
}
@@ -99,7 +99,7 @@ impl AppOpts {
9999
/// Execute the command.
100100
///
101101
/// Returns the exit code.
102-
fn exec(self, output_writer: &mut OutputWriter) -> Result<i32> {
102+
fn exec(self, cli_args: Vec<String>, output_writer: &mut OutputWriter) -> Result<i32> {
103103
let output = self.common.output.init();
104104

105105
match self.command {
@@ -138,6 +138,7 @@ impl AppOpts {
138138
run_opts.no_capture,
139139
&run_opts.runner_opts,
140140
&run_opts.reporter_opts,
141+
cli_args,
141142
output_writer,
142143
)?;
143144
Ok(0)
@@ -372,7 +373,7 @@ struct NtrOpts {
372373
}
373374

374375
impl NtrOpts {
375-
fn exec(self, output_writer: &mut OutputWriter) -> Result<i32> {
376+
fn exec(self, cli_args: Vec<String>, output_writer: &mut OutputWriter) -> Result<i32> {
376377
let output = self.common.output.init();
377378

378379
let base = BaseApp::new(
@@ -389,6 +390,7 @@ impl NtrOpts {
389390
self.run_opts.no_capture,
390391
&self.run_opts.runner_opts,
391392
&self.run_opts.reporter_opts,
393+
cli_args,
392394
output_writer,
393395
)?;
394396
Ok(0)
@@ -1523,6 +1525,7 @@ impl App {
15231525
no_capture: bool,
15241526
runner_opts: &TestRunnerOpts,
15251527
reporter_opts: &TestReporterOpts,
1528+
cli_args: Vec<String>,
15261529
output_writer: &mut OutputWriter,
15271530
) -> Result<()> {
15281531
let (version_only_config, config) = self.base.load_config()?;
@@ -1606,6 +1609,7 @@ impl App {
16061609
let runner = runner_builder.build(
16071610
&test_list,
16081611
&profile,
1612+
cli_args,
16091613
handler,
16101614
double_spawn.clone(),
16111615
target_runner.clone(),

cargo-nextest/src/main.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ fn main() -> Result<()> {
99
color_eyre::install()?;
1010
let _ = enable_ansi_support::enable_ansi_support();
1111

12+
let cli_args: Vec<_> = std::env::args_os()
13+
.map(|arg| arg.to_string_lossy().into_owned())
14+
.collect();
15+
1216
let opts = CargoNextestApp::parse();
13-
match opts.exec(&mut OutputWriter::default()) {
17+
match opts.exec(cli_args, &mut OutputWriter::default()) {
1418
Ok(code) => std::process::exit(code),
1519
Err(error) => {
1620
error.display_to_stderr();

integration-tests/test-helpers/cargo-nextest-dup.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,12 @@ fn main() -> Result<()> {
1212
color_eyre::install()?;
1313
let _ = enable_ansi_support::enable_ansi_support();
1414

15+
let cli_args: Vec<_> = std::env::args_os()
16+
.map(|arg| arg.to_string_lossy().into_owned())
17+
.collect();
18+
1519
let opts = CargoNextestApp::parse();
16-
match opts.exec(&mut OutputWriter::default()) {
20+
match opts.exec(cli_args, &mut OutputWriter::default()) {
1721
Ok(code) => std::process::exit(code),
1822
Err(error) => {
1923
error.display_to_stderr();

nextest-runner/src/reporter.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,7 @@ impl<'a> TestReporterImpl<'a> {
598598
test_list,
599599
run_id,
600600
profile_name,
601+
cli_args: _,
601602
} => {
602603
write!(writer, "{:>12} ", "Starting".style(self.styles.pass))?;
603604

@@ -1675,6 +1676,9 @@ pub enum TestEventKind<'a> {
16751676

16761677
/// The nextest profile chosen for this run.
16771678
profile_name: String,
1679+
1680+
/// The command-line arguments for the process.
1681+
cli_args: Vec<String>,
16781682
},
16791683

16801684
/// A setup script started.

nextest-runner/src/runner.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ impl TestRunnerBuilder {
170170
self,
171171
test_list: &'a TestList,
172172
profile: &'a NextestProfile<'a>,
173+
cli_args: Vec<String>,
173174
handler_kind: SignalHandlerKind,
174175
double_spawn: DoubleSpawnInfo,
175176
target_runner: TargetRunner,
@@ -193,6 +194,7 @@ impl TestRunnerBuilder {
193194
inner: TestRunnerInner {
194195
capture_strategy: self.capture_strategy,
195196
profile,
197+
cli_args,
196198
test_threads,
197199
force_retries: self.retries,
198200
fail_fast,
@@ -253,6 +255,7 @@ impl<'a> TestRunner<'a> {
253255
struct TestRunnerInner<'a> {
254256
capture_strategy: CaptureStrategy,
255257
profile: &'a NextestProfile<'a>,
258+
cli_args: Vec<String>,
256259
test_threads: usize,
257260
// This is Some if the user specifies a retry policy over the command-line.
258261
force_retries: Option<RetryPolicy>,
@@ -286,6 +289,7 @@ impl<'a> TestRunnerInner<'a> {
286289
callback,
287290
self.run_id,
288291
self.profile.name(),
292+
self.cli_args.clone(),
289293
self.test_list.run_count(),
290294
self.fail_fast,
291295
);
@@ -1681,6 +1685,7 @@ struct CallbackContext<F, E> {
16811685
callback: F,
16821686
run_id: Uuid,
16831687
profile_name: String,
1688+
cli_args: Vec<String>,
16841689
stopwatch: StopwatchStart,
16851690
run_stats: RunStats,
16861691
fail_fast: bool,
@@ -1699,6 +1704,7 @@ where
16991704
callback: F,
17001705
run_id: Uuid,
17011706
profile_name: &str,
1707+
cli_args: Vec<String>,
17021708
initial_run_count: usize,
17031709
fail_fast: bool,
17041710
) -> Self {
@@ -1707,6 +1713,7 @@ where
17071713
run_id,
17081714
stopwatch: crate::time::stopwatch(),
17091715
profile_name: profile_name.to_owned(),
1716+
cli_args,
17101717
run_stats: RunStats {
17111718
initial_run_count,
17121719
..RunStats::default()
@@ -1725,6 +1732,7 @@ where
17251732
test_list,
17261733
run_id: self.run_id,
17271734
profile_name: self.profile_name.clone(),
1735+
cli_args: self.cli_args.clone(),
17281736
})
17291737
}
17301738

@@ -2380,6 +2388,7 @@ mod tests {
23802388
.build(
23812389
&test_list,
23822390
&profile,
2391+
vec![],
23832392
handler_kind,
23842393
DoubleSpawnInfo::disabled(),
23852394
TargetRunner::empty(),

nextest-runner/tests/integration/basic.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ fn test_run() -> Result<()> {
102102
.build(
103103
&test_list,
104104
&profile,
105+
vec![], // we aren't testing CLI args at the moment
105106
SignalHandlerKind::Noop,
106107
DoubleSpawnInfo::disabled(),
107108
TargetRunner::empty(),
@@ -210,6 +211,7 @@ fn test_run_ignored() -> Result<()> {
210211
.build(
211212
&test_list,
212213
&profile,
214+
vec![],
213215
SignalHandlerKind::Noop,
214216
DoubleSpawnInfo::disabled(),
215217
TargetRunner::empty(),
@@ -418,6 +420,7 @@ fn test_retries(retries: Option<RetryPolicy>) -> Result<()> {
418420
.build(
419421
&test_list,
420422
&profile,
423+
vec![],
421424
SignalHandlerKind::Noop,
422425
DoubleSpawnInfo::disabled(),
423426
TargetRunner::empty(),
@@ -556,6 +559,7 @@ fn test_termination() -> Result<()> {
556559
.build(
557560
&test_list,
558561
&profile,
562+
vec![],
559563
SignalHandlerKind::Noop,
560564
DoubleSpawnInfo::disabled(),
561565
TargetRunner::empty(),

nextest-runner/tests/integration/target_runner.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ fn test_run_with_target_runner() -> Result<()> {
220220
.build(
221221
&test_list,
222222
&profile,
223+
vec![],
223224
SignalHandlerKind::Noop,
224225
DoubleSpawnInfo::disabled(),
225226
target_runner,

0 commit comments

Comments
 (0)