Skip to content

Commit b9b3973

Browse files
authored
Introduce constant dist dirs for testing
* Rename setup() to test() as it only returns after the test has happened. * Separate tracking the mutable dist servers from the new const dist server * Permit starting a test with no dist server * add with_scenario to construct a specific dist server on-demand, but also cache it for other tests * Migrate cli-exact to use with_scenario * Remove some stale no longer relvant end of test checks * Cached dist servers are generated new per test run for now, and are unique per test binary. They leak at the end of the test, but aren't very large. Clean your target :). * Simplify many tests that had unnecessary work in them (work that wasn't being tested)
2 parents 5b36ca2 + 099b2d5 commit b9b3973

15 files changed

+1963
-1568
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ stack backtrace:
252252
8: core::panicking::panic_fmt
253253
at /rustc/de02101e6d949c4a9040211e9ce8c488a997497e\/src\libcore\panicking.rs:85
254254
9: core::result::unwrap_failed
255-
10: cli_v1::mock::clitools::setup
255+
10: cli_v1::mock::clitools::test
256256
11: alloc::boxed::{{impl}}::call_once<(),FnOnce<()>>
257257
at /rustc/de02101e6d949c4a9040211e9ce8c488a997497e\src\liballoc\boxed.rs:746
258258
12: panic_unwind::__rust_maybe_catch_panic

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ version = "0.3"
109109

110110
[dev-dependencies]
111111
walkdir = "2"
112+
once_cell = "1.17.0"
113+
enum-map = "2.4.2"
112114

113115
[build-dependencies]
114116
lazy_static = "1"

src/test.rs

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,52 @@ impl Env for HashMap<String, String> {
4545
}
4646
}
4747

48-
/// Returns a tempdir for running tests in
49-
pub fn test_dir() -> io::Result<tempfile::TempDir> {
48+
/// The path to a dir for this test binaries state
49+
fn exe_test_dir() -> io::Result<PathBuf> {
5050
let current_exe_path = env::current_exe().unwrap();
5151
let mut exe_dir = current_exe_path.parent().unwrap();
5252
if exe_dir.ends_with("deps") {
5353
exe_dir = exe_dir.parent().unwrap();
5454
}
55-
let test_dir = exe_dir.parent().unwrap().join("tests");
55+
Ok(exe_dir.parent().unwrap().to_owned())
56+
}
57+
58+
/// Returns a tempdir for running tests in
59+
pub fn test_dir() -> io::Result<tempfile::TempDir> {
60+
let exe_dir = exe_test_dir()?;
61+
let test_dir = exe_dir.join("tests");
5662
fs::create_dir_all(&test_dir).unwrap();
5763
tempfile::Builder::new()
5864
.prefix("running-test-")
5965
.tempdir_in(test_dir)
6066
}
6167

68+
/// Returns a directory for storing immutable distributions in
69+
pub fn const_dist_dir() -> io::Result<tempfile::TempDir> {
70+
// TODO: do something smart, like managing garbage collection or something.
71+
let exe_dir = exe_test_dir()?;
72+
let dists_dir = exe_dir.join("dists");
73+
fs::create_dir_all(&dists_dir)?;
74+
let current_exe = env::current_exe().unwrap();
75+
let current_exe_name = current_exe.file_name().unwrap();
76+
tempfile::Builder::new()
77+
.prefix(&format!(
78+
"dist-for-{}-",
79+
Path::new(current_exe_name).display()
80+
))
81+
.tempdir_in(dists_dir)
82+
}
83+
84+
/// Returns a tempdir for storing test-scoped distributions in
85+
pub fn test_dist_dir() -> io::Result<tempfile::TempDir> {
86+
let exe_dir = exe_test_dir()?;
87+
let test_dir = exe_dir.join("tests");
88+
fs::create_dir_all(&test_dir).unwrap();
89+
tempfile::Builder::new()
90+
.prefix("test-dist-dir-")
91+
.tempdir_in(test_dir)
92+
}
93+
6294
/// Makes persistent unique directory inside path.
6395
///
6496
/// Should only be used with path=a tempdir that will be cleaned up, as the

0 commit comments

Comments
 (0)