|
1 | 1 | use super::{Config, TomlConfig};
|
2 |
| -use std::path::Path; |
| 2 | +use std::{env, path::Path}; |
3 | 3 |
|
4 | 4 | fn toml(config: &str) -> impl '_ + Fn(&Path) -> TomlConfig {
|
5 | 5 | |&_| toml::from_str(config).unwrap()
|
@@ -33,4 +33,35 @@ fn download_ci_llvm() {
|
33 | 33 | ));
|
34 | 34 | }
|
35 | 35 |
|
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