-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.sh
executable file
·184 lines (124 loc) · 3.95 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
#!/usr/bin/env bash
cli=$1
function ok {
echo -e ' \033[32m✓\033[0m'
}
function fail {
echo -e ' \033[31m✗\033[0m'
exit_status=1
}
# Print test title
function test {
echo -n "$1"
}
# Print group of tests title
function group {
echo -e "\n\033[2m*** $1\033[0m"
}
# Create a sandbox folder to run the tests in isolation
function sandbox {
mkdir sandbox ; cd sandbox
}
# Cleanup the sandbox
function clean {
cd .. ; rm -R sandbox
}
echo Running test suite...
test "prints help (-h)"
if [[ $($cli -h) =~ Usage: ]]; then ok; else fail; fi
test "prints help (--help)"
if [[ $($cli --help) =~ Usage: ]]; then ok; else fail; fi
test "prints version (-V)"
if [ "$($cli -V)" == 2.0.0 ]; then ok; else fail; fi
test "prints version (--version)"
if [ "$($cli --version)" == 2.0.0 ]; then ok; else fail; fi
echo When invalid arg provided,
test " prints to stderr"
if [[ "$($cli --badarg 2>&1)" =~ "elm-new: illegal option --badarg" ]]; then ok; else fail; fi
test " prints synopsis to stdout"
if [[ "$($cli --badarg 2>/dev/null)" =~ Usage: ]]; then ok; else fail; fi
test " exits with error"
if ! $cli --badarg >/dev/null 2>&1; then ok; else fail; fi
sandbox
group "Running $cli with no args..."
../$cli >/dev/null
test "elm.json exists"
if [ -f elm.json ]; then ok; else fail; fi
test "It's an application"
if grep --quiet application elm.json; then ok; else fail; fi
test "README.md exists"
if [ -f README.md ]; then ok; else fail; fi
test ".gitignore exists"
if [ -f .gitignore ]; then ok; else fail; fi
test "src/ exists"
if [ -d src ]; then ok; else fail; fi
test "src/Main.elm exists"
if [ -f src/Main.elm ]; then ok; else fail; fi
test "It's a Browser.document"
if grep --quiet Browser.document src/Main.elm; then ok; else fail; fi
clean
sandbox
group "Running $cli --beginner..."
../$cli --beginner >/dev/null
test "elm.json exists"
if [ -f elm.json ]; then ok; else fail; fi
test "README.md exists"
if [ -f README.md ]; then ok; else fail; fi
test ".gitignore exists"
if [ -f .gitignore ]; then ok; else fail; fi
test "src/ exists"
if [ -d src ]; then ok; else fail; fi
test "src/Main.elm exists"
if [ -f src/Main.elm ]; then ok; else fail; fi
test "It's a Browser.sandbox"
if grep --quiet Browser.sandbox src/Main.elm; then ok; else fail; fi
clean
sandbox
group "Running $cli --hello-world..."
../$cli --hello-world >/dev/null
test "elm.json exists"
if [ -f elm.json ]; then ok; else fail; fi
test "README.md exists"
if [ -f README.md ]; then ok; else fail; fi
test ".gitignore exists"
if [ -f .gitignore ]; then ok; else fail; fi
test "src/ exists"
if [ -d src ]; then ok; else fail; fi
test "src/Main.elm exists"
if [ -f src/Main.elm ]; then ok; else fail; fi
test "It's a 'Hello world' program"
if grep --quiet "Hello, World!" src/Main.elm; then ok; else fail; fi
clean
sandbox
group "Running $cli somepath --hello-world --beginner..."
../$cli somepath --hello-world --beginner >/dev/null
test "elm.json exists"
if [ -f somepath/elm.json ]; then ok; else fail; fi
test "README.md exists"
if [ -f somepath/README.md ]; then ok; else fail; fi
test ".gitignore exists"
if [ -f somepath/.gitignore ]; then ok; else fail; fi
test "src/ exists"
if [ -d somepath/src ]; then ok; else fail; fi
test "src/Main.elm exists"
if [ -f somepath/src/Main.elm ]; then ok; else fail; fi
test "It's a Browser.sandbox"
if grep --quiet Browser.sandbox somepath/src/Main.elm; then ok; else fail; fi
clean
sandbox
group "Running $cli --navigation nav..."
../$cli --navigation nav >/dev/null
test "elm.json exists"
if [ -f nav/elm.json ]; then ok; else fail; fi
test "README.md exists"
if [ -f nav/README.md ]; then ok; else fail; fi
test ".gitignore exists"
if [ -f nav/.gitignore ]; then ok; else fail; fi
test "src/ exists"
if [ -d nav/src ]; then ok; else fail; fi
test "src/Main.elm exists"
if [ -f nav/src/Main.elm ]; then ok; else fail; fi
test "It's a Browser.application"
if grep --quiet Browser.application nav/src/Main.elm; then ok; else fail; fi
clean
exit $exit_status