corrade-nucleus-nucleons – Blame information for rev 2

Subversion Repositories:
Rev:
Rev Author Line No. Line
2 office 1 #!/usr/bin/env bash
2  
3 REL_SCRIPT_DIR="`dirname \"$0\"`"
4 SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
5  
6 test_cli_common()
7 {
8 echo ----------------------------------------
9 echo Testing common cli behavior...
10 CLI_SCRIPT_NAME=${1:?missing_param}
11 CLI_SCRIPT=$SCRIPT_DIR/../../$CLI_SCRIPT_NAME
12 echo Script: $CLI_SCRIPT
13  
14 # should find the minimal help output
15 $CLI_SCRIPT 2>&1 | grep -q "Must pipe input or define at least one file\." || {
16 $CLI_SCRIPT 2>&1
17 echo "[$CLI_SCRIPT_NAME] Output should be help message."
18 exit 1
19 }
20  
21 $CLI_SCRIPT 2> /dev/null && {
22 echo "[$CLI_SCRIPT_NAME (with no parameters)] Return code should be error."
23 exit 1
24 }
25  
26 $CLI_SCRIPT -Z 2> /dev/null && {
27 echo "[$CLI_SCRIPT_NAME -Z] Return code for invalid parameter should be error."
28 exit 1
29 }
30  
31 $CLI_SCRIPT -h > /dev/null || {
32 echo "[$CLI_SCRIPT_NAME -h] Return code should be success."
33 exit 1
34 }
35  
36 $CLI_SCRIPT -v > /dev/null || {
37 echo "[$CLI_SCRIPT_NAME -v] Return code should be success."
38 exit 1
39 }
40  
41 MISSING_FILE="$SCRIPT_DIR/../../../js/bin/missing_file"
42 MISSING_FILE_MESSAGE="No such file or directory"
43 $CLI_SCRIPT $MISSING_FILE 2> /dev/null && {
44 echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Return code should be error."
45 exit 1
46 }
47  
48 $CLI_SCRIPT $MISSING_FILE 2>&1 | grep -q "$MISSING_FILE_MESSAGE" || {
49 echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stderr should have useful message."
50 exit 1
51 }
52  
53 if [ "`$CLI_SCRIPT $MISSING_FILE 2> /dev/null`" != "" ]; then
54 echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stdout should have no text."
55 exit 1
56 fi
57  
58 }
59  
60 setup_temp()
61 {
62 mkdir -p target
63 TEST_TEMP=$PWD/`mktemp -d target/test_temp_XXXX`
64 echo Created $TEST_TEMP...
65 }
66  
67 cleanup()
68 {
69 rm -rf $TEST_TEMP && echo Removed $TEST_TEMP...
70 test -z $1 || exit $1
71 }
72  
73 test_cli_js_beautify()
74 {
75 echo ----------------------------------------
76 echo Testing js-beautify cli behavior...
77 CLI_SCRIPT=$SCRIPT_DIR/../../js-beautify
78  
79 $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js > /dev/null || {
80 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected succeed."
81 exit 1
82 }
83  
84 $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js > /dev/null || {
85 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/css-beautify.js was expected succeed."
86 exit 1
87 }
88  
89 $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - || {
90 $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - | cat -t -e
91 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected to be unchanged."
92 exit 1
93 }
94  
95 cat $SCRIPT_DIR/../../../js/bin/js-beautify.js | $CLI_SCRIPT | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - || {
96 $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - | cat -t -e
97 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected to be unchanged."
98 exit 1
99 }
100  
101 cat $SCRIPT_DIR/../../../js/bin/js-beautify.js | $CLI_SCRIPT - | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - || {
102 $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/js-beautify.js | diff $SCRIPT_DIR/../../../js/bin/js-beautify.js - | cat -t -e
103 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js was expected to be unchanged."
104 exit 1
105 }
106  
107 setup_temp
108 cat $SCRIPT_DIR/../../../js/bin/js-beautify.js | $CLI_SCRIPT -o $TEST_TEMP/js-beautify-pipe.js - || diff $SCRIPT_DIR/../../../js/bin/js-beautify.js $TEST_TEMP/js-beautify-pipe.js || {
109 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js should have been created in $TEST_TEMP/js-beautify-pipe.js."
110 cleanup 1
111 }
112  
113  
114 $CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js && diff $SCRIPT_DIR/../../../js/bin/js-beautify.js $TEST_TEMP/js-beautify.js || {
115 $CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js && diff $SCRIPT_DIR/../../../js/bin/js-beautify.js $TEST_TEMP/js-beautify.js | cat -t -e
116 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/js-beautify.js should have been created in $TEST_TEMP/js-beautify.js."
117 cleanup 1
118 }
119  
120 # ensure new line settings work
121 $CLI_SCRIPT -o $TEST_TEMP/js-beautify-n.js -e '\n' $SCRIPT_DIR/../../../js/bin/js-beautify.js
122 $CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn.js -e '\r\n' $TEST_TEMP/js-beautify-n.js
123  
124 # ensure eol processed correctly
125 # Issue #987 - strange error when processing --eol
126 # uncomment to reproduce
127 # $CLI_SCRIPT -o $TEST_TEMP/js-beautify-n-dash.js --indent-size 2 --eol '\n' $TEST_TEMP/js-beautify-n.js
128 # $CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn-dash.js --indent-size 2 --eol '\r\n' $TEST_TEMP/js-beautify-n.js
129 # diff -q $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js && {
130 # diff $TEST_TEMP/js-beautify-n-dash.js $TEST_TEMP/js-beautify-rn-dash.js | cat -t -e
131 # echo "js-beautify output for $TEST_TEMP/js-beautify-n-dash.js and $TEST_TEMP/js-beautify-rn-dash.js was expected to be different."
132 # cleanup 1
133 # }
134  
135 diff -q $TEST_TEMP/js-beautify-n.js $TEST_TEMP/js-beautify-rn.js && {
136 diff $TEST_TEMP/js-beautify-n.js $TEST_TEMP/js-beautify-rn.js | cat -t -e
137 echo "js-beautify output for $TEST_TEMP/js-beautify-n.js and $TEST_TEMP/js-beautify-rn.js was expected to be different."
138 cleanup 1
139 }
140  
141 $CLI_SCRIPT $TEST_TEMP/js-beautify-n.js | diff -q $TEST_TEMP/js-beautify-n.js - || {
142 echo "js-beautify output for $TEST_TEMP/js-beautify-n.js was expected to be unchanged."
143 cleanup 1
144 }
145  
146 $CLI_SCRIPT -e 'auto' $TEST_TEMP/js-beautify-rn.js | diff -q $TEST_TEMP/js-beautify-rn.js - || {
147 echo "js-beautify output for $TEST_TEMP/js-beautify-rn.js was expected to be unchanged."
148 cleanup 1
149 }
150  
151 # EditorConfig related tests
152 cp -r ../js/test/resources/editorconfig $TEST_TEMP/
153 $CLI_SCRIPT -o $TEST_TEMP/editorconfig/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
154 $CLI_SCRIPT -o $TEST_TEMP/editorconfig/example-ec.js --indent-size 2 -e '\n' $TEST_TEMP/editorconfig/example-base.js
155  
156 $CLI_SCRIPT -o $TEST_TEMP/editorconfig/cr/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
157 $CLI_SCRIPT -o $TEST_TEMP/editorconfig/cr/example-ec.js --indent-size 2 -e '\r' $TEST_TEMP/editorconfig/example-base.js
158  
159 $CLI_SCRIPT -o $TEST_TEMP/editorconfig/crlf/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
160 $CLI_SCRIPT -o $TEST_TEMP/editorconfig/crlf/example-ec.js --indent-size 2 -e '\r\n' $TEST_TEMP/editorconfig/example-base.js
161  
162 $CLI_SCRIPT -o $TEST_TEMP/editorconfig/error/example.js --end-with-newline --indent-size 4 -e '\n' $TEST_TEMP/editorconfig/example-base.js
163  
164 pushd $TEST_TEMP/editorconfig
165  
166 cd $TEST_TEMP/editorconfig/error
167 $CLI_SCRIPT --editorconfig $TEST_TEMP/js-beautify-n.js \
168 > /dev/null || {
169 echo "Invalid editorconfig file should not report error (consistent with the EditorConfig)."
170 cleanup 1
171 }
172  
173 $CLI_SCRIPT --editorconfig example.js \
174 > /dev/null || {
175 echo "Invalid editorconfig file should not report error (consistent with the EditorConfig)."
176 cleanup 1
177 }
178  
179 # TODO: EditorConfig setting should NOT overide cli setting, but that is
180 # the current by-design behavior, due to code limitations.
181  
182 # file input scenario
183 SCENARIO=a
184 cd $TEST_TEMP/editorconfig || exit 1
185 $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js example.js \
186 && diff -q example-${SCENARIO}.js example-ec.js || {
187 echo "EditorConfig setting should overide cli setting."
188 diff example-${SCENARIO}.js example-ec.js | cat -t -e
189 cleanup 1
190 }
191  
192 cd $TEST_TEMP/editorconfig/crlf || exit 1
193 $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js example.js \
194 && diff -q example-${SCENARIO}.js example-ec.js || {
195 echo "EditorConfig setting should overide cli setting."
196 diff example-${SCENARIO}.js example-ec.js | cat -t -e
197 cleanup 1
198 }
199  
200 cd $TEST_TEMP/editorconfig/cr || exit 1
201 $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js example.js \
202 && diff -q example-${SCENARIO}.js example-ec.js || {
203 echo "EditorConfig setting should overide cli setting."
204 diff example-${SCENARIO}.js example-ec.js | cat -t -e
205 cleanup 1
206 }
207  
208 # stdin input to stdout scenario
209 SCENARIO=b
210 cd $TEST_TEMP/editorconfig || exit 1
211 echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js"
212 cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js \
213 && diff -q example-${SCENARIO}.js example-ec.js || {
214 echo "EditorConfig setting should overide cli setting."
215 diff example-${SCENARIO}.js example-ec.js | cat -t -e
216 cleanup 1
217 }
218  
219 cd $TEST_TEMP/editorconfig/crlf || exit 1
220 echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js"
221 cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js \
222 && diff -q example-${SCENARIO}.js example-ec.js || {
223 echo "EditorConfig setting should overide cli setting."
224 diff example-${SCENARIO}.js example-ec.js | cat -t -e
225 cleanup 1
226 }
227  
228 cd $TEST_TEMP/editorconfig/cr || exit 1
229 echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js"
230 cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig > example-${SCENARIO}.js \
231 && diff -q example-${SCENARIO}.js example-ec.js || {
232 echo "EditorConfig setting should overide cli setting."
233 diff example-${SCENARIO}.js example-ec.js | cat -t -e
234 cleanup 1
235 }
236  
237  
238 # stdin input to file scenario
239 SCENARIO=c
240 cd $TEST_TEMP/editorconfig || exit 1
241 echo "cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js"
242 cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js - \
243 && diff -q example-${SCENARIO}.js example-ec.js || {
244 echo "EditorConfig setting should overide cli setting."
245 diff example-${SCENARIO}.js example-ec.js | cat -t -e
246 cleanup 1
247 }
248  
249 cd $TEST_TEMP/editorconfig/crlf || exit 1
250 cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js - \
251 && diff -q example-${SCENARIO}.js example-ec.js || {
252 echo "EditorConfig setting should overide cli setting."
253 diff example-${SCENARIO}.js example-ec.js | cat -t -e
254 cleanup 1
255 }
256  
257 cd $TEST_TEMP/editorconfig/cr || exit 1
258 cat example.js | $CLI_SCRIPT --end-with-newline --indent-size 6 --editorconfig -o example-${SCENARIO}.js - \
259 && diff -q example-${SCENARIO}.js example-ec.js || {
260 echo "EditorConfig setting should overide cli setting."
261 diff example-${SCENARIO}.js example-ec.js | cat -t -e
262 cleanup 1
263 }
264  
265 popd
266 # End EditorConfig
267  
268 # ensure unchanged files are not overwritten
269 $CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $SCRIPT_DIR/../../../js/bin/js-beautify.js
270 cp -p $TEST_TEMP/js-beautify.js $TEST_TEMP/js-beautify-old.js
271 touch $TEST_TEMP/js-beautify.js
272 sleep 2
273 touch $TEST_TEMP/js-beautify-old.js
274 $CLI_SCRIPT -r $TEST_TEMP/js-beautify.js && test $TEST_TEMP/js-beautify.js -nt $TEST_TEMP/js-beautify-old.js && {
275 echo "js-beautify should not replace unchanged file $TEST_TEMP/js-beautify.js when using -r"
276 cleanup 1
277 }
278  
279 $CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $TEST_TEMP/js-beautify.js && test $TEST_TEMP/js-beautify.js -nt $TEST_TEMP/js-beautify-old.js && {
280 echo "js-beautify should not replace unchanged file $TEST_TEMP/js-beautify.js when using -o and same file name"
281 cleanup 1
282 }
283  
284 $CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $TEST_TEMP/js-beautify-old.js && test $TEST_TEMP/js-beautify.js -nt $TEST_TEMP/js-beautify-old.js && {
285 echo "js-beautify should not replace unchanged file $TEST_TEMP/js-beautify.js when using -o and different file name"
286 cleanup 1
287 }
288  
289 $CLI_SCRIPT $SCRIPT_DIR/../../../js/bin/css-beautify.js | diff -q $SCRIPT_DIR/../../../js/bin/css-beautify.js - && {
290 echo "js-beautify output for $SCRIPT_DIR/../../../js/bin/css-beautify.js was expected to be different."
291 cleanup 1
292 }
293  
294 cleanup
295 }
296  
297 test_smoke_js_beautify()
298 {
299 echo ----------------------------------------
300 echo Testing beautify functionality...
301 $SCRIPT_DIR/../../js-beautify-test.py || exit 1
302 }
303  
304 test_perf_js_beautify()
305 {
306 echo ----------------------------------------
307 echo Testing beautify performance...
308 # PYTHON=python $SCRIPT_DIR/../../js-beautify-profile || exit 1
309 $SCRIPT_DIR/test-perf-jsbeautifier.py || exit 1
310 }
311  
312 main() {
313 #test_cli_common css-beautify
314 #test_cli_common html-beautify
315 test_cli_common js-beautify
316  
317 test_cli_js_beautify
318 test_smoke_js_beautify
319 test_perf_js_beautify
320  
321 echo ----------------------------------------
322 echo $0 - PASSED.
323 echo ----------------------------------------
324 }
325  
326 (main $*)