-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.pl
68 lines (54 loc) · 1.48 KB
/
test.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
#!/usr/bin/perl
use 5.16.0;
use warnings FATAL => 'all';
use Test::Simple tests => 22;
system("mkdir -p tmp");
my $prompt = `./nush < /dev/null`;
ok($prompt =~ /nush\$/, "nush\$ prompt");
my $inter = `./nush < tests/02-echo-twice.sh`;
ok($inter =~ /nush\$/, "show prompt interactively");
$inter =~ s/nush\$//;
ok($inter =~ /nush\$/, "show prompt interactively twice");
ok($inter =~ /one/, "run interactive command 1");
ok($inter =~ /two/, "run interactive command 2");
my @scripts = glob("tests/*.sh");
for my $script (@scripts) {
system("rm -f tmp/output");
system("./nush $script > tmp/output");
my $correct = $script;
$correct =~ s/\.sh$/.out/;
my $diff = `diff $correct tmp/output`;
ok($diff eq "", $script);
if ($diff ne "") {
$diff =~ s/^/# /mg;
print $diff;
}
}
sub check_errors {
my ($errs) = @_;
chomp $errs;
if ($errs ne "") {
$errs =~ s/^/# /mg;
warn $errs;
return 0;
}
else {
return 1;
}
}
sub clang_check {
my $errs = `clang-check -analyze *.c -- 2>&1`;
return check_errors($errs);
}
sub valgrind() {
system(qq{valgrind -q --leak-check=full --log-file=valgrind.out ./nush < tests/01-echo.sh > main.out});
return `cat -n valgrind.out` eq "";
}
ok(clang_check(), "clang check");
ok(valgrind(), "valgrind");
my $procs = `ps | grep memcheck`;
chomp $procs;
ok($procs eq "", "no stray processes after tests");
if ($procs ne "") {
system("killall memcheck-amd64-");
}