corrade-nucleus-nucleons – Blame information for rev 20

Subversion Repositories:
Rev:
Rev Author Line No. Line
20 office 1 #!/usr/bin/env bash
2  
3 REL_SCRIPT_DIR="`dirname \"$0\"`"
4 SCRIPT_DIR="`( cd \"$REL_SCRIPT_DIR\" && pwd )`"
5  
6  
7 test_cli_common()
8 {
9 echo ----------------------------------------
10 echo Testing common cli behavior...
11 CLI_SCRIPT_NAME=${1:?missing_param}.js
12 CLI_SCRIPT=$SCRIPT_DIR/../bin/$CLI_SCRIPT_NAME
13 echo Script: $CLI_SCRIPT
14  
15 # should find the minimal help output
16 $CLI_SCRIPT 2>&1 | grep -q "Must pipe input or define at least one file\." || {
17 $CLI_SCRIPT 2>&1
18 echo "[$CLI_SCRIPT_NAME] Output should be help message."
19 exit 1
20 }
21  
22 $CLI_SCRIPT 2> /dev/null && {
23 echo "[$CLI_SCRIPT_NAME (with no parameters)] Return code should be error."
24 exit 1
25 }
26  
27 $CLI_SCRIPT -Z 2> /dev/null && {
28 echo "[$CLI_SCRIPT_NAME -Z] Return code for invalid parameter should be error."
29 exit 1
30 }
31  
32 $CLI_SCRIPT -h > /dev/null || {
33 echo "[$CLI_SCRIPT_NAME -h] Return code should be success."
34 exit 1
35 }
36  
37 $CLI_SCRIPT -v > /dev/null || {
38 echo "[$CLI_SCRIPT_NAME -v] Return code should be success."
39 exit 1
40 }
41  
42 MISSING_FILE="$SCRIPT_DIR/../../../js/bin/missing_file"
43 MISSING_FILE_MESSAGE="Unable to open path"
44 $CLI_SCRIPT $MISSING_FILE 2> /dev/null && {
45 echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Return code should be error."
46 exit 1
47 }
48  
49 $CLI_SCRIPT $MISSING_FILE 2>&1 | grep -q "$MISSING_FILE_MESSAGE" || {
50 echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stderr should have useful message."
51 exit 1
52 }
53  
54 if [ "`$CLI_SCRIPT $MISSING_FILE 2> /dev/null`" != "" ]; then
55 echo "[$CLI_SCRIPT_NAME $MISSING_FILE] Stdout should have no text."
56 exit 1
57 fi
58  
59 }
60  
61 setup_temp()
62 {
63 mkdir -p target
64 TEST_TEMP=$PWD/`mktemp -d target/test_temp_XXXX`
65 echo Created $TEST_TEMP...
66 }
67  
68 cleanup()
69 {
70 rm -rf $TEST_TEMP && echo Removed $TEST_TEMP...
71 test -z $1 || exit $1
72 }
73  
74  
75 test_cli_js_beautify()
76 {
77 echo ----------------------------------------
78 echo Testing js-beautify cli behavior...
79 CLI_SCRIPT=$SCRIPT_DIR/../bin/js-beautify.js
80  
81 $CLI_SCRIPT $SCRIPT_DIR/../bin/js-beautify.js > /dev/null || {
82 echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected succeed."
83 exit 1
84 }
85  
86 $CLI_SCRIPT $SCRIPT_DIR/../bin/css-beautify.js > /dev/null || {
87 echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected succeed."
88 exit 1
89 }
90  
91 $CLI_SCRIPT $SCRIPT_DIR/../bin/js-beautify.js | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
92 echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
93 exit 1
94 }
95  
96 node $SCRIPT_DIR/../lib/cli.js $SCRIPT_DIR/../bin/js-beautify.js | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
97 echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
98 exit 1
99 }
100  
101 cat $SCRIPT_DIR/../bin/js-beautify.js | $CLI_SCRIPT | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
102 echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
103 exit 1
104 }
105  
106 cat $SCRIPT_DIR/../bin/js-beautify.js | $CLI_SCRIPT - | diff $SCRIPT_DIR/../bin/js-beautify.js - || {
107 echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js was expected to be unchanged."
108 exit 1
109 }
110  
111 setup_temp
112 cat $SCRIPT_DIR/../bin/js-beautify.js | $CLI_SCRIPT -o $TEST_TEMP/js-beautify-pipe.js - && diff $TEST_TEMP/js-beautify-pipe.js $SCRIPT_DIR/../bin/js-beautify.js || {
113 echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js should have been created in $TEST_TEMP/js-beautify-pipe.js."
114 cleanup 1
115 }
116  
117 $CLI_SCRIPT -o $TEST_TEMP/js-beautify.js $SCRIPT_DIR/../bin/js-beautify.js && diff $SCRIPT_DIR/../bin/js-beautify.js $TEST_TEMP/js-beautify.js || {
118 echo "js-beautify output for $SCRIPT_DIR/../bin/js-beautify.js should have been created in $TEST_TEMP/js-beautify.js."
119 cleanup 1
120 }
121  
122 # ensure new line settings work
123 $CLI_SCRIPT -o $TEST_TEMP/js-beautify-n.js -e '\n' $SCRIPT_DIR/../bin/js-beautify.js
124 $CLI_SCRIPT -o $TEST_TEMP/js-beautify-rn.js -e '\r\n' $TEST_TEMP/js-beautify-n.js
125  
126 # ensure eol processed correctly
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/../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/../bin/css-beautify.js | diff -q $SCRIPT_DIR/../bin/css-beautify.js - && {
290 echo "js-beautify output for $SCRIPT_DIR/../bin/css-beautify.js was expected to be different."
291 cleanup 1
292 }
293  
294 unset HOME
295 unset USERPROFILE
296 $CLI_SCRIPT -o $TEST_TEMP/example1-default.js $SCRIPT_DIR/resources/example1.js || exit 1
297  
298 $CLI_SCRIPT -o $TEST_TEMP/example1-sanity.js $TEST_TEMP/example1-default.js || exit 1
299 diff -q $TEST_TEMP/example1-default.js $TEST_TEMP/example1-sanity.js || {
300 echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be identical after no change in settings."
301 cleanup 1
302 }
303  
304 cd $SCRIPT_DIR/resources/configerror
305 $CLI_SCRIPT $TEST_TEMP/example1-default.js 2>&1 | grep -q "Error while loading beautifier configuration\." || {
306 echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be configration load error message."
307 cleanup 1
308 }
309  
310 cd $SCRIPT_DIR/resources/indent11chars
311 $CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
312 echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on CWD settings."
313 cleanup 1
314 }
315  
316 cd $SCRIPT_DIR/resources/indent11chars/subDir1/subDir2
317 $CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
318 echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on CWD parent folder settings."
319 cleanup 1
320 }
321 cd $SCRIPT_DIR
322  
323 export HOME=$SCRIPT_DIR/resources/indent11chars
324 $CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
325 echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on HOME settings."
326 cleanup 1
327 }
328  
329 $CLI_SCRIPT -o $TEST_TEMP/example1-indent11chars.js $TEST_TEMP/example1-default.js
330  
331 unset HOME
332 export USERPROFILE=$SCRIPT_DIR/resources/indent11chars
333 # node -p 'process.env["USERPROFILE"] || process.env["HOME"] || "unset"'
334 $CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-indent11chars.js - || {
335 echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be identical for same HOME and USERPROFILE settings."
336 cleanup 1
337 }
338  
339 $CLI_SCRIPT $TEST_TEMP/example1-default.js | diff -q $TEST_TEMP/example1-default.js - && {
340 echo "js-beautify output for $TEST_TEMP/example1-default.js was expected to be different based on USERPROFILE settings."
341 cleanup 1
342 }
343  
344 cleanup
345 }
346  
347 test_smoke_js_beautify()
348 {
349 echo ----------------------------------------
350 echo Testing js-beautify functionality...
351 node $SCRIPT_DIR/node-beautify-tests.js || exit 1
352 node $SCRIPT_DIR/amd-beautify-tests.js || exit 1
353 }
354  
355  
356 test_performance_js_beautify()
357 {
358 echo ----------------------------------------
359 echo Testing js-beautify performance...
360 node $SCRIPT_DIR/node-beautify-perf-tests.js || exit 1
361 echo ----------------------------------------
362 }
363  
364 test_performance_html_beautify()
365 {
366 echo ----------------------------------------
367 echo Testing html-beautify performance...
368 node $SCRIPT_DIR/node-beautify-html-perf-tests.js || exit 1
369 echo ----------------------------------------
370 }
371  
372 test_cli_common css-beautify
373 test_cli_common html-beautify
374 test_cli_common js-beautify
375  
376 test_cli_js_beautify
377 test_smoke_js_beautify
378 test_performance_js_beautify
379 test_performance_html_beautify
380  
381 echo ----------------------------------------
382 echo $0 - PASSED.
383 echo ----------------------------------------