4 # This script helps us write tests in a portable way, without relying on a lot
5 # of shell features. Since we already have Perl to run the tests, use that.
7 # The arguments represent a set of steps that will be run one at a time.
8 # Each step consists of an operator and argument.
10 # It supports the following operators:
11 # out <word> : echo <word> to stdout
12 # file <word> : echo <word> to stdout AND create the file <word>
13 # dir <word> : echo <word> to stdout AND create the directory <word>
14 # rm <word> : echo <word> to stdout AND delete the file/directory <word>
15 # wait <word> : wait for a file named <word> to exist
16 # tmout <secs> : Change the timeout for waiting. Default is 4 seconds.
17 # sleep <secs> : Sleep for <secs> seconds then echo <secs>
18 # fail <err> : echo <err> to stdout then exit with error code err
20 # If given -q only the "out" command generates output.
31 defined $nm or die "Missing value for $op\n";
38 # Show the output before creating the file
40 print "file $nm\n" unless $quiet;
41 open(my $fh, '>', $nm) or die "$nm: open: $!\n";
46 # Show the output before creating the directory
48 print "dir $nm\n" unless $quiet;
49 mkdir($nm) or die "$nm: mkdir: $!\n";
53 # Show the output after removing the file
56 unlink($nm) or die "$nm: unlink: $!\n";
58 rmdir($nm) or die "$nm: rmdir: $!\n";
60 die "$nm: not file or directory: $!\n";
62 print "rm $nm\n" unless $quiet;
68 print "tmout $nm\n" unless $quiet;
72 # Show the output after the file exists
75 my $end = $start + $timeout;
76 while (time() <= $end) {
78 print "wait $nm\n" unless $quiet;
81 select(undef, undef, undef, 0.1);
83 die "wait $nm: timeout after ".(time()-$start-1)." seconds\n";
86 # Show the output after sleeping
89 print "sleep $nm\n" unless $quiet;
98 die("Invalid command: $op $nm\n");
101 if (@ARGV && $ARGV[0] eq '-q') {
107 if (op($ARGV[0], $ARGV[1])) {