This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lab3-tester.pl
executable file
·134 lines (108 loc) · 3.49 KB
/
lab3-tester.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#! /usr/bin/perl -w
open(FOO, "ospfsmod.c") || die "Did you delete ospfsmod.c?";
$lines = 0;
$lines++ while defined($_ = <FOO>);
close FOO;
@tests = (
# test reading
[ 'diff base/hello.txt test/hello.txt >/dev/null 2>&1 && echo $?',
"0"
],
[ 'cmp base/pokercats.gif test/pokercats.gif >/dev/null 2>&1 && echo $?',
"0"
],
[ 'ls -l test/pokercats.gif | awk "{ print \$5 }"',
"91308"
],
# test writing
# We use dd to write because it doesn't initially truncate, and it can
# be told to seek forward to a particular point in the disk.
[ "echo Bybye | dd bs=1 count=5 of=test/hello.txt conv=notrunc >/dev/null 2>&1 ; cat test/hello.txt",
"Bybye, world!"
],
[ "echo Hello | dd bs=1 count=5 of=test/hello.txt conv=notrunc >/dev/null 2>&1 ; cat test/hello.txt",
"Hello, world!"
],
[ "echo gi | dd bs=1 count=2 seek=7 of=test/hello.txt conv=notrunc >/dev/null 2>&1 ; cat test/hello.txt",
"Hello, girld!"
],
[ "echo worlds galore | dd bs=1 count=13 seek=7 of=test/hello.txt conv=notrunc >/dev/null 2>&1 ; cat test/hello.txt",
"Hello, worlds galore"
],
[ "echo 'Hello, world!' > test/hello.txt ; cat test/hello.txt",
"Hello, world!"
],
# 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
[ 'ls test | dd bs=1 of=test/dir-contents.txt >/dev/null 2>&1; ' .
' 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 -f 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 hello > test/file1 ; echo goodbye >> test/file1 && cat test/file1',
'hello goodbye'
],
# delete a file
[ 'rm -f 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(@wanttests);
foreach $i (@ARGV) {
$wanttests[$i] = 1 if (int($i) == $i && $i > 0 && $i <= @tests);
}
my($sh) = "bash";
my($tempfile) = "lab3test.txt";
my($ntestfailed) = 0;
my($ntestdone) = 0;
foreach $test (@tests) {
$ntest++;
next if (@wanttests && !$wanttests[$ntest]);
$ntestdone++;
print STDOUT "Running 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) = $ntestdone - $ntestfailed;
print "$ntestpassed of $ntestdone tests passed\n";
exit(0);