forked from compilerla/conventional-pre-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.sh
executable file
·54 lines (33 loc) · 959 Bytes
/
tests.sh
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
#!/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 "[email protected]"
git config user.name "conventional-pre-commit"
pre-commit install --hook-type commit-msg
git add .
}
teardown () {
cd "$this_dir"
rm -rf "$test_dir"
}
# 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 += "$?" ))
# 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 += "$?" ))
exit "$result"