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 with a newline
12 # raw <word> : echo <word> to stdout without adding anything
13 # file <word> : echo <word> to stdout AND create the file <word>
14 # dir <word> : echo <word> to stdout AND create the directory <word>
15 # rm <word> : echo <word> to stdout AND delete the file/directory <word>
16 # wait <word> : wait for a file named <word> to exist
17 # tmout <secs> : Change the timeout for waiting. Default is 4 seconds.
18 # sleep <secs> : Sleep for <secs> seconds then echo <secs>
19 # fail <err> : echo <err> to stdout then exit with error code err
21 # If given -q only the "out" command generates output.
32 defined $nm or die "Missing value for $op\n";
43 # Show the output before creating the file
45 print "file $nm\n" unless $quiet;
46 open(my $fh, '>', $nm) or die "$nm: open: $!\n";
51 # Show the output before creating the directory
53 print "dir $nm\n" unless $quiet;
54 mkdir($nm) or die "$nm: mkdir: $!\n";
58 # Show the output after removing the file
61 unlink($nm) or die "$nm: unlink: $!\n";
63 rmdir($nm) or die "$nm: rmdir: $!\n";
65 die "$nm: not file or directory: $!\n";
67 print "rm $nm\n" unless $quiet;
73 print "tmout $nm\n" unless $quiet;
77 # Show the output after the file exists
80 my $end = $start + $timeout;
81 while (time() <= $end) {
83 print "wait $nm\n" unless $quiet;
86 select(undef, undef, undef, 0.1);
88 die "wait $nm: timeout after ".(time()-$start-1)." seconds\n";
91 # Show the output after sleeping
94 print "sleep $nm\n" unless $quiet;
103 die("Invalid command: $op $nm\n");
106 if (@ARGV && $ARGV[0] eq '-q') {
112 if (op($ARGV[0], $ARGV[1])) {