Skip to content

Commit bb0a059

Browse files
committed
dupliate filter understands command
1 parent 0c5dfdc commit bb0a059

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

bear/src/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ mod types {
323323
File,
324324
#[serde(rename = "arguments")]
325325
Arguments,
326+
#[serde(rename = "command")]
327+
Command,
326328
#[serde(rename = "output")]
327329
Output,
328330
}

bear/src/semantic/clang/filter.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl DuplicateEntryFilter {
3939
config::OutputFields::Directory => entry.directory.hash(&mut hasher),
4040
config::OutputFields::File => entry.file.hash(&mut hasher),
4141
config::OutputFields::Arguments => entry.arguments.hash(&mut hasher),
42+
config::OutputFields::Command => entry.command.hash(&mut hasher),
4243
config::OutputFields::Output => entry.output.hash(&mut hasher),
4344
}
4445
}
@@ -50,6 +51,8 @@ impl DuplicateEntryFilter {
5051
pub enum ConfigurationError {
5152
#[error("Duplicate field: {0:?}")]
5253
DuplicateField(config::OutputFields),
54+
#[error("Command and Arguments cannot be both specified")]
55+
CommandAndArgumentsBothSpecified,
5356
#[error("Empty field list")]
5457
EmptyFieldList,
5558
}
@@ -68,6 +71,12 @@ impl TryFrom<config::DuplicateFilter> for DuplicateEntryFilter {
6871
}
6972
}
7073

74+
if already_seen.contains(&config::OutputFields::Command)
75+
&& already_seen.contains(&config::OutputFields::Arguments)
76+
{
77+
return Err(ConfigurationError::CommandAndArgumentsBothSpecified);
78+
}
79+
7180
Ok(DuplicateEntryFilter {
7281
fields: config.by_fields,
7382
hash_values: HashSet::new(),
@@ -112,6 +121,21 @@ mod tests {
112121
));
113122
}
114123

124+
#[test]
125+
fn test_try_from_failure_command_and_arguments() {
126+
let config = config::DuplicateFilter {
127+
by_fields: vec![
128+
config::OutputFields::Command,
129+
config::OutputFields::Arguments,
130+
],
131+
};
132+
let result = DuplicateEntryFilter::try_from(config);
133+
assert!(matches!(
134+
result,
135+
Err(ConfigurationError::CommandAndArgumentsBothSpecified)
136+
));
137+
}
138+
115139
#[test]
116140
fn test_is_duplicate_with_file_and_directory_fields() {
117141
let config = config::DuplicateFilter {

0 commit comments

Comments
 (0)