Skip to content

Commit c36f493

Browse files
committed
add unit tests on unknown fields
Signed-off-by: onur-ozkan <[email protected]>
1 parent 83bbb55 commit c36f493

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,7 @@ pub(crate) struct TomlConfig {
618618
#[derive(Deserialize, Default)]
619619
pub(crate) struct ChangeIdWrapper {
620620
#[serde(alias = "change-id")]
621-
inner: Option<usize>,
621+
pub(crate) inner: Option<usize>,
622622
}
623623

624624
/// Describes how to handle conflicts in merging two [`TomlConfig`]

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

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use super::{flags::Flags, Config};
1+
use super::{flags::Flags, ChangeIdWrapper, Config};
22
use crate::core::config::{LldMode, TomlConfig};
33

44
use clap::CommandFactory;
@@ -237,3 +237,20 @@ fn rust_lld() {
237237
assert!(matches!(parse("rust.use-lld = true").lld_mode, LldMode::External));
238238
assert!(matches!(parse("rust.use-lld = false").lld_mode, LldMode::Unused));
239239
}
240+
241+
#[test]
242+
#[should_panic]
243+
fn parse_config_with_unknown_field() {
244+
parse("unknown-key = 1");
245+
}
246+
247+
#[test]
248+
fn parse_change_id_with_unknown_field() {
249+
let config = r#"
250+
change-id = 3461
251+
unknown-key = 1
252+
"#;
253+
254+
let change_id_wrapper: ChangeIdWrapper = toml::from_str(config).unwrap();
255+
assert_eq!(change_id_wrapper.inner, Some(3461));
256+
}

0 commit comments

Comments
 (0)