-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest
89 lines (77 loc) · 1.57 KB
/
test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/bin/sh
# test commitlint-sh
#
text_red() {
[ -z "$NO_COLOR" ] && printf '\033[31m%s\033[m' "$@" || printf '%s\n' "$@"
}
_test_count=0
failed=0
passed=0
_test_num="$(grep -c '^_test ' "$(basename "$0")")"
_test() {
# if first arg is ! , test for failing command
assert_pass() {
echo "$*" | ./commitlint
}
assert_fail() {
echo "$*" | ./commitlint 2>&1 | grep -q ERROR
}
run_test_command() {
if [ "$1" = "!" ]; then
shift
assert_fail "$*"
return
else
assert_pass "$*"
return
fi
}
_command="$*"
_test_count=$((_test_count + 1))
if run_test_command "$@"; then
_result="PASS"
passed=$((passed + 1))
else
failed=$((failed + 1))
_result="$(text_red FAIL)"
fi
echo "(${_test_count}/${_test_num}) $_result '$_command'"
}
# custom rules
_test "initial commit"
_test ! "initial Commit"
_test ! "Initial Commit"
_test 'Revert "french toast"'
_test 'Revert "initial commit"'
_test ! 'revert "initial commit"'
_test ! 'revert foo'
# conventionalcommits
## Subject
_test "feat: foo"
_test ! "documentation: foo"
_test ! "invalid: foo"
_test ! "Feat: foo"
_test ! "feat: !foo"
## Scope
_test ! "feat(): foo"
_test "feat(module): foo"
_test "feat(module): foo bar baz"
_test "feat(package/module): foo"
_test "feat(package/mod_ule): foo"
## Breaking Changes
_test "feat!: foo"
_test "feat(bar)!: foo"
_test ! "feat!!: foo"
_test ! "feat(bar)!!: foo"
_test "feat!: foo!"
_test "feat!: foo!!"
_test "feat: foo!"
_test "feat: foo!!"
_test "feat!: foo"
_test "feat(module)!: foo"
_test ! "feat!(module)!: foo"
cat <<!
SUMMARY
$_test_count tests
$failed failures
!