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

test: Migrate jobserver to snapbox #14191

Merged
merged 2 commits into from
Jul 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 92 additions & 20 deletions tests/testsuite/jobserver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Tests for the jobserver protocol.

#![allow(deprecated)]

use cargo_util::is_ci;
use std::env;
use std::net::TcpListener;
Expand All @@ -12,8 +10,7 @@ use cargo_test_support::basic_bin_manifest;
use cargo_test_support::cargo_exe;
use cargo_test_support::install::assert_has_installed_exe;
use cargo_test_support::install::cargo_home;
use cargo_test_support::project;
use cargo_test_support::rustc_host;
use cargo_test_support::{project, rustc_host, str};

const EXE_CONTENT: &str = r#"
use std::env;
Expand Down Expand Up @@ -156,6 +153,7 @@ fn runner_inherits_jobserver() {
[package]
name = "{name}"
version = "0.0.1"
edition = "2015"
"#
),
)
Expand Down Expand Up @@ -200,7 +198,12 @@ test-runner:
.env("CARGO", cargo_exe())
.arg("run-runner")
.arg("-j2")
.with_stderr_contains("[..]this is a runner[..]")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `runner target/debug/cargo-jobserver-check[EXE]`
this is a runner

"#]])
.run();
p.process(make)
.env("CARGO", cargo_exe())
Expand All @@ -212,33 +215,104 @@ test-runner:
.env("CARGO", cargo_exe())
.arg("test-runner")
.arg("-j2")
.with_stderr_contains("[..]this is a runner[..]")
.with_stderr_data(str![[r#"
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/debug/deps/cargo_jobserver_check-[HASH][EXE])
this is a runner

"#]])
.run();

// but not from `-j` flag
p.cargo("run -j2")
.with_status(101)
.with_stderr_contains("[..]no jobserver from env[..]")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `target/debug/cargo-jobserver-check[EXE]`
thread 'main' panicked at src/main.rs:5:43:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
...

"#]])
.run();
p.cargo("run -j2")
.env("PATH", path)
.arg("--config")
.arg(config_value)
.with_status(101)
.with_stderr_contains("[..]this is a runner[..]")
.with_stderr_contains("[..]no jobserver from env[..]")
.with_stderr_data(str![[r#"
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] `runner target/debug/cargo-jobserver-check[EXE]`
this is a runner
thread 'main' panicked at src/main.rs:5:43:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'main' panicked at src/main.rs:6:17:
assertion failed: status.success()
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
...
Copy link
Contributor Author

Choose a reason for hiding this comment

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

globbing the error line.

https://github.com/rust-lang/cargo/actions/runs/9803335785/job/27069355328#step:11:4063

 running `D:\a\cargo\cargo\target\debug\cargo.exe run -j2 --config 'target.x86_64-pc-windows-msvc.runner = "runner"'`
thread 'jobserver::runner_inherits_jobserver' panicked at tests\testsuite\jobserver.rs:256:10:
---- expected: tests\testsuite\jobserver.rs:244:27
++++ actual:   stderr
   1    1 | [FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
   2    2 | [RUNNING] `runner target/debug/cargo-jobserver-check[EXE]`
   3    3 | this is a runner
   4    4 | thread 'main' panicked at src/main.rs:5:43:
   5    5 | no jobserver from env: NotPresent
   6    6 | [NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
   7    7 | thread 'main' panicked at src/main.rs:6:17:
   8    8 | assertion failed: status.success()
   9    9 | [NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
       10 + [ERROR] process didn't exit successfully: `runner target/debug/cargo-jobserver-check[EXE]` ([EXIT_STATUS]: 101)


"#]])
.run();
p.cargo("test -j2")
.with_status(101)
.with_stdout_contains("[..]no jobserver from env[..]")
.with_stdout_data(str![[r#"

running 1 test
test test ... FAILED

failures:

---- test stdout ----
thread 'test' panicked at src/lib.rs:4:42:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
test

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s


"#]])
.run();
p.cargo("test -j2")
.env("PATH", path)
.arg("--config")
.arg(config_value)
.with_status(101)
.with_stderr_contains("[..]this is a runner[..]")
.with_stdout_contains("[..]no jobserver from env[..]")
.with_stderr_data(str![[r#"
[FINISHED] `test` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
[RUNNING] unittests src/lib.rs (target/debug/deps/cargo_jobserver_check-[HASH][EXE])
this is a runner
thread 'main' panicked at src/main.rs:6:17:
assertion failed: status.success()
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace
[ERROR] test failed, to rerun pass `--lib`

"#]])
.with_stdout_data(str![[r#"

running 1 test
test test ... FAILED

failures:

---- test stdout ----
thread 'test' panicked at src/lib.rs:4:42:
no jobserver from env: NotPresent
[NOTE] run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
test

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in [ELAPSED]s


"#]])
.run();
}

Expand Down Expand Up @@ -371,13 +445,11 @@ all:
p.process(make)
.env("CARGO", cargo_exe())
.arg("-j2")
.with_stderr(
"\
warning: a `-j` argument was passed to Cargo but Cargo is also configured \
with an external jobserver in its environment, ignoring the `-j` parameter
[COMPILING] [..]
[FINISHED] [..]
",
)
.with_stderr_data(str![[r#"
[WARNING] a `-j` argument was passed to Cargo but Cargo is also configured with an external jobserver in its environment, ignoring the `-j` parameter
[COMPILING] foo v0.0.1 ([ROOT]/foo)
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s

"#]])
.run();
}