This repository was archived by the owner on Dec 4, 2023. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathtest
More file actions
executable file
·140 lines (115 loc) · 3.21 KB
/
Copy pathtest
File metadata and controls
executable file
·140 lines (115 loc) · 3.21 KB
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
135
136
137
138
139
#!/usr/bin/perl
use File::Temp qw(tempfile);
my $SEMESTER = "cs3600sp14";
my $SOLDIR = "/course/$SEMESTER/code/solutions/project1/";
my $SHELL = "3600sh";
if (! (-e $SHELL)) {
error("Unable to find problem '$SHELL'.");
}
if (! (-e "$SOLDIR$SHELL")) {
print("$SOLDIR$SHELL");
error("Unable to find reference solution '$SHELL'.");
}
my $pattern = "/tmp/cs3600.project1.XXXXXX";
my ($f1, $t1) = tempfile($pattern, UNLINK => 1);
my ($f2, $t2) = tempfile($pattern, UNLINK => 1);
my ($f3, $t3) = tempfile($pattern, UNLINK => 1);
my ($f4, $t4) = tempfile($pattern, UNLINK => 1);
my $total = 0;
my $passed = 0;
print "Milestone tests\n";
my @tries = ( "ls",
"ls ~/tmp\ncat /etc/hostname",
"uname -a\ntime\n/bin/ls",
"stat /home\n",
"opdpfo\nmfdoimfo",
"ls a b c d e f g h i\n",
"pwd\nls\npwd\nls\nuname -a\nuname-a\nls\n",
"whoami\nwho am i\nwhoami who am i",
"ls /bin > $t1\ncat $t1\n\n",
"wc < $t1 > $t2\ncat $t2",
"ls /mfmfoifoi 2> $t1\ncat $t1");
test($problem, \@tries);
print "\nFinal project tests\n";
my @tries = ( "ls foo\\ bar",
"ls \\\\baz\\ foo\\ bah\\\\\\ ",
"ls -altr a\\&b",
"ls -altr a>b b<a",
"ls -altr a\\tcad\n",
"ls -altr /etc &\n",
"ls -altr /bin > $t1\ncat $t1\nls -altr /bin > $t1\ncat $t1",
"ls -altr /bin < $t1 > $t2 2> $t3\ncat $t1\ncat $t2\ncat $t3",
"ls a b c d e f g h i j k\n\n\n\n",
"ls a b c d e f g h i j k l m n o p q r s t u v w x y z");
test($problem, \@tries);
print "\nStress tests\n";
my @tries = ( "ls \\8",
"ls -al /bin ",
"ls -a /bin",
" ls -a -l -t -r -n -o -i -h /bin",
"ls \\ \\\\ \\ \\a",
"ls\t-altr\t/etc",
"ls -altr /etc &",
"ls\t-altr /etc & ",
"ls & ls\n \n\t\n",
"ls >",
"ls < /fdiononiono",
"ls < 2>",
"ls & < foo\n",
"ls -a < foo bar",
"./3600sh.c a b",
"fndsiofnsodfnsof",
"& & & ls");
test($problem, \@tries);
print "\nPassed $passed of $total tests.\n";
sub test {
my ($problem, $vals) = @_;
foreach $val (@{ $vals }) {
$total ++;
my $pr = $val;
$pr =~ s/\n/\\n/g;
print pad(" Trying with script '$pr'", 60);
open (MYFILE, '> .data');
print MYFILE $val;
close(MYFILE);
system("./$SHELL < .data > .actual 2>&1");
system("$SOLDIR$SHELL < .data > .expected 2>&1");
my $diff = `diff .expected .actual | egrep "^([<>]|Binary)"`;
if ($diff) {
$diff = `diff -y .expected .actual`;
`cp .expected .actual ~`;
}
`rm .actual .expected .data`;
if (! $diff) {
$passed++;
print "[PASS]\n";
} else {
print "[FAIL]\n";
print " Command was:\n$pr\n Diff in expected output:\n$diff\n";
}
}
}
sub error {
my ($msg) = @_;
print "ERROR: $msg\n";
exit(1);
}
sub pad {
my ($name, $len) = @_;
while (length($name) < $len) {
$name = "$name ";
}
if (length($name) > $len) {
$name = substr($name, 0, $len-3) . "...";
}
return $name;
}
sub random {
my ($len) = @_;
my @chars=('a'..'z','A'..'Z','0'..'9','_');
my $random_string;
foreach (1..$len) {
$random_string.=$chars[rand @chars];
}
return $random_string;
}