diff options
| author | hi-rustin <rustin.liu@gmail.com> | 2023-07-01 16:59:35 +0800 |
|---|---|---|
| committer | hi-rustin <rustin.liu@gmail.com> | 2023-07-01 16:59:35 +0800 |
| commit | 878eff12074621e37bef8dabc85c5a8d312fd400 (patch) | |
| tree | cd341fff1925553afeb46f62c19d54be64436f0e | |
| parent | e6e2825bb018baa4f0f6dfecd4206beb73d3ebf4 (diff) | |
| download | rust-878eff12074621e37bef8dabc85c5a8d312fd400.tar.gz rust-878eff12074621e37bef8dabc85c5a8d312fd400.zip | |
Add tests for RustOptimize
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
| -rw-r--r-- | src/bootstrap/config.rs | 2 | ||||
| -rw-r--r-- | src/bootstrap/config/tests.rs | 19 |
2 files changed, 20 insertions, 1 deletions
diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 5a0e5d20818..5f5f7ea25fb 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -875,7 +875,7 @@ impl Default for StringOrBool { } } -#[derive(Clone, Debug, Deserialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq)] #[serde(untagged)] pub enum RustOptimize { #[serde(deserialize_with = "deserialize_and_validate_opt_level")] diff --git a/src/bootstrap/config/tests.rs b/src/bootstrap/config/tests.rs index 3bee659abd1..6ec24530af2 100644 --- a/src/bootstrap/config/tests.rs +++ b/src/bootstrap/config/tests.rs @@ -178,3 +178,22 @@ fn profile_user_dist() { } 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() + }); +} |
