listfull.sh: Quote paths
authorJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Fri, 2 Jun 2017 15:30:24 +0000 (11:30 -0400)
committerJean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>
Sat, 3 Jun 2017 17:56:22 +0000 (13:56 -0400)
Make the list unambiguous and easy to consume by POSIX shell scripts.

Signed-off-by: Jean-Christophe Beaupré <jcbrinfo@users.noreply.github.com>

tests/README.md
tests/listfull.sh

index f0883e3..ed83013 100644 (file)
@@ -17,6 +17,8 @@ This directory contains small Nit programs and useful scripts to test the non re
   Useful before committing something.
 * `listfull.sh` lists tests that are run by `testfull.sh`.
   It is used by other scripts but can be used by human to see what is tested.
+  Each path is quoted using apostrophes, with `'\''` escaping an apostrophe.
+  This syntax is compatible with `xargs` and the POSIX shell.
 
   Currently, all files in `tests/`, `lib/` and `examples/` are executed, some of `contrib/` and the main programs of `src/`.
   To update the list of tested files, just edit this script.
index edbc37e..697cab8 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/sh
-ls -1 -- "$@" \
+for module in "$@" \
        ../src/nit*.nit \
        ../src/test_*.nit \
        ../src/examples/*.nit \
@@ -17,4 +17,15 @@ ls -1 -- "$@" \
        ../contrib/nitin/nitin.nit \
        ../contrib/nitiwiki/src/nitiwiki.nit \
        *.nit \
-       | grep -v ../lib/popcorn/examples/
+; do
+       case "${module}" in
+               ../lib/popcorn/examples/*)
+                       continue
+                       ;;
+               *)
+                       # See [Rich’s sh (POSIX shell) tricks](http://www.etalabs.net/sh_tricks.html),
+                       # section “Shell-quoting arbitrary strings”.
+                       printf '%s\n' "${module}" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/'/"
+                       ;;
+       esac
+done