From 8093e2eee3390e6b250c3ae5bfeb5b4a4196d2e2 Mon Sep 17 00:00:00 2001 From: Paul Smith Date: Sun, 26 Feb 2023 12:43:27 -0500 Subject: * tests/scripts/options/dash-l: Simplify the test via the helper * tests/thelp.pl: Add "exist" and "noexist" operators. --- tests/scripts/options/dash-l | 17 ++++++----------- tests/thelp.pl | 36 +++++++++++++++++++++++++----------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/tests/scripts/options/dash-l b/tests/scripts/options/dash-l index d1e60494..a89da78c 100644 --- a/tests/scripts/options/dash-l +++ b/tests/scripts/options/dash-l @@ -20,32 +20,27 @@ also specified on the command line."; $port_type eq 'W32' and return -1; open(MAKEFILE,"> $makefile"); -printf MAKEFILE q, -define test -if [ ! -f test-file ]; then \ - echo >> test-file; sleep 2; %s test-file; \ -else \ - echo $@ FAILED; \ -fi -endef +printf MAKEFILE subst_make_string(q! +test = #HELPER# noexist test-file file test-file sleep 2 rm test-file all : ONE TWO THREE ONE : ; @$(test) TWO : ; @$(test) THREE : ; @$(test) -,, $CMD_rmfile; +!); close(MAKEFILE); +my $ans = "noexist test-file\nfile test-file\nsleep 2\nrm test-file\n"; $mkoptions = "-l 0.0001"; $mkoptions .= " -j 4" if ($parallel_jobs); # We have to wait longer than the default (5s). -&run_make_with_options($makefile, $mkoptions, &get_logfile, 0, 8); +&run_make_with_options($makefile, $mkoptions, &get_logfile, 0, 10); $slurp = &read_file_into_string(&get_logfile(1)); if ($slurp =~ /cannot enforce load limit/) { return -1; } -&compare_output("", &get_logfile(1)); +&compare_output("$ans$ans$ans", &get_logfile(1)); 1; diff --git a/tests/thelp.pl b/tests/thelp.pl index 55650521..da042aa4 100755 --- a/tests/thelp.pl +++ b/tests/thelp.pl @@ -8,17 +8,19 @@ # Each step consists of an operator and argument. # # It supports the following operators: -# out : echo to stdout with a newline -# raw : echo to stdout without adding anything -# env : echo the value of the env.var. , or "" -# file : echo to stdout AND create the file -# dir : echo to stdout AND create the directory -# rm : echo to stdout AND delete the file/directory -# wait : wait for a file named to exist -# tmout : Change the timeout for waiting. Default is 4 seconds. -# sleep : Sleep for seconds then echo -# term : send SIGTERM to PID -# fail : echo to stdout then exit with error code err +# out : echo to stdout with a newline +# raw : echo to stdout without adding anything +# env : echo the value of the env.var. , or "" +# file : echo to stdout AND create the file +# dir : echo to stdout AND create the directory +# rm : echo to stdout AND delete the file/directory +# wait : wait for a file named to exist +# exist : echo AND fail if a file named doesn't exist +# noexist : echo AND fail if a file named exists +# tmout : Change the timeout for waiting. Default is 4 seconds. +# sleep : Sleep for seconds then echo +# term : send SIGTERM to PID +# fail : echo to stdout then exit with error code err # # If given -q only the "out", "raw", and "env" commands generate output. @@ -60,6 +62,18 @@ sub op { return 1; } + if ($op eq 'exist') { + -f "$nm" || die "$nm: file should exist: $!\n"; + print "exist $nm\n" unless $quiet; + return 1 + } + + if ($op eq 'noexist') { + -f "$nm" && die "$nm: file exists\n"; + print "noexist $nm\n" unless $quiet; + return 1 + } + # Show the output before creating the directory if ($op eq 'dir') { print "dir $nm\n" unless $quiet; -- cgit v1.2.1