Skip to content

Commit fda5bb1

Browse files
committed
scripts: add test_codeowners.sh
test cases for codeowners_pattern_to_regex(), though they aren't run automatically Signed-off-by: Casey Bodley <[email protected]>
1 parent 63ceb2b commit fda5bb1

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

scripts/test_codeowners.sh

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#!/bin/bash
2+
3+
. build_utils.sh
4+
5+
test_match() {
6+
local f=$1
7+
local p=$(codeowners_pattern_to_regex "$2")
8+
if [[ $f =~ $p ]]; then return 0; fi
9+
return 1
10+
}
11+
12+
# absolute matching
13+
test_match "/foo/bar" "/foo" || exit 1
14+
test_match "/a/foo" "/foo" && exit 1
15+
test_match "/foo/bar" "foo/bar" || exit 1
16+
test_match "/a/foo/bar" "foo/bar" && exit 1
17+
# relative matching
18+
test_match "/bar" "bar" || exit 1
19+
test_match "/foo/bar" "bar" || exit 1
20+
test_match "/foobar" "bar" && exit 1
21+
test_match "/foo/bar" "ba" && exit 1
22+
test_match "/foo/bar" "ar" && exit 1
23+
# directory-only matching
24+
test_match "/foo" "/foo/" && exit 1
25+
test_match "/foo/" "/foo/" && exit 1
26+
test_match "/foo/bar" "/foo/" || exit 1
27+
# asterisk
28+
test_match "/x" "/*" || exit 1
29+
test_match "/xy" "/*" || exit 1
30+
test_match "/Ax" "/A*" || exit 1
31+
test_match "/Axy" "/A*" || exit 1
32+
test_match "/Bx" "/A*" && exit 1
33+
test_match "/xA" "/*A" || exit 1
34+
test_match "/xyA" "/*A" || exit 1
35+
test_match "/xB" "/*A" && exit 1
36+
test_match "/AxyzB" "/A*B" || exit 1
37+
test_match "/A/B" "/A*B" && exit 1
38+
test_match "/AB" "/A*B" || exit 1
39+
test_match "/AxB" "/A*B" || exit 1
40+
test_match "/AxyzB" "/A*B" || exit 1
41+
test_match "/A/B" "/A*B" && exit 1
42+
test_match "/x.y" "/*.*" || exit 1
43+
test_match "/x." "/*.*" || exit 1
44+
test_match "/.y" "/*.*" || exit 1
45+
# question
46+
test_match "/AxB" "A?B" || exit 1
47+
test_match "/AB" "A?B" && exit 1
48+
test_match "/AxxB" "A?B" && exit 1
49+
test_match "/A/B" "A?B" && exit 1
50+
# double-asterisk
51+
test_match "/foo" "**/foo" || exit 1
52+
test_match "/x/foo" "**/foo" || exit 1
53+
test_match "/x/y/foo" "**/foo" || exit 1
54+
test_match "/foo/bar" "**/foo/bar" || exit 1
55+
test_match "/x/y/foo/bar" "**/foo/bar" || exit 1
56+
test_match "/x/y/bar" "**/foo/bar" && exit 1
57+
test_match "/abc/" "abc/**" || exit 1
58+
test_match "/abc/x" "abc/**" || exit 1
59+
test_match "/abc/x/y" "abc/**" || exit 1
60+
test_match "/foo/abc/" "abc/**" && exit 1
61+
test_match "/a/b" "a/**/b" || exit 1
62+
test_match "/a/x/b" "a/**/b" || exit 1
63+
test_match "/a/x/y/b" "a/**/b" || exit 1
64+
test_match "/foo/a/x/y/b" "a/**/b" && exit 1
65+
66+
echo "all tests passed"

0 commit comments

Comments
 (0)