forked from openresty/sregex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit-test-file.pl
executable file
·87 lines (63 loc) · 1.38 KB
/
split-test-file.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
#!/usr/bin/env perl
use strict;
use warnings;
my $infile = shift
or usage();
if ($infile !~ m{(.*)\.t_?$}) {
die "Bad input file name: $infile\n";
}
my $base = $1;
open my $in, $infile
or die "cannot open $infile for reading: $!\n";
my $preamble;
my $parsing;
my $ncases = 0;
my $nfiles = 0;
my $out;
while (<$in>) {
if (!$parsing) {
$preamble .= $_;
if (/^__DATA__$/) {
$parsing = 1;
}
next;
}
# parsing
if (/^=== /) {
$ncases++;
if ($ncases % 50 == 1) {
if (defined $out) {
close $out;
undef $out;
}
$nfiles++;
my $suffix = sprintf("%02d", $nfiles);
my $outfile = "$base-$suffix.t";
warn "writing $outfile ...\n";
open $out, ">$outfile"
or die "cannot open $outfile for writing: $!\n";
print $out $preamble;
}
my $ntests = $ncases % 50 ? $ncases % 50 : 50;
$_ =~ s/^===\sTEST\s+(\d+)/=== TEST $ntests/g;
print $out $_;
next;
}
if (!defined $out) {
#die "syntax error in $infile: $.: $_";
$preamble .= $_;
next;
}
print $out $_;
}
if (defined $out) {
close $out;
undef $out;
}
close $in;
warn "base: $base\n";
sub usage {
die <<_EOC_;
Usage: $0 <infile>
_EOC_
}