netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH nft 1/1] tests/shell: accept name of dump files in place of test names
@ 2023-11-22 18:22 Thomas Haller
  2023-11-23 10:48 ` Pablo Neira Ayuso
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Haller @ 2023-11-22 18:22 UTC (permalink / raw)
  To: NetFilter; +Cc: Thomas Haller

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 tests/shell/run-tests.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/tests/shell/run-tests.sh b/tests/shell/run-tests.sh
index 3cde97b7ea17..c26142b7ff17 100755
--- a/tests/shell/run-tests.sh
+++ b/tests/shell/run-tests.sh
@@ -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
-- 
2.42.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-11-23 13:07 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-11-22 18:22 [PATCH nft 1/1] tests/shell: accept name of dump files in place of test names Thomas Haller
2023-11-23 10:48 ` Pablo Neira Ayuso
2023-11-23 13:07   ` Thomas Haller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).