Skip to content

Commit 3f1c707

Browse files
authored
Rollup merge of rust-lang#109055 - ozkanonur:detect_src_and_out, r=albertlarsan68
create `config::tests::detect_src_and_out` test for bootstrap Resolves one of the `FIXME` in bootstrap
2 parents d461444 + 58c7b67 commit 3f1c707

File tree

1 file changed

+33
-2
lines changed

1 file changed

+33
-2
lines changed

src/bootstrap/config/tests.rs

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{Config, TomlConfig};
2-
use std::path::Path;
2+
use std::{env, path::Path};
33

44
fn toml(config: &str) -> impl '_ + Fn(&Path) -> TomlConfig {
55
|&_| toml::from_str(config).unwrap()
@@ -33,4 +33,35 @@ fn download_ci_llvm() {
3333
));
3434
}
3535

36-
// FIXME: add test for detecting `src` and `out`
36+
#[test]
37+
fn detect_src_and_out() {
38+
let cfg = parse("");
39+
40+
// This will bring absolute form of `src/bootstrap` path
41+
let current_dir = std::env::current_dir().unwrap();
42+
43+
// get `src` by moving into project root path
44+
let expected_src = current_dir.ancestors().nth(2).unwrap();
45+
46+
assert_eq!(&cfg.src, expected_src);
47+
48+
// This should bring output path of bootstrap in absolute form
49+
let cargo_target_dir = env::var_os("CARGO_TARGET_DIR")
50+
.expect("CARGO_TARGET_DIR must been provided for the test environment from bootstrap");
51+
52+
// Move to `build` from `build/bootstrap`
53+
let expected_out = Path::new(&cargo_target_dir).parent().unwrap();
54+
assert_eq!(&cfg.out, expected_out);
55+
56+
let args: Vec<String> = env::args().collect();
57+
58+
// Another test for `out` as a sanity check
59+
//
60+
// This will bring something similar to:
61+
// `{config_toml_place}/build/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804`
62+
// `{config_toml_place}` can be anywhere, not just in the rust project directory.
63+
let dep = Path::new(args.first().unwrap());
64+
let expected_out = dep.ancestors().nth(4).unwrap();
65+
66+
assert_eq!(&cfg.out, expected_out);
67+
}

0 commit comments

Comments
 (0)