5 # run script on the first line and compare its output to remaining lines
7 my $regenerate = @ARGV > 1 && $ARGV[0] eq '-G' && shift;
9 @ARGV or die "missing input script\n";
10 !!(my $spec = readline)
11 or die "input lacks a script on the first line\n";
15 my $wantexit = $script =~ s/\h+[?](\d+)\z// ? $1 : 0;
16 my $wantwarn = $script !~ s/[?]\z//;
18 if ($script =~ /\|/) {
19 # explicit shell wrapper to capture all warnings
20 $script =~ s/'/'\\''/g;
21 $shell = "sh -c '$shell'";
23 $shell .= ' 2>&1' if $wantwarn;
25 local $ENV{COLUMNS} = 40;
26 open my $cmd, '-|', $shell or do {
27 say "cannot run script `$script`: $!";
30 my @lines = readline $cmd;
35 open my $rewrite, '>', $ARGV;
36 print {$rewrite} $_ for $spec, @lines;
40 if ($error != $wantexit) {
41 say "unexpected exit status $error for `$script`";
45 my @wanted = readline;
48 while (@lines or @wanted) {
49 my $was = shift @wanted;
50 my $is = shift @lines;
51 next if defined $was and defined $is and $was eq $is;
53 print color(32), "< ", color(0), $_ for $was // ();
54 print color(31), "> ", color(0), $_ for $is // ();