Skip to content

Commit

Permalink
[nextest-runner] support pressing t to dump current test info (#1911)
Browse files Browse the repository at this point in the history
In prior work (#1938) we enabled the `SIGUSR1` and `SIGINFO` handlers to
dump internal state to standard output.

However, those handlers aren't present on all platforms.

* `SIGINFO` doesn't exist on Linux. `SIGUSR1` exists but is hard to send
signals over (have to use `kill`, nothing like `^T`).
* Windows' very basic signal handling mechanism isn't really up to the
task.

As an alternative, allow these platforms to specify `t` to dump current
test information to the interactive terminal.

It would also be interesting to support a Unix domain socket as a way to
query current state in the future, and have a separate instance of
nextest be able to connect to the socket -- this work naturally builds
towards that kind of model.
  • Loading branch information
sunshowers authored Dec 5, 2024
1 parent 1833ee8 commit e2f5950
Show file tree
Hide file tree
Showing 11 changed files with 557 additions and 32 deletions.
111 changes: 111 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ config = { version = "0.14.1", default-features = false, features = [
chrono = "0.4.38"
clap = { version = "4.5.22", features = ["derive"] }
console-subscriber = "0.4.1"
crossterm = { version = "0.28.1", features = ["event-stream"] }
dialoguer = "0.11.0"
debug-ignore = "1.0.5"
duct = "0.13.7"
Expand Down
31 changes: 25 additions & 6 deletions cargo-nextest/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ use nextest_runner::{
},
double_spawn::DoubleSpawnInfo,
errors::WriteTestListError,
input::InputHandlerKind,
list::{
BinaryList, OutputFormat, RustTestArtifact, SerializableFormat, TestExecuteContext,
TestList,
Expand Down Expand Up @@ -986,6 +987,13 @@ struct TestReporterOpts {
#[arg(long, env = "NEXTEST_HIDE_PROGRESS_BAR", value_parser = BoolishValueParser::new())]
hide_progress_bar: bool,

/// Disable handling of input keys from the terminal.
///
/// By default, when running a terminal, nextest accepts the `t` key to dump
/// test information. This flag disables that behavior.
#[arg(long, env = "NEXTEST_NO_INPUT_HANDLER", value_parser = BoolishValueParser::new())]
no_input_handler: bool,

/// Format to use for test results (experimental).
#[arg(
long,
Expand Down Expand Up @@ -1780,12 +1788,16 @@ impl App {
.color
.should_colorize(supports_color::Stream::Stderr);

let mut reporter = reporter_opts
.to_builder(no_capture, should_colorize)
.set_verbose(self.base.output.verbose)
.build(&test_list, &profile, output, structured_reporter);
let signal_handler = SignalHandlerKind::Standard;
let input_handler = if reporter_opts.no_input_handler {
InputHandlerKind::Noop
} else {
// This means that the input handler determines whether it should be
// enabled.
InputHandlerKind::Standard
};

let handler = SignalHandlerKind::Standard;
// Make the runner.
let runner_builder = match runner_opts.to_builder(cap_strat) {
Some(runner_builder) => runner_builder,
None => {
Expand All @@ -1798,11 +1810,18 @@ impl App {
&test_list,
&profile,
cli_args,
handler,
signal_handler,
input_handler,
double_spawn.clone(),
target_runner.clone(),
)?;

// Make the reporter.
let mut reporter = reporter_opts
.to_builder(no_capture, should_colorize)
.set_verbose(self.base.output.verbose)
.build(&test_list, &profile, output, structured_reporter);

configure_handle_inheritance(no_capture)?;
let run_stats = runner.try_execute(|event| {
// Write and flush the event.
Expand Down
2 changes: 2 additions & 0 deletions nextest-runner/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ cargo_metadata.workspace = true
config.workspace = true
cfg-if.workspace = true
chrono.workspace = true
crossterm.workspace = true
debug-ignore.workspace = true
duct.workspace = true
future-queue.workspace = true
Expand Down Expand Up @@ -69,6 +70,7 @@ thiserror.workspace = true
# For parsing of .cargo/config.toml files
tokio = { workspace = true, features = [
"fs",
"io-std",
"io-util",
"macros",
"process",
Expand Down
Loading

0 comments on commit e2f5950

Please sign in to comment.