forked from wofr06/lesspipe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.pl
executable file
·93 lines (89 loc) · 2.64 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
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
#!/usr/bin/env perl
#use strict;
#use warnings;
use vars qw(%ENV);
my $debug = 0;
$debug = 1 if $ARGV[0] and $ARGV[0] eq '-d';
$ENV{LESSOPEN} = "|./lesspipe.sh %s";
# to check all test cases with the filter
$ENV{LESS_ADVANCED_PREPROCESSOR} =1;
open F, "TESTCMDS" or die "Could not read TESTCMDS:$!\n";
my $retcode = 0;
my $duration = time();
my $sumok = 0;
my $sumignore = 0;
my $sumnok = 0;
while (<F>) {
next if /^#/;
next if /^\s*$/;
chomp;
my $ignore = $1 if s/#\s*needs (.*)//;
my $res = `$_ 2>&1`;
my $ok = 0;
my $lines = 0;
if ( $res and $res =~ /command not found: (\S+)/m ) { # zsh style
print "result:$res" if $debug;
$res = "NOT found: $1";
$ok = 1;
} elsif ( $res and $res =~ /(\S+):\s+command not found/m ) { # bash style
print "result:$res" if $debug;
$res = "NOT found: $1";
$ok = 1;
} elsif ( $res and $res =~ /(\S+):\s+not found/m ) { # ksh style
print "result:$res" if $debug;
$res = "NOT found: $1";
$ok = 1;
} elsif ( $res and $res =~ /no such file or directory: .*?([^\/]+)\b$/m ) {
print "result:$res" if $debug;
$res = "NOT found: $1";
$ok = 1;
} elsif ( $res ) {
print "result:$res" if $debug;
my @res = split /\n/, $res;
shift @res if $res[0] =~ /^==>/;
$res[0] =~ s/^pst0$//;
shift @res while @res and $res[0] =~ /^\s*$/;
# special case for directory listing
$res[0] = 'test' if $res =~ /-rw-.*test/;
$ok = $res[0] =~ /^\s*(\e\[36m)?test(\e\[0m)?\s*$/ if $res[0];
# special case for nroff
$ok = $res[0] =~ s/^test \(1\)\s+.*/test/ if $res[0] and ! $ok;
# special case for perl storable
$ok = $res[0] =~ s/^\$VAR1 = \\'test';$/test/ if $res[0] and ! $ok;
# special case for batcat
$ok = $res[0] = 'test' if $res[3] =~ /test/;
# special case for mp3
if ($res[1] and ! $ok) {
$ok = $res[1] =~ s/.*Title.*:\s+test\b.*/test/;
$res[0] = $res[1] if $ok;
}
$res = $res[0] if $res[0];
$lines = $#res;
}
if ( $ok ) {
$res =~ s/test/ok/ if $ok;
$res =~ s/^\s+// if $ok;
#$res .= " ($lines trailing lines)" if $lines;
$sumok++;
} else {
my $failed = is_exec($ignore);
$retcode++ if ! $ok and $failed;
$res = "NOT ok";
$res = "ignored, needs " . (split ' ', $ignore)[0] if ! $failed;
$sumnok++ if $failed;
$sumignore++ if ! $failed;
}
printf "%-56s %s\n", $_, $res;
}
close F;
$duration = time() - $duration;
print "$sumok/$sumignore/$sumnok tests passed/ignored/failed in $duration seconds\n";
exit $retcode;
sub is_exec {
my $arg = shift;
return 1 if ! $arg;
for my $prog (split ' ', $arg) {
return 1 if grep {-x "$_/$prog"} split /:/, $ENV{PATH};
}
return 0
}