Codebase list clitest / 907e3624-ea26-4372-b4d3-22d81a63bf80/main
New upstream snapshot. Debian Janitor 1 year, 6 months ago
13 changed file(s) with 237 addition(s) and 113 deletion(s). Raw diff Collapse all Expand all
0 // https://aka.ms/devcontainer.json
1 {
2 "name": "clitest dev",
3 //
4 // https://github.com/aureliojargas/devcontainer
5 "image": "ghcr.io/aureliojargas/devcontainer",
6 //
7 // https://aka.ms/vscode-remote/containers/non-root
8 "remoteUser": "vscode",
9 //
10 // https://github.com/devcontainers/features/tree/main/src
11 "features": {
12 "github-cli": "latest",
13 // Makefile commands are run inside the clitest-dev Docker container
14 "docker-in-docker": "latest"
15 }
16 }
+0
-1
.gitignore less more
0 .vscode
+0
-10
.travis.yml less more
0 language: bash
1
2 script:
3 - make docker-build
4 - make versions
5 - make lint
6 - make test
7
8 notifications:
9 email: false
0 # Developer workflow: run locally the same commands Travis will run in
1 # the CI. See the .travis.yml file for the list of commands.
0 # Developer workflow: run locally the same commands the CI will run.
1 # See the .github/workflows/check.yml file for the list of commands.
22 #
33 # By default, the linting and testing targets are run inside the
44 # clitest-dev Docker container. To run them directly on the host,
88 # make test-bash docker_run= # test using host's bash
99
1010 docker_image = clitest-dev
11 docker_run = docker run --rm -it -v $$PWD:/mnt $(docker_image)
11 docker_run = docker run --rm -t -v $$PWD:/mnt $(docker_image)
1212 test_cmd = ./clitest --first --progress none test.md
1313
1414 default:
463463 - ksh
464464 - sh (busybox)
465465 - zsh
466
467 > Fish shell is not supported (it's not POSIX), but you
468 > can use [doctest.fish][27] instead.
466469
467470 Portability issues are considered serious bugs, please
468471 [report them][14]!
516519 [24]: https://github.com/funcoeszz/funcoeszz/tree/master/testador
517520 [25]: https://linux.die.net/man/1/checkbashisms
518521 [26]: https://www.shellcheck.net/
522 [27]: https://github.com/aureliojargas/doctest.fish
2626
2727 tt_my_name="$(basename "$0")"
2828 tt_my_url='https://github.com/aureliojargas/clitest'
29 tt_my_version='0.4.0'
29 tt_my_version='dev'
3030
3131 # Customization (if needed, edit here or use the command line options)
3232 tt_prefix=''
8989 tt_skip_range=
9090 tt_skip_range_data=
9191 tt_failed_range=
92 tt_temp_dir=
9293 tt_test_file=
9394 tt_input_line=
9495 tt_line_number=0
112113 ### Utilities
113114
114115 tt_clean_up() {
115 rm -rf "$tt_temp_dir"
116 test -n "$tt_temp_dir" && rm -rf "$tt_temp_dir"
116117 }
117118 tt_message() {
118119 test "$tt_output_mode" = 'quiet' && return 0
130131 tt_error() {
131132 test $tt_missing_nl -eq 1 && echo
132133 printf '%s\n' "$tt_my_name: Error: $1" >&2
133 tt_clean_up
134134 exit 2
135135 }
136136 tt_debug() { # $1=id, $2=contents
137137 test $tt_debug -ne 1 && return 0
138138 if test INPUT_LINE = "$1"; then
139 # Original input line is all blue
140 printf "${tt_color_blue}[%10s: %s]${tt_color_off}\n" "$1" "$2"
139 # Original input line is all cyan and preceded by separator line
140 printf -- "${tt_color_cyan}%s${tt_color_off}\n" "$(tt_separator_line)"
141 printf -- "${tt_color_cyan}-- %10s[%s]${tt_color_off}\n" "$1" "$2"
141142 else
142 # Highlight tabs and inline prefix
143 printf "${tt_color_blue}[%10s:${tt_color_off} %s${tt_color_blue}]${tt_color_off}\n" "$1" "$2" |
144 sed "/LINE_CMD:/ s/$tt_inline_prefix/${tt_color_red}&${tt_color_off}/g" |
143 # Highlight tabs and the (last) inline prefix
144 printf -- "${tt_color_cyan}-- %10s[${tt_color_off}%s${tt_color_cyan}]${tt_color_off}\n" "$1" "$2" |
145 sed "/LINE_CMD/ s/\(.*\)\($tt_inline_prefix\)/\1${tt_color_red}\2${tt_color_off}/" |
145146 sed "s/$tt_tab/${tt_color_green}<tab>${tt_color_off}/g"
146147 fi
147148 }
297298 ;;
298299 esac
299300
300 #tt_debug EVAL "$tt_test_command"
301 tt_debug EVAL "$tt_test_command"
301302
302303 # Execute the test command, saving output (STDOUT and STDERR)
303 eval "$tt_test_command" > "$tt_test_output_file" 2>&1
304 eval "$tt_test_command" > "$tt_test_output_file" 2>&1 < /dev/null
304305 tt_test_exit_code=$?
305306
306 #tt_debug OUTPUT "$(cat "$tt_test_output_file")"
307 tt_debug OUTPUT "$(cat "$tt_test_output_file")"
307308
308309 # The command output matches the expected output?
309310 case $tt_test_mode in
417418
418419 # Should I abort now?
419420 if test $tt_stop_on_first_fail -eq 1; then
420 tt_clean_up
421421 exit 1
422422 fi
423423
441441 # Note: read -r to preserve the backslashes
442442 while IFS='' read -r tt_input_line || test -n "$tt_input_line"; do
443443 tt_line_number=$((tt_line_number + 1))
444 #tt_debug INPUT_LINE "$tt_input_line"
444 tt_debug INPUT_LINE "$tt_input_line"
445445
446446 case "$tt_input_line" in
447447
448448 "$tt_prefix$tt_prompt" | "$tt_prefix${tt_prompt% }" | "$tt_prefix$tt_prompt ")
449449 # Prompt alone: closes previous command line (if any)
450450
451 #tt_debug 'LINE_$' "$tt_input_line"
451 tt_debug 'LINE_$' "$tt_input_line"
452452
453453 # Run pending tests
454454 test -n "$tt_test_command" && tt_run_test
457457 "$tt_prefix$tt_prompt"*)
458458 # This line is a command line to be tested
459459
460 #tt_debug LINE_CMD "$tt_input_line"
460 tt_debug LINE_CMD "$tt_input_line"
461461
462462 # Run pending tests
463463 test -n "$tt_test_command" && tt_run_test
474474 tt_test_command="${tt_test_command%"$tt_inline_prefix"*}"
475475 tt_test_inline="${tt_input_line##*"$tt_inline_prefix"}"
476476
477 #tt_debug NEW_CMD "$tt_test_command"
478 #tt_debug OK_INLINE "$tt_test_inline"
477 tt_debug NEW_CMD "$tt_test_command"
478 tt_debug OK_INLINE "$tt_test_inline"
479479
480480 # Maybe the OK text has options?
481481 case "$tt_test_inline" in
516516 ;;
517517 esac
518518
519 #tt_debug OK_TEXT "$tt_test_inline"
519 tt_debug OK_TEXT "$tt_test_inline"
520520
521521 # There must be a number in --lines and --exit
522522 if test "$tt_test_mode" = 'lines' || test "$tt_test_mode" = 'exit'; then
538538 # It's a normal command line, output begins in next line
539539 tt_test_mode='output'
540540
541 #tt_debug NEW_CMD "$tt_test_command"
541 tt_debug NEW_CMD "$tt_test_command"
542542 fi
543543 ;;
544544
545545 *)
546546 # Test output, blank line or comment
547547
548 #tt_debug 'LINE_*' "$tt_input_line"
548 tt_debug 'LINE_MISC' "$tt_input_line"
549549
550550 # Ignore this line if there's no pending test
551551 test -n "$tt_test_command" || continue
552552
553553 # Required prefix is missing: we just left a command block
554554 if test -n "$tt_prefix" && test "${tt_input_line#"$tt_prefix"}" = "$tt_input_line"; then
555 #tt_debug BLOCK_OUT "$tt_input_line"
555 tt_debug BLOCK_OUT "$tt_input_line"
556556
557557 # Run the pending test and we're done in this line
558558 tt_run_test
562562 # This line is a test output, save it (without prefix)
563563 tt_test_ok_text="$tt_test_ok_text${tt_input_line#"$tt_prefix"}$tt_nl"
564564
565 #tt_debug OK_TEXT "${tt_input_line#"$tt_prefix"}"
565 tt_debug OK_TEXT "${tt_input_line#"$tt_prefix"}"
566566 ;;
567567 esac
568568 done < "$tt_temp_file"
569569
570 #tt_debug LOOP_OUT "\$tt_test_command=$tt_test_command"
570 tt_debug LOOP_OUT "\$tt_test_command=$tt_test_command"
571571
572572 # Run pending tests
573573 test -n "$tt_test_command" && tt_run_test
588588
589589 ### Init process
590590
591 # Temporary files (using files because <(...) is not portable)
592 tt_temp_dir=
593 tt_make_temp_dir # sets global $tt_temp_dir
594 tt_temp_file="$tt_temp_dir/temp.txt"
595 tt_stdin_file="$tt_temp_dir/stdin.txt"
596 tt_test_ok_file="$tt_temp_dir/ok.txt"
597 tt_test_output_file="$tt_temp_dir/output.txt"
598
599591 # Handle command line options
600592 while test "${1#-}" != "$1"; do
601593 case "$1" in
635627 tt_post_command="$1"
636628 shift
637629 ;;
638 --debug)
639 shift
640 tt_debug=1
641 ;;
642630 -P | --progress)
643631 shift
644632 tt_progress="$1"
677665 -V | --version)
678666 printf '%s %s\n' "$tt_my_name" "$tt_my_version"
679667 exit 0
668 ;;
669 --debug)
670 # Undocumented dev-only option
671 shift
672 tt_debug=1
680673 ;;
681674 --)
682675 # No more options to process
770763 if test $tt_use_colors -eq 1; then
771764 tt_color_red=$( printf '\033[31m') # fail
772765 tt_color_green=$(printf '\033[32m') # ok
773 tt_color_blue=$( printf '\033[34m') # debug
774 #tt_color_cyan=$( printf '\033[36m') # not used
766 tt_color_cyan=$( printf '\033[36m') # debug
775767 tt_color_off=$( printf '\033[m')
776768 fi
777769
795787 fi
796788
797789 ### Real execution begins here
790
791 trap tt_clean_up EXIT
792
793 # Temporary files (using files because <(...) is not portable)
794 tt_make_temp_dir # sets global $tt_temp_dir
795 tt_temp_file="$tt_temp_dir/temp.txt"
796 tt_stdin_file="$tt_temp_dir/stdin.txt"
797 tt_test_ok_file="$tt_temp_dir/ok.txt"
798 tt_test_output_file="$tt_temp_dir/output.txt"
798799
799800 # Some preparing command to run before all the tests?
800801 if test -n "$tt_pre_command"; then
869870 test $tt_missing_nl -eq 1 && tt_missing_nl=0 && tt_message
870871 done
871872
872 tt_clean_up
873
874873 # Some clean up command to run after all the tests?
875874 if test -n "$tt_post_command"; then
876875 eval "$tt_post_command" ||
912911 if test $tt_nr_files -gt 1 && test "$tt_output_mode" != 'quiet'; then
913912 echo
914913 printf ' %5s %5s %5s\n' ok fail skip
915 printf %s "$tt_files_stats" | while read -r ok fail skip; do
914 printf %s "$tt_files_stats" | while IFS=' ' read -r ok fail skip; do
916915 printf ' %5s %5s %5s %s\n' "$ok" "$fail" "$skip" "$1"
917916 shift
918917 done | sed 's/ 0/ -/g' # hide zeros
0 clitest (0.4.0+git20221025.1.3d6ebeb-1) UNRELEASED; urgency=low
1
2 * New upstream snapshot.
3
4 -- Debian Janitor <janitor@jelmer.uk> Sun, 30 Oct 2022 18:07:17 -0000
5
06 clitest (0.4.0-1) unstable; urgency=medium
17
28 * New upstream version 0.4.0
88
99 $ echo 'ok' > /tmp/foo.txt
1010 $ echo 'ok' #=> --file /tmp/foo.txt
11 $ rm /tmp/foo.txt
12 $
1113
1214 # Syntax: Must be exactly one space before and after --file
1315
0 # If multiple markers, only the last one is identified as such
1 # There are 4 ' #=> ' marker-like occurrences in this test.
2
3 $ echo "a #=> b #=> c" #=> --lines 99 #=> --lines 1
0 $ echo "tab " #=> tab
1 $
0 # Test file to be run with --debug
1
2 $ echo "tab+space " #=> tab+space
3 $
4 # A comment line between command blocks
5 $ echo "unclosed block"
6 unclosed block
0 #
1 # This was a bug found on early versions of clitest in which tests shared
2 # STDIN with clitest and with each other, causing unexpected results when
3 # a test read from STDIN. This was reported on issue #42 on Github.
4 #
5 # Testing for a regression.
6 #
7
8 $ echo testing stdin isolation ; read stdin_isolation
9 testing stdin isolation
10 $ echo Failed\? Regression to stdin isolation added. ; unset stdin_isolation
11 Failed? Regression to stdin isolation added.
119119
120120 ```
121121 $ ./clitest --version
122 clitest 0.4.0
122 clitest dev
123123 $ ./clitest -V
124 clitest 0.4.0
124 clitest dev
125125 $
126126 ```
127127
193193 $
194194 ```
195195
196 ## Option --quiet has no effect in --debug (disabled)
197
198 ```
199 # $ ./clitest --quiet --debug test/ok-2.sh
200 # [INPUT_LINE: $ echo ok]
201 # [ LINE_CMD: $ echo ok]
202 # [ NEW_CMD: echo ok]
203 # [INPUT_LINE: ok]
204 # [ LINE_*: ok]
205 # [ OK_TEXT: ok]
206 # [INPUT_LINE: $ echo ok #=> ok]
207 # [ LINE_CMD: $ echo ok #=> ok]
208 # [ EVAL: echo ok]
209 # [ OUTPUT: ok]
210 # [ NEW_CMD: echo ok ]
211 # [ OK_INLINE: ok]
212 # [ OK_TEXT: ok]
213 # [ EVAL: echo ok ]
214 # [ OUTPUT: ok]
215 # [ LOOP_OUT: $test_command=]
216 # $
196 ## Option --quiet has no effect in --debug
197
198 ```
199 $ ./clitest --debug --quiet test/ok-1.sh | grep -o INPUT_LINE
200 INPUT_LINE
201 INPUT_LINE
202 $
203 ```
204
205 ## Option --debug
206
207 Tricky test file with: empty line, inline marker, tab, $, comment line, normal command, unclosed block.
208
209 ```
210 $ ./clitest --debug test/option-debug.sh
211 --------------------------------------------------------------------------------
212 -- INPUT_LINE[# Test file to be run with --debug]
213 -- LINE_MISC[# Test file to be run with --debug]
214 --------------------------------------------------------------------------------
215 -- INPUT_LINE[]
216 -- LINE_MISC[]
217 --------------------------------------------------------------------------------
218 -- INPUT_LINE[$ echo "tab+space " #=> tab+space ]
219 -- LINE_CMD[$ echo "tab+space<tab> "<tab> #=> tab+space<tab> ]
220 -- NEW_CMD[echo "tab+space<tab> "<tab> ]
221 -- OK_INLINE[tab+space<tab> ]
222 -- OK_TEXT[tab+space<tab> ]
223 #1 echo "tab+space "
224 -- EVAL[echo "tab+space<tab> "<tab> ]
225 -- OUTPUT[tab+space<tab> ]
226 --------------------------------------------------------------------------------
227 -- INPUT_LINE[$]
228 -- LINE_$[$]
229 --------------------------------------------------------------------------------
230 -- INPUT_LINE[# A comment line between command blocks]
231 -- LINE_MISC[# A comment line between command blocks]
232 --------------------------------------------------------------------------------
233 -- INPUT_LINE[$ echo "unclosed block"]
234 -- LINE_CMD[$ echo "unclosed block"]
235 -- NEW_CMD[echo "unclosed block"]
236 --------------------------------------------------------------------------------
237 -- INPUT_LINE[unclosed block]
238 -- LINE_MISC[unclosed block]
239 -- OK_TEXT[unclosed block]
240 -- LOOP_OUT[$tt_test_command=echo "unclosed block"]
241 #2 echo "unclosed block"
242 -- EVAL[echo "unclosed block"]
243 -- OUTPUT[unclosed block]
244 OK: 2 of 2 tests passed
245 $
246 ```
247
248 ## Option --debug with colors
249
250 - Separator line is cyan
251 - `INPUT_LINE[...]` is cyan, others are normal color inside `[]`
252 - `<tab>` must be green
253 - `#=>` inline marker must be red
254
255 This test forces `--color always` because normally the tests inside this file are not colored (output is not a terminal). Note that the escape character (`\033`) is removed to have only printable ASCII characters in the output.
256
257 ```
258 $ ./clitest --debug --color always test/option-debug-color.sh | head -n 3 | tr -d '\033'
259 [36m--------------------------------------------------------------------------------[m
260 [36m-- INPUT_LINE[$ echo "tab " #=> tab ][m
261 [36m-- LINE_CMD[[m$ echo "tab[32m<tab>[m" [31m#=> [mtab[32m<tab>[m[36m][m
262 $
263 ```
264
265 In case of multiple `#=>`, only the last one should be red:
266
267 ```
268 $ ./clitest --debug --color always test/inline-multiple-marker.sh | command grep LINE_CMD | tr -d '\033'
269 [36m-- LINE_CMD[[m$ echo "a #=> b #=> c" #=> --lines 99 [31m#=> [m--lines 1[36m][m
270 $
217271 ```
218272
219273 ## Option --color
229283
230284 Color ON
231285
232 ```
233 $ ./clitest --color always test/ok-1.sh
234 #1 echo ok
235 OK: 1 of 1 test passed
236 $ ./clitest --color yes test/ok-1.sh
237 #1 echo ok
238 OK: 1 of 1 test passed
286 > Note that the escape character (`\033`) is removed to have only printable ASCII characters in the output.
287
288 ```
289 $ ./clitest --color always test/ok-1.sh | tr -d '\033'
290 #1 echo ok
291 [32mOK:[m 1 of 1 test passed
292 $ ./clitest --color yes test/ok-1.sh | tr -d '\033'
293 #1 echo ok
294 [32mOK:[m 1 of 1 test passed
239295 $
240296 ```
241297
265321
266322 The real default `--color auto` cannot be tested here.
267323 Test it by hand at the command line.
268
269 ```
270 ## $ ./clitest test/ok-1.sh
271 ## OK! The single test has passed.
272 ## $ ./clitest --color auto test/ok-1.sh
273 ## OK! The single test has passed.
274 ## $
275 ```
276324
277325 ## Option --list
278326
345393
346394 Normal results (using colors) and exit code
347395
348 ```
349 $ ./clitest --list-run --color yes test/no-nl-command.sh; echo $?
350 #1 printf 'ok\n'
351 #2 printf 'fail'
352 #3 printf 'ok\nok\nfail'
353 #4 printf 'ok\n' 
354 #5 printf 'fail' 
355 #6 printf 'ok'; echo 
356 #7 printf 'ok' 
396 > Note that the escape character (`\033`) is removed to have only printable ASCII characters in the output.
397
398 ```
399 $ ./clitest --list-run --color always test/no-nl-command.sh > /tmp/foo.txt; echo $?
357400 1
401 $ cat /tmp/foo.txt | tr -d '\033'
402 [32m#1 printf 'ok\n'[m
403 [31m#2 printf 'fail'[m
404 [31m#3 printf 'ok\nok\nfail'[m
405 [32m#4 printf 'ok\n' [m
406 [31m#5 printf 'fail' [m
407 [32m#6 printf 'ok'; echo [m
408 [32m#7 printf 'ok' [m
409 $ rm /tmp/foo.txt
358410 $
359411 ```
360412
10711123 OK: 19 of 19 tests passed
10721124 $
10731125 ```
1126
1127 In case of multiple `#=>`, consider only the last one:
1128
1129 ```
1130 $ ./clitest test/inline-multiple-marker.sh
1131 #1 echo "a #=> b #=> c" #=> --lines 99
1132 OK: 1 of 1 test passed
1133 $
10741134
10751135 ## Inline match modes
10761136
12431303 #1 OK printf '$ echo ok\nok\n'
12441304 #2 OK echo 'ok' > /tmp/foo.txt
12451305 #3 OK echo 'ok'
1246 #4 FAIL echo 'fail'
1306 #4 OK rm /tmp/foo.txt
12471307 #5 FAIL echo 'fail'
1248 #6 OK echo '--file'
1249 #7 OK echo '--filer'
1250 #8 OK echo '--file is cool'
1308 #6 FAIL echo 'fail'
1309 #7 OK echo '--file'
1310 #8 OK echo '--filer'
1311 #9 OK echo '--file is cool'
12511312 $
12521313 ```
12531314
21902251 $
21912252 ```
21922253
2254 STDIN Isolation
2255
2256 ```
2257 $ ./clitest --quiet test/stdin-isolation.sh ; echo $?
2258 0
2259 $
2260 ```
2261
2262 Temporary files and directories must be removed after execution
2263
2264 ```
2265 $ TMPDIR__TEST=$(mktemp -d)
2266 $ TMPDIR="$TMPDIR__TEST" ./clitest --help >/dev/null 2>&1
2267 $ find "$TMPDIR__TEST" -mindepth 1
2268 $ echo '$ true' | TMPDIR="$TMPDIR__TEST" ./clitest --debug - >/dev/null 2>&1
2269 $ find "$TMPDIR__TEST" -mindepth 1
2270 $ unset TMPDIR__TEST
2271 $
2272 ```
21932273 Multiple commands in one line
21942274
21952275 ```
23272407
23282408 ## And now, the colored output tests
23292409
2330 ```
2331 $ ./clitest --color yes --first test/fail-2.sh
2332 #1 echo ok
2333 --------------------------------------------------------------------------------
2334 [FAILED #1, line 1] echo ok
2410 > Note that the escape character (`\033`) is removed to have only printable ASCII characters in the output.
2411
2412 ```
2413 $ ./clitest --color yes --first test/fail-2.sh | tr -d '\033'
2414 #1 echo ok
2415 [31m--------------------------------------------------------------------------------[m
2416 [31m[FAILED #1, line 1] echo ok[m
23352417 @@ -1 +1 @@
23362418 -fail
23372419 +ok
2338 --------------------------------------------------------------------------------
2339 $
2340 ```
2420 [31m--------------------------------------------------------------------------------[m
2421 $
2422 ```