Skip to content

Commit 44c66c9

Browse files
committed
Add tests for the modified submodule handler
1 parent 7604864 commit 44c66c9

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

src/handlers/check_commits/modified_submodule.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,47 @@ pub(super) fn modifies_submodule(diff: &[FileDiff]) -> Option<String> {
1111
None
1212
}
1313
}
14+
15+
#[test]
16+
fn no_submodule_update() {
17+
let filediff = FileDiff {
18+
path: "src/lib.rs".to_string(),
19+
diff: "@@ -1 +1 @@\
20+
-let mut my_var = 5;\
21+
+let mut my_var = \"tmp\";"
22+
.to_string(),
23+
};
24+
25+
assert_eq!(modifies_submodule(&[filediff]), None)
26+
}
27+
28+
#[test]
29+
fn simple_submodule_update() {
30+
// Taken from https://api.github.com/repos/rust-lang/rust/compare/5af801b687e6e8b860ae970e725c8b9a3820d0ce...d6c4ab81be200855df856468ddedde057958441a
31+
let filediff = FileDiff {
32+
path: "src/tools/rustc-perf".to_string(),
33+
diff: "@@ -1 +1 @@\n\
34+
-Subproject commit c0f3b53c8e5de87714d18a5f42998859302ae03a\n\
35+
+Subproject commit 8158f78f738715c060d230351623a7f7cc01bf97"
36+
.to_string(),
37+
};
38+
39+
assert_eq!(
40+
modifies_submodule(&[filediff]),
41+
Some(SUBMODULE_WARNING_MSG.to_string())
42+
)
43+
}
44+
45+
#[test]
46+
fn no_submodule_update_tricky_case() {
47+
let filediff = FileDiff {
48+
path: "src/tools.sh".to_string(),
49+
diff: "@@ -1 +1 @@\
50+
-let mut subproject_commit = 5;\
51+
+let mut subproject_commit = \"+Subproject commit \";"
52+
.to_string(),
53+
};
54+
55+
// FIXME: This should be true (aka None), but isn't currently!
56+
assert_eq!(modifies_submodule(&[filediff]), None)
57+
}

0 commit comments

Comments
 (0)