-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathupdate-compiletest-from-doctest.pl
executable file
·80 lines (66 loc) · 2.19 KB
/
update-compiletest-from-doctest.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
#!/usr/bin/perl -w
# This extracts the `compile_fail` tests from the doctests and puts
# them in a folder for `trybuild` to test. `trybuild` lets us verify
# that the errors generated are what are expected. This should be
# re-run after any change to the doctests, and the results should be
# checked in along with any new `.stderr` files.
die "Running in wrong directory" unless -f "../qcell/Cargo.toml";
$/ = undef;
for my $in (<src/doctest_*.rs>) {
my $prefix = $in;
$prefix =~ s|^.*doctest_(.*?)\.rs$|trybuild-qcell/src/compiletest/$1|;
die "Can't read $in" unless open IN, "<$in";
my $data = <IN>;
die "Can't read $in" unless close IN;
my @tests = ();
my %index = ();
while (1) {
last unless $data =~ s/```compile_fail(.*?)```//s;
my $test = $1;
$test =~ s|//!#?||sg;
$test =~ s/^/ /mg;
$test =~ s/^[ \t]*\n//s; # Remove initial empty line
$test =~ s/\s*$//s;
my $testdata = <<"EOF";
extern crate qcell;
#[allow(warnings)]
fn main() {
$test
}
EOF
push @tests, $testdata;
$index{$testdata} = @tests-1;
}
for my $fnam (<$prefix-*.rs>) {
die "Can't read $in" unless open IN, "<$fnam";
my $data = <IN>;
die "Can't read $in" unless close IN;
# Keep the file if it is still identical to a test still
# required, else delete it
my $match = $index{$data};
if (defined $match) {
$tests[$match] = '';
} else {
print "Deleting $fnam ...\n";
die "Can't delete file: $fnam" unless unlink $fnam;
# Also delete error file if present
my $stderr = $fnam;
$stderr =~ s/\.rs$/.stderr/;
unlink $stderr;
}
}
# Output the rest in a sequential order
my $cnt = 0;
for $data (@tests) {
next if $data eq '';
while (1) {
my $out = sprintf("%s-%02d.rs", $prefix, $cnt++);
next if -f $out;
print "Writing $out ...\n";
die "Can't create file: $out" unless open OUT, ">$out";
print OUT $data;
die "Can't write file: $out" unless close OUT;
last;
}
}
}