#! /usr/bin/perl -w open(FOO, "ospfsmod.c") || die "Did you delete ospfsmod.c?"; $lines = 0; $lines++ while defined($_ = ); close FOO; @tests = ( # create a file [ 'touch test/file1 && echo $?', "0" ], # read directory [ 'touch test/dir-contents.txt ; ls test | tee test/dir-contents.txt | grep file1', 'file1' ], # write files, remove them, then read dir again [ ' touch test/foo test/bar test/baz && '. ' rm test/foo test/bar test/baz && '. 'diff <( ls test ) test/dir-contents.txt', '' ], # remove the last file [ ' rm test/dir-contents.txt && ls test | grep dir-contents.txt', '' ], # write to a file [ 'echo hello > test/file1 && cat test/file1', 'hello' ], # append to a file [ 'echo goodbye >> test/file1 && cat test/file1', 'hello goodbye' ], # delete a file [ 'rm test/file1 && ls test | grep file1', '' ], # make a larger file for indirect blocks [ ' yes | head -n 5632 > test/yes.txt && ls -l test/yes.txt | awk \'{ print $5 }\'', '11264' ], # truncate the large file [ 'echo truncernated11 > test/yes.txt | ls -l test/yes.txt | awk \'{ print $5 }\' ; rm test/yes.txt', '15' ], ); my($ntest) = 0; my($sh) = "bash"; my($tempfile) = "lab3test.txt"; my($ntestfailed) = 0; foreach $test (@tests) { $ntest++; print STDOUT "Starting test $ntest\n"; my($in, $want) = @$test; open(F, ">$tempfile") || die; print F $in, "\n"; print STDERR $in, "\n"; close(F); $result = `$sh < $tempfile 2>&1`; $result =~ s|\[\d+\]||g; $result =~ s|^\s+||g; $result =~ s|\s+| |g; $result =~ s|\s+$||; next if $result eq $want; next if $want eq 'Syntax error [NULL]' && $result eq '[NULL]'; next if $result eq $want; print STDERR "Test $ntest FAILED!\n input was \"$in\"\n expected output like \"$want\"\n got \"$result\"\n"; $ntestfailed += 1; } unlink($tempfile); my($ntestpassed) = $ntest - $ntestfailed; print "$ntestpassed of $ntest tests passed\n"; exit(0);