Skip to content

Commit 9fbf9f6

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

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,21 @@ impl Config {
401401
skip_std_check_if_no_download_rustc: flags_skip_std_check_if_no_download_rustc,
402402
} = flags;
403403

404+
#[cfg(test)]
405+
{
406+
let tmp = test_build_dir();
407+
if let Some(config_path) = flags_config.as_ref() {
408+
assert!(
409+
!config_path.starts_with(&tmp),
410+
"Path {:?} should not be inside or equal to temp dir {:?}",
411+
config_path,
412+
tmp
413+
);
414+
} else {
415+
panic!("During test the config should be explicitly added");
416+
}
417+
}
418+
404419
#[cfg(feature = "tracing")]
405420
span!(
406421
target: "CONFIG_HANDLING",

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

Lines changed: 9 additions & 14 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]
@@ -648,6 +642,7 @@ fn test_include_precedence_over_profile() {
648642
.config("check")
649643
.with_default_toml_config(
650644
r#"
645+
profile = "dist"
651646
include = ["./extension.toml"]
652647
"#,
653648
)

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)