Add tests for RustOptimize

Signed-off-by: hi-rustin <rustin.liu@gmail.com>
This commit is contained in:
hi-rustin 2023-07-01 16:59:35 +08:00
parent e6e2825bb0
commit 878eff1207
2 changed files with 20 additions and 1 deletions

View File

@ -875,7 +875,7 @@ fn default() -> StringOrBool {
} }
} }
#[derive(Clone, Debug, Deserialize)] #[derive(Clone, Debug, Deserialize, PartialEq, Eq)]
#[serde(untagged)] #[serde(untagged)]
pub enum RustOptimize { pub enum RustOptimize {
#[serde(deserialize_with = "deserialize_and_validate_opt_level")] #[serde(deserialize_with = "deserialize_and_validate_opt_level")]

View File

@ -178,3 +178,22 @@ fn get_toml(file: &Path) -> TomlConfig {
} }
Config::parse_inner(&["check".to_owned()], get_toml); Config::parse_inner(&["check".to_owned()], get_toml);
} }
#[test]
fn rust_optimize() {
let parse = |s| Config::parse_inner(&["check".to_owned()], |&_| toml::from_str(s).unwrap());
assert_eq!(parse("").rust_optimize.is_release(), true);
assert_eq!(parse("rust.optimize = false").rust_optimize.is_release(), false);
assert_eq!(parse("rust.optimize = true").rust_optimize.is_release(), true);
assert_eq!(parse("rust.optimize = \"1\"").rust_optimize.get_opt_level(), Some("1".to_string()));
assert_eq!(parse("rust.optimize = \"s\"").rust_optimize.get_opt_level(), Some("s".to_string()));
}
#[test]
#[should_panic]
fn invalid_rust_optimize() {
Config::parse_inner(&["check".to_owned()], |&_| {
toml::from_str("rust.optimize = \"a\"").unwrap()
});
}