Skip to content

Commit 878eff1

Browse files
committed
Add tests for RustOptimize
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
1 parent e6e2825 commit 878eff1

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/bootstrap/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ impl Default for StringOrBool {
875875
}
876876
}
877877

878-
#[derive(Clone, Debug, Deserialize)]
878+
#[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
879879
#[serde(untagged)]
880880
pub enum RustOptimize {
881881
#[serde(deserialize_with = "deserialize_and_validate_opt_level")]

src/bootstrap/config/tests.rs

+19
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,22 @@ fn profile_user_dist() {
178178
}
179179
Config::parse_inner(&["check".to_owned()], get_toml);
180180
}
181+
182+
#[test]
183+
fn rust_optimize() {
184+
let parse = |s| Config::parse_inner(&["check".to_owned()], |&_| toml::from_str(s).unwrap());
185+
186+
assert_eq!(parse("").rust_optimize.is_release(), true);
187+
assert_eq!(parse("rust.optimize = false").rust_optimize.is_release(), false);
188+
assert_eq!(parse("rust.optimize = true").rust_optimize.is_release(), true);
189+
assert_eq!(parse("rust.optimize = \"1\"").rust_optimize.get_opt_level(), Some("1".to_string()));
190+
assert_eq!(parse("rust.optimize = \"s\"").rust_optimize.get_opt_level(), Some("s".to_string()));
191+
}
192+
193+
#[test]
194+
#[should_panic]
195+
fn invalid_rust_optimize() {
196+
Config::parse_inner(&["check".to_owned()], |&_| {
197+
toml::from_str("rust.optimize = \"a\"").unwrap()
198+
});
199+
}

0 commit comments

Comments
 (0)