Skip to content

Commit aaa82ae

Browse files
committed
move config check logic from get_toml to parse_inner
1 parent 83b784f commit aaa82ae

File tree

4 files changed

+23
-24
lines changed

4 files changed

+23
-24
lines changed

src/bootstrap/src/core/builder/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ mod sysroot_target_dirs {
308308
/// cg_gcc tests instead.
309309
#[test]
310310
fn test_test_compiler() {
311-
let config = configure_with_args(&["test", "compiler"], &[], &[TEST_TRIPLE_1]);
311+
let config = configure_with_args(&["test", "compiler"], &[&host_target()], &[TEST_TRIPLE_1]);
312312
let cache = run_build(&config.paths.clone(), config);
313313

314314
let compiler = cache.contains::<test::CrateLibrustc>();
315315
let cranelift = cache.contains::<test::CodegenCranelift>();
316316
let gcc = cache.contains::<test::CodegenGCC>();
317317

318-
assert_eq!((compiler, cranelift, gcc), (false, false, false));
318+
assert_eq!((compiler, cranelift, gcc), (true, false, false));
319319
}
320320

321321
#[test]

src/bootstrap/src/core/config/config.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,18 @@ impl Config {
424424
src = src_;
425425
}
426426

427+
#[cfg(test)]
428+
{
429+
if let Some(config_path) = flags_config.as_ref() {
430+
assert!(
431+
!config_path.starts_with(&src),
432+
"Path {config_path:?} should not be inside or equal to src dir {src:?}"
433+
);
434+
} else {
435+
panic!("During test the config should be explicitly added");
436+
}
437+
}
438+
427439
// Now load the TOML config, as soon as possible
428440
let (mut toml, toml_path) = load_toml_config(&src, flags_config, &get_toml);
429441

src/bootstrap/src/core/config/tests.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -175,20 +175,14 @@ fn override_toml_duplicate() {
175175

176176
#[test]
177177
fn profile_user_dist() {
178-
fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
179-
let contents = if file.ends_with("bootstrap.toml")
180-
|| file.ends_with("config.toml")
181-
|| env::var_os("RUST_BOOTSTRAP_CONFIG").is_some()
182-
{
183-
"profile = \"user\"".to_owned()
184-
} else {
185-
assert!(file.ends_with("config.dist.toml") || file.ends_with("bootstrap.dist.toml"));
186-
std::fs::read_to_string(file).unwrap()
187-
};
188-
189-
toml::from_str(&contents).and_then(|table: toml::Value| TomlConfig::deserialize(table))
190-
}
191-
Config::parse_inner(Flags::parse(&["check".to_owned()]), get_toml);
178+
TestCtx::new()
179+
.config("check")
180+
.with_default_toml_config(
181+
r#"
182+
profile = "user"
183+
"#,
184+
)
185+
.create_config();
192186
}
193187

194188
#[test]
@@ -224,8 +218,6 @@ fn verify_file_integrity() {
224218
config
225219
.verify(&tempfile, "7e255dd9542648a8779268a0f268b891a198e9828e860ed23f826440e786eae5")
226220
);
227-
228-
remove_file(tempfile).unwrap();
229221
}
230222

231223
#[test]
@@ -648,6 +640,7 @@ fn test_include_precedence_over_profile() {
648640
.config("check")
649641
.with_default_toml_config(
650642
r#"
643+
profile = "dist"
651644
include = ["./extension.toml"]
652645
"#,
653646
)

src/bootstrap/src/core/config/toml/mod.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,6 @@ impl Config {
152152
}
153153

154154
pub(crate) fn get_toml(file: &Path) -> Result<TomlConfig, toml::de::Error> {
155-
#[cfg(test)]
156-
{
157-
let tmp = std::env::temp_dir();
158-
assert!(file.starts_with(&tmp), "Expected path in temp dir {:?}, got {:?}", tmp, file);
159-
}
160-
161155
Self::get_toml_inner(file)
162156
}
163157

0 commit comments

Comments
 (0)