Skip to content

Commit dd20c0f

Browse files
committed
[fixtures] loosen test_cwd check
We're going to use a seed archive soon, which makes the current check not work anyway. Just do a couple of basic heuristic checks.
1 parent 9990bd8 commit dd20c0f

File tree

3 files changed

+69
-59
lines changed

3 files changed

+69
-59
lines changed

fixture-data/src/nextest_tests.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ pub static EXPECTED_TEST_SUITES: Lazy<BTreeMap<RustBinaryId, TestSuiteFixture>>
2424
vec![
2525
TestCaseFixture::new("test_cargo_env_vars", TestCaseFixtureStatus::Pass)
2626
.with_property(TestCaseFixtureProperty::NotInDefaultSetUnix),
27-
TestCaseFixture::new("test_cwd", TestCaseFixtureStatus::Pass)
28-
.with_property(TestCaseFixtureProperty::NeedsSameCwd),
27+
TestCaseFixture::new("test_cwd", TestCaseFixtureStatus::Pass),
2928
TestCaseFixture::new("test_execute_bin", TestCaseFixtureStatus::Pass),
3029
TestCaseFixture::new("test_failure_assert", TestCaseFixtureStatus::Fail),
3130
TestCaseFixture::new("test_failure_error", TestCaseFixtureStatus::Fail),

fixtures/nextest-tests/tests/basic.rs

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// Copyright (c) The nextest Contributors
2-
use std::{
3-
env,
4-
io::Read,
5-
path::{Path, PathBuf},
6-
};
2+
use std::{env, io::Read, path::PathBuf};
73

84
#[test]
95
fn test_success() {
@@ -66,10 +62,33 @@ fn test_failure_should_panic() {}
6662

6763
#[test]
6864
fn test_cwd() {
69-
// Ensure that the cwd is correct.
65+
// Ensure that the cwd is correct. It's a bit tricky to do this in the face
66+
// of a relative path, but just ensure that the cwd looks like what it
67+
// should be (has a `Cargo.toml` with `name = "nextest-tests"` within it).
7068
let runtime_cwd = env::current_dir().expect("should be able to read current dir");
71-
let compile_time_cwd = Path::new(env!("CARGO_MANIFEST_DIR"));
72-
assert_eq!(runtime_cwd, compile_time_cwd, "current dir matches");
69+
let cargo_toml_path = runtime_cwd.join("Cargo.toml");
70+
let cargo_toml =
71+
std::fs::read_to_string(runtime_cwd.join("Cargo.toml")).unwrap_or_else(|error| {
72+
panic!(
73+
"should be able to read Cargo.toml: {}",
74+
cargo_toml_path.display()
75+
)
76+
});
77+
assert!(
78+
cargo_toml.contains("name = \"nextest-tests\""),
79+
"{} contains name = \"nextest-tests\"",
80+
cargo_toml_path.display()
81+
);
82+
83+
// Also ensure that the runtime cwd and the runtime CARGO_MANIFEST_DIR are
84+
// the same.
85+
let runtime_cargo_manifest_dir =
86+
env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR should be set");
87+
assert_eq!(
88+
runtime_cwd,
89+
PathBuf::from(runtime_cargo_manifest_dir),
90+
"runtime cwd and CARGO_MANIFEST_DIR are the same"
91+
);
7392
}
7493

7594
#[test]
@@ -149,10 +168,8 @@ fn test_cargo_env_vars() {
149168

150169
// Note: we do not test CARGO here because nextest does not set it -- it's set by Cargo when
151170
// invoked as `cargo nextest`.
152-
assert_env!(
153-
"CARGO_MANIFEST_DIR",
154-
"__NEXTEST_ORIGINAL_CARGO_MANIFEST_DIR"
155-
);
171+
// Also, CARGO_MANIFEST_DIR is tested separately by test_cwd.
172+
156173
assert_env!("CARGO_PKG_VERSION");
157174
assert_env!("CARGO_PKG_VERSION_MAJOR");
158175
assert_env!("CARGO_PKG_VERSION_MINOR");

nextest-runner/src/test_command.rs

Lines changed: 39 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -149,53 +149,47 @@ where
149149
}
150150

151151
fn apply_package_env(cmd: &mut std::process::Command, package: &PackageMetadata<'_>) {
152-
cmd.env(
153-
"__NEXTEST_ORIGINAL_CARGO_MANIFEST_DIR",
154-
// This is a test-only environment variable set to the *old* cwd. Not part of the
155-
// public API.
156-
package.manifest_path().parent().unwrap(),
157-
)
158152
// These environment variables are set at runtime by cargo test:
159153
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
160-
.env("CARGO_PKG_VERSION", format!("{}", package.version()))
161-
.env(
162-
"CARGO_PKG_VERSION_MAJOR",
163-
format!("{}", package.version().major),
164-
)
165-
.env(
166-
"CARGO_PKG_VERSION_MINOR",
167-
format!("{}", package.version().minor),
168-
)
169-
.env(
170-
"CARGO_PKG_VERSION_PATCH",
171-
format!("{}", package.version().patch),
172-
)
173-
.env(
174-
"CARGO_PKG_VERSION_PRE",
175-
format!("{}", package.version().pre),
176-
)
177-
.env("CARGO_PKG_AUTHORS", package.authors().join(":"))
178-
.env("CARGO_PKG_NAME", package.name())
179-
.env(
180-
"CARGO_PKG_DESCRIPTION",
181-
package.description().unwrap_or_default(),
182-
)
183-
.env("CARGO_PKG_HOMEPAGE", package.homepage().unwrap_or_default())
184-
.env("CARGO_PKG_LICENSE", package.license().unwrap_or_default())
185-
.env(
186-
"CARGO_PKG_LICENSE_FILE",
187-
package.license_file().unwrap_or_else(|| "".as_ref()),
188-
)
189-
.env(
190-
"CARGO_PKG_REPOSITORY",
191-
package.repository().unwrap_or_default(),
192-
)
193-
.env(
194-
"CARGO_PKG_RUST_VERSION",
195-
package
196-
.minimum_rust_version()
197-
.map_or(String::new(), |v| v.to_string()),
198-
);
154+
cmd.env("CARGO_PKG_VERSION", format!("{}", package.version()))
155+
.env(
156+
"CARGO_PKG_VERSION_MAJOR",
157+
format!("{}", package.version().major),
158+
)
159+
.env(
160+
"CARGO_PKG_VERSION_MINOR",
161+
format!("{}", package.version().minor),
162+
)
163+
.env(
164+
"CARGO_PKG_VERSION_PATCH",
165+
format!("{}", package.version().patch),
166+
)
167+
.env(
168+
"CARGO_PKG_VERSION_PRE",
169+
format!("{}", package.version().pre),
170+
)
171+
.env("CARGO_PKG_AUTHORS", package.authors().join(":"))
172+
.env("CARGO_PKG_NAME", package.name())
173+
.env(
174+
"CARGO_PKG_DESCRIPTION",
175+
package.description().unwrap_or_default(),
176+
)
177+
.env("CARGO_PKG_HOMEPAGE", package.homepage().unwrap_or_default())
178+
.env("CARGO_PKG_LICENSE", package.license().unwrap_or_default())
179+
.env(
180+
"CARGO_PKG_LICENSE_FILE",
181+
package.license_file().unwrap_or_else(|| "".as_ref()),
182+
)
183+
.env(
184+
"CARGO_PKG_REPOSITORY",
185+
package.repository().unwrap_or_default(),
186+
)
187+
.env(
188+
"CARGO_PKG_RUST_VERSION",
189+
package
190+
.minimum_rust_version()
191+
.map_or(String::new(), |v| v.to_string()),
192+
);
199193
}
200194

201195
/// Applies environment variables spcified by the build script via `cargo::rustc-env`

0 commit comments

Comments
 (0)