File: testsuite

package info (click to toggle)
colorized-logs 2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 152 kB
  • sloc: ansic: 883; perl: 132; makefile: 3; sh: 1
file content (124 lines) | stat: -rwxr-xr-x 2,736 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl
use warnings;
print "Running tests...\n" unless @ARGV;
undef $/;

my $DATADIR = $0;
$DATADIR=~s|testsuite$||;
$DATADIR//='.';
my $BINDIR = $ENV{'BINDIR'}//'.';

-x "$DATADIR/unescape" or $DATADIR="$DATADIR/tests";
-x "$DATADIR/unescape" or die "unescape missing from $DATADIR?\n";
-x "$BINDIR/ansi2html" or $BINDIR="$BINDIR/..";
-x "$BINDIR/ansi2html" or die "ansi2html not yet built in $BINDIR?\n";

my $id = $$;

my ($pass,$fail) = (0,0);
sub test($$$$;$)
{
    my ($name, $cmd, $stdin, $stdout, $expret) = @_;
    $expret //= 0;

    return if @ARGV && !grep { $name eq $_ } @ARGV;
    printf '* %-20s ', $name unless @ARGV;

    open I, '>', "stdin.$id" or die "Can't write to \"stdin.$id\": $!\n";
    print I $stdin;
    close I;
    open O, '>', "expout.$id" or die "Can't write to \"expout.$id\": $!\n";
    print O $stdout;
    close O;

    my $pid = fork;
    unless ($pid)
    {
        alarm 20;
        open STDIN,  '<', "stdin.$id"  or die "Can't dup stdin: $!\n";
        open STDOUT, '>', "stdout.$id" or die "Can't dup stdout: $!\n";
        open STDERR, '>', "stderr.$id" or die "Can't dup stderr: $!\n";
        exec $cmd;
        die "Couldn't exec: $!\n";
    }

    waitpid $pid, 0;
    my $ret = $?;
    my $bad = system "cmp -s stdout.$id expout.$id" || system "cmp -s stderr.$id /dev/null";

    if (($ret != $expret) || $bad)
    {
        $fail++;
        print "\e[31mFAIL\e[0m\n" unless @ARGV;
        system "cat stderr.$id";
        system "diff -u expout.$id stdout.$id";
        print "return value: $ret\n" if ($ret != $expret);
    }
    else
    {
        $pass++;
        print "\e[32mok\e[0m\n" unless @ARGV;
    }

    unlink "$_.$id" for qw(stdin expout stdout stderr);
}

test('ansi2txt', "$DATADIR/unescape|$BINDIR/ansi2txt", <<'IN', <<'OUT');
foo\e[1mbar\e[0m\n
\e[?2004l
\e]0;title1\e\\
\e]4;16;rgb:0/0/0\e\\
\e]0;title2\a
\n
IN
foobar

OUT

test('ansi2html', "$DATADIR/unescape|$BINDIR/ansi2html|$DATADIR/htmlpre2txt", <<'IN', <<"OUT");
foo\e[1mbar\e[0m\n
\e[?2004l
\e]0;title1\e\\
\e]4;16;rgb:0/0/0\e\\
\e]0;title2\a
\n
\f\n
\xff\n
IN
foobar

\f
\xff
OUT

test('pipetty', "$BINDIR/pipetty </dev/null sh stdin.$id", <<'IN', <<'OUT');
test -t 0
printf 'isatty(0): %d\n' $?
test -t 1
printf 'isatty(1): %d\n' $?
test -t 2
printf 'isatty(2): %d\n' $?
IN
isatty(0): 1
isatty(1): 0
isatty(2): 0
OUT

test('pipetty:sigobit', "$BINDIR/pipetty </dev/null sh stdin.$id 2>&1", <<'IN', <<'OUT', 0x8f00);
PID=$$
(kill $PID) &
sleep 10
IN
Terminated
OUT

test('ttyrec2ansi', "$DATADIR/unescape|$BINDIR/ttyrec2ansi", <<'IN', <<'OUT');
aaaa10\a\0\b\0\0\0foo bar\n
aaaa10\b\0\b\0\0\0baz qux\n
IN
foo bar
baz qux
OUT

print "Passed: $pass, failed: $fail.\n" unless @ARGV;
exit($fail>0);