forked from compilerla/conventional-pre-commit
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtests.sh
More file actions
executable file
·116 lines (64 loc) · 1.98 KB
/
tests.sh
File metadata and controls
executable file
·116 lines (64 loc) · 1.98 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/env bash
this_dir="$PWD"
test_dir=""
result=0
setup () {
test_dir=$(mktemp -d)
cp "$this_dir/.pre-commit-config.yaml" "$test_dir/"
cp "$this_dir/conventional-pre-commit.sh" "$test_dir/"
cd "$test_dir"
git init
git branch -m main
git config user.email "conventional-pre-commit@compiler.la"
git config user.name "conventional-pre-commit"
pre-commit install --hook-type commit-msg
git add .
}
teardown () {
cd "$this_dir"
rm -rf "$test_dir"
}
echo "test a failure"
setup
fail="$(git commit -m 'bad: conventional-pre-commit' 2>&1 > /dev/null)"
teardown
echo "$fail" | grep -Eq "Your commit message does not follow Conventional Commits formatting"
(( result += "$?" ))
echo "$result"
echo "test a success"
setup
pass="$(git commit -m 'test: conventional-pre-commit')"
teardown
echo "$pass" | grep -Eq "\[main \(root-commit\) [[:alnum:]]{7}\] test: conventional-pre-commit"
(( result += "$?" ))
echo "$result"
echo "test printable characters/marks in subject"
echo "test escaped double quote \""
setup
pass="$(git commit -m 'test: conventional-pre-commit "')"
teardown
echo "$pass" | grep -Eq "\[main \(root-commit\) [[:alnum:]]{7}\] test: conventional-pre-commit \""
(( result += "$?" ))
echo "$result"
echo "test backtick \`"
setup
pass="$(git commit -m 'test: conventional-pre-commit `')"
teardown
echo "$pass" | grep -Eq "\[main \(root-commit\) [[:alnum:]]{7}\] test: conventional-pre-commit \`"
(( result += "$?" ))
echo "$result"
echo "test hash/number sign #"
setup
pass="$(git commit -m 'test: conventional-pre-commit #')"
teardown
echo "$pass" | grep -Eq "\[main \(root-commit\) [[:alnum:]]{7}\] test: conventional-pre-commit #"
(( result += "$?" ))
echo "$result"
echo "test ampersand &"
setup
pass="$(git commit -m 'test: conventional-pre-commit &')"
teardown
echo "$pass" | grep -Eq "\[main \(root-commit\) [[:alnum:]]{7}\] test: conventional-pre-commit &"
(( result += "$?" ))
echo "$result"
exit "$result"