tests/shell: accept name of dump files in place of test names
PATCH 1/1 tests/shell: accept name of dump files in place of test names
Imagine you have the filename of a dump file at hand. For example, because it shows up in git status and you can copy it from the terminal.
If you want to run the corresponding test, that was cumbersome. It involved editing the command line (removing the /dumps/ directory and the file suffix).
Instead, let "run-tests.sh" do that automatically. There is little value in bothering the user with a failure:
Before:
$ ./tests/shell/run-tests.sh tests/shell/testcases/optionals/dumps/comments_table_0.json-nft -L E: Unknown test "tests/shell/testcases/optionals/dumps/comments_table_0.json-nft"
After:
$ ./tests/shell/run-tests.sh tests/shell/testcases/optionals/dumps/comments_table_0.json-nft -L tests/shell/testcases/optionals/comments_table_0
--- tests/shell/run-tests.sh | 13 +++++++++++++ 1 file changed, 13 insertions(+)
tests/shell/run-tests.sh +13 -0
@@ -431,6 +431,19 @@ for t in "${TESTSOLD[@]}" ; do elif [ -d "$t" ] ; then TESTS+=( $(find_tests "$t") ) else + if [ -f "$t" ] ; then + # If the test name looks like a dumps file, autodetect + # the correct test name. It's not useful to bother the + # user with a failure in this case. + rx="^(.*/)?dumps/([^/]+)\\.(nodump|nft|json-nft)$" + if [[ "$t" =~ $rx ]] ; then + t2="${BASH_REMATCH[1]}${BASH_REMATCH[2]}" + if [ -f "$t2" -a -x "$t2" ] ; then + TESTS+=( "$t2" ) + continue + fi + fi + fi msg_error "Unknown test \"$t\"" fi done
Signature · 1 line
2.42.0
Pablo Neira Ayuso
maintainerQuoted 11 lines · Thomas Haller
tests/shell/run-tests.sh +3
-0@@ -431,6 +431,19 @@ for t in "${TESTSOLD[@]}" ; do elif [ -d "$t" ] ; then TESTS+=( $(find_tests "$t") ) else + if [ -f "$t" ] ; then + # If the test name looks like a dumps file, autodetect + # the correct test name. It's not useful to bother the
tests/shell/run-tests.sh for t in "${TESTSOLD[@]}" ; do · line 446
Quoted 10 lines
tests/shell/run-tests.sh +10
-0+ # user with a failure in this case. + rx="^(.*/)?dumps/([^/]+)\\.(nodump|nft|json-nft)$" + if [[ "$t" =~ $rx ]] ; then + t2="${BASH_REMATCH[1]}${BASH_REMATCH[2]}" + if [ -f "$t2" -a -x "$t2" ] ; then + TESTS+=( "$t2" ) + continue + fi + fi + fi
I think it is not worth, users of this infrastructure is very small.
So let's keep back this usability feature for tests/shell.
Quoted 29 lines · Pablo Neira Ayuso
Quoted 19 lines · Thomas Haller
tests/shell/run-tests.sh +0
-0@@ -431,6 +431,19 @@ for t in "${TESTSOLD[@]}" ; doelif [ -d "$t" ] ; then
TESTS+=( $(find_tests "$t") )
elsetests/shell/run-tests.sh +2
-0+ if [ -f "$t" ] ; then + # If the test name looks like a dumpsfile, autodetect
tests/shell/run-tests.sh +1
-0+ # the correct test name. It's not usefulto bother the
tests/shell/run-tests.sh +2
-0+ # user with a failure in this case. + rx="^(.*/)?dumps/([^/]+)\\.(nodump|nft|json-nft)$"
tests/shell/run-tests.sh +2
-0+ if [[ "$t" =~ $rx ]] ; then + t2="${BASH_REMATCH[1]}${BASH_REMATCH[2]}"
tests/shell/run-tests.sh for t in "${TESTSOLD[@]}" ; do · line 446
Quoted 6 lines
tests/shell/run-tests.sh +6
-0+ if [ -f "$t2" -a -x "$t2" ] ; then + TESTS+=( "$t2" ) + continue + fi + fi + fiI think it is not worth, users of this infrastructure is very small.
Quoted 1 line
So let's keep back this usability feature for tests/shell.
OK. Fine.
But while closing and dropping it, let me still make the use case clear.
When I look at a patch in git-log and see for example the diff-stat:
src/json.c | 25 +++++++++++++------------ src/parser_json.c | 91 +++++++++++++++++++++++++++++++++++++++++++++---------------------------------------------- tests/shell/testcases/chains/dumps/0021prio_0.json-nft | Bin 61509 -> 61639 bytes tests/shell/testcases/chains/dumps/0042chain_variable_0.json-nft | Bin 952 -> 1046 bytes tests/shell/testcases/chains/dumps/0043chain_ingress_0.json-nft | Bin 619 -> 632 bytes
I'd like to re-run those tests. I'd like to do that by copy-pasting the file names at hand into the terminal.
Thomas