diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-03-13 21:55:37 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-03-13 21:55:37 +0100 |
| commit | f33292fa5d85165fea55682c367827cf37f21216 (patch) | |
| tree | c9c7871b47163a9ed30d9dd8eaaae5c01b2dd741 | |
| parent | 6cec8cb5c2e3653b9d533e2d280b91a9114cf15a (diff) | |
| parent | 58c7b670adee30a3fb987297ceb03483756c8f0f (diff) | |
| download | rust-f33292fa5d85165fea55682c367827cf37f21216.tar.gz rust-f33292fa5d85165fea55682c367827cf37f21216.zip | |
Rollup merge of #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
| -rw-r--r-- | src/bootstrap/config/tests.rs | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/bootstrap/config/tests.rs b/src/bootstrap/config/tests.rs index 5a105007f21..16dc8c63abc 100644 --- a/src/bootstrap/config/tests.rs +++ b/src/bootstrap/config/tests.rs @@ -1,5 +1,5 @@ use super::{Config, TomlConfig}; -use std::path::Path; +use std::{env, path::Path}; fn toml(config: &str) -> impl '_ + Fn(&Path) -> TomlConfig { |&_| toml::from_str(config).unwrap() @@ -33,4 +33,35 @@ fn download_ci_llvm() { )); } -// FIXME: add test for detecting `src` and `out` +#[test] +fn detect_src_and_out() { + let cfg = parse(""); + + // This will bring absolute form of `src/bootstrap` path + let current_dir = std::env::current_dir().unwrap(); + + // get `src` by moving into project root path + let expected_src = current_dir.ancestors().nth(2).unwrap(); + + assert_eq!(&cfg.src, expected_src); + + // This should bring output path of bootstrap in absolute form + let cargo_target_dir = env::var_os("CARGO_TARGET_DIR") + .expect("CARGO_TARGET_DIR must been provided for the test environment from bootstrap"); + + // Move to `build` from `build/bootstrap` + let expected_out = Path::new(&cargo_target_dir).parent().unwrap(); + assert_eq!(&cfg.out, expected_out); + + let args: Vec<String> = env::args().collect(); + + // Another test for `out` as a sanity check + // + // This will bring something similar to: + // `{config_toml_place}/build/bootstrap/debug/deps/bootstrap-c7ee91d5661e2804` + // `{config_toml_place}` can be anywhere, not just in the rust project directory. + let dep = Path::new(args.first().unwrap()); + let expected_out = dep.ancestors().nth(4).unwrap(); + + assert_eq!(&cfg.out, expected_out); +} |
