1
0
mirror of https://github.com/openresty/openresty synced 2024-11-14 08:45:50 +01:00
openresty/util/fix-tests
2016-01-25 14:33:53 -08:00

86 lines
1.7 KiB
C
Executable File

#!/usr/bin/env perl
use strict;
use warnings;
sub cd ($);
my $ver = `bash util/ver`;
chomp $ver;
cd "openresty-$ver/bundle";
opendir(my $dh, '.') or
die "cannot opendir .: $!";
my @dirs = grep { /\d+\.\d+/ && -d "$_" } readdir($dh);
closedir $dh;
cd '../../t';
opendir($dh, '.') or
die "cannot opendir .: $!";
my @t_files = grep { /\.t$/ } readdir($dh);
closedir $dh;
for my $t_file (@t_files) {
open my $in, $t_file or
die "Cannot open $t_file for reading: $!\n";
my $outfile = $t_file . '_';
open my $out, ">$outfile" or
die "Cannot open $outfile for writing: $!\n";
my $changed;
while (<$in>) {
for my $dir (@dirs) {
(my $pat = $dir) =~ s/-(\d+\..*)/-/;
my $orig = $_;
if (s{\.\./$pat\S+}{../$dir}g && $orig ne $_) {
$changed++;
warn "\n- $orig";
warn "+ $_";
} elsif (s{openresty-\d+\.\d+\.\d+\.\d+(?:rc\d+)?}{openresty-$ver} && $orig ne $_) {
$changed++;
warn "\n- $orig";
warn "+ $_";
} elsif (s{OPENRESTY_BUILD_DIR/$pat[^/ \t\n\w]*\d[^/ \t\n]*}{OPENRESTY_BUILD_DIR/$dir}g && $orig ne $_) {
$changed++;
warn "\n- $orig";
warn "+ $_";
} elsif (s{^cd $pat[^/ \t\n]+}{cd $dir}g && $orig ne $_) {
$changed++;
warn "\n- $orig";
warn "+ $_";
}
}
print $out $_;
}
close $out;
warn "Wrote t/$outfile\n";
close $in;
}
#print join("\n", map { /^LuaJIT/ ? "* ~$_" : "* $_" } sort @dirs), "\n";
sub cd ($) {
my $dir = shift;
print("cd $dir\n");
chdir $dir or die "failed to cd $dir: $!\n";
}