-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
executable file
·130 lines (111 loc) · 4.6 KB
/
test.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env bash
set -eo pipefail
echo Running tests...
source ./lib/main.bash
failed_tests=0
function expect_to_equal() {
local actual="$1"
local expected="$2"
local label="$3"
if [ "$actual" == "$expected" ]; then
printf '.' # no newline
return
fi
echo
echo "- Test failed: \`$label\`"
actual_msg=`f -b "$actual"`
expected_msg=`f -b "$expected"`
echo " - Expected ${actual_msg} to be ${expected_msg}"
echo
failed_tests=$((failed_tests+1))
}
function test() {
local function_call_string="$1"
local operator="$2"
local expected="$3"
if [ "$operator" != '==' ]; then
echo "Invalid operator '$operator' for test '$*'"
return
fi
local result=`eval $function_call_string`
expect_to_equal "$result" "$expected" "$function_call_string"
}
# ************************* Test: commit_message_to_branch *************************
test 'commit_message_to_branch "hello world"' \
== "hello-world"
test 'commit_message_to_branch "hello world with lots of words"' \
== "hello-world-with-lots-of-words"
test 'commit_message_to_branch "hello: world stuff"' \
== "hello/world-stuff"
test 'commit_message_to_branch "Hello: World stuff"' \
== "hello/world-stuff"
test 'commit_message_to_branch "Hello: World__stuff"' \
== "hello/world-stuff"
test 'commit_message_to_branch "Hello: world stuff"' \
== "hello/world-stuff"
test 'commit_message_to_branch "Hello: world stuff - part 1 - fix things"' \
== "hello/world-stuff--part-1--fix-things"
test 'commit_message_to_branch "Hello: world stuff with lots of words"' \
== "hello/world-stuff-with-lots-of-words"
test 'commit_message_to_branch "JIRA-123: Hello world stuff"' \
== "JIRA-123/hello-world-stuff"
test 'commit_message_to_branch "JIRA-123 Hello world stuff"' \
== "jira-123-hello-world-stuff"
test 'commit_message_to_branch "Testing stuff: Hello world"' \
== "testing-stuff/hello-world"
# Remove extraneous symbols
test 'commit_message_to_branch '\''hello,world, we do stuff and/or things !@#$ %% ^ &*()_+=-[]\\{}|",./<>?~ lol'\' \
== "hello-world-we-do-stuff-and-or-things-lol"
test 'commit_message_to_branch "hello '\'' world"' \
== "hello-world"
# Remove extra colons
test 'commit_message_to_branch "hello: this: is: a: test"' \
== "hello/this-is-a-test"
# Current behaviour, TODO do we want to keep this?
test 'commit_message_to_branch "feat(example cool-domain): make cooler"' \
== "feat(example-cool-domain)/make-cooler"
# ************************* Test: branch_to_commit_message *************************
test 'branch_to_commit_message "hello-world"' \
== "Hello world"
test 'branch_to_commit_message "hello-world-with-lots-of-words"' \
== "Hello world with lots of words"
test 'branch_to_commit_message "hello/world-stuff"' \
== "hello: World stuff"
test 'branch_to_commit_message "hello/world-stuff--part-1--fix-things"' \
== "hello: World stuff - part 1 - fix things"
test 'branch_to_commit_message "hello/world-stuff-with-lots-of-words"' \
== "hello: World stuff with lots of words"
test 'branch_to_commit_message "JIRA-123/hello-world-stuff"' \
== "JIRA-123: Hello world stuff"
test 'branch_to_commit_message "JIRA-9375017/hello-world-stuff"' \
== "JIRA-9375017: Hello world stuff"
test 'branch_to_commit_message "testing-stuff/hello-world"' \
== "testing stuff: Hello world"
# Current behaviour, TODO do we want to keep this?
test 'branch_to_commit_message "feat(example-cool-domain)/make-cooler"' \
== "feat(example cool domain): Make cooler"
# ************************* Test: reformat_clipboard_to_commit_message *************************
test 'printf "hello world" | reformat_clipboard_to_commit_message' \
== "hello world"
test 'printf "custom prefix: testing" | reformat_clipboard_to_commit_message' \
== "custom prefix: testing"
test 'printf "custom prefix:\n\ntesting" | reformat_clipboard_to_commit_message' \
== "custom prefix: testing"
test 'printf "custom prefix\n\n\ntesting" | reformat_clipboard_to_commit_message' \
== "custom prefix: testing"
test 'printf "JIRA-123 Hello world stuff" | reformat_clipboard_to_commit_message' \
== "JIRA-123: Hello world stuff"
test 'printf "JIRA-123 Hello world stuff" | reformat_clipboard_to_commit_message' \
== "JIRA-123: Hello world stuff"
test 'printf "ARIJ-987654\n\n\nThis is a test ARIJ task\n" | reformat_clipboard_to_commit_message' \
== "ARIJ-987654: This is a test ARIJ task"
echo
echo
if [ "$failed_tests" == "0" ]; then
echo All tests passed!
exit 0
else
f -b "${failed_tests} tests failed"
echo `not_bold`
exit 1
fi