2011-03-06 16:56:26 +00:00
|
|
|
package t::Config;
|
|
|
|
|
|
|
|
use Test::Base -Base;
|
|
|
|
use IPC::Run3 qw( run3 );
|
2011-12-29 03:14:10 +00:00
|
|
|
use Cwd qw( cwd );
|
2011-03-06 16:56:26 +00:00
|
|
|
|
|
|
|
our @EXPORT = qw(
|
|
|
|
run_tests
|
|
|
|
);
|
|
|
|
|
|
|
|
sub run_tests;
|
|
|
|
sub run_test ($);
|
|
|
|
sub shell (@);
|
|
|
|
sub cd ($);
|
|
|
|
|
2011-03-06 18:19:54 +00:00
|
|
|
our $BuildRoot;
|
2011-12-29 03:14:10 +00:00
|
|
|
our $DistRoot;
|
2011-08-11 02:04:00 +00:00
|
|
|
our @SavedTests;
|
|
|
|
our $RootDir = `pwd`;
|
|
|
|
chomp $RootDir;
|
2011-03-06 18:19:54 +00:00
|
|
|
|
2011-03-06 16:56:26 +00:00
|
|
|
sub run_tests {
|
|
|
|
my $ver = `bash util/ver`;
|
|
|
|
chomp $ver;
|
|
|
|
|
2016-01-25 22:33:53 +00:00
|
|
|
cd "openresty-$ver";
|
2011-03-06 16:56:26 +00:00
|
|
|
|
2011-12-29 03:14:10 +00:00
|
|
|
$DistRoot = cwd();
|
2011-03-06 18:19:54 +00:00
|
|
|
$BuildRoot = File::Spec->rel2abs("./build");
|
|
|
|
|
2011-03-06 16:56:26 +00:00
|
|
|
for my $block (blocks()) {
|
|
|
|
run_test($block);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub run_test ($) {
|
|
|
|
my $block = shift;
|
2011-08-11 02:04:00 +00:00
|
|
|
|
2011-03-06 16:56:26 +00:00
|
|
|
my $name = $block->name;
|
|
|
|
my $cmd = $block->cmd or
|
|
|
|
die "No --- cmd defined for $name\n";
|
|
|
|
|
|
|
|
#warn "$cmd > out.txt 2>\&1";
|
|
|
|
my ($stdout, $stderr);
|
|
|
|
run3 $cmd, undef, \$stdout, \$stderr;
|
|
|
|
my $retval = $?;
|
|
|
|
|
|
|
|
my $expected_exit = $block->exit;
|
|
|
|
if (!defined $expected_exit) {
|
|
|
|
$expected_exit = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $expected_err = $block->err;
|
|
|
|
if (!defined $expected_err) {
|
|
|
|
$expected_err = '';
|
2011-03-06 18:19:54 +00:00
|
|
|
} else {
|
|
|
|
$expected_err =~ s/\$OPENRESTY_BUILD_DIR\b/$BuildRoot/gs;
|
2011-12-29 03:14:10 +00:00
|
|
|
$expected_err =~ s/\$OPENRESTY_DIR\b/$DistRoot/gs;
|
2011-03-06 16:56:26 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 00:12:54 +00:00
|
|
|
my ($expected_out, $expected_out_regex);
|
|
|
|
|
|
|
|
if (defined $block->out_like) {
|
|
|
|
$expected_out_regex = $block->out_like;
|
|
|
|
if (!ref $expected_out_regex) {
|
|
|
|
$expected_out_regex = qr~$expected_out_regex~s;
|
|
|
|
}
|
|
|
|
|
|
|
|
} elsif (defined $block->out) {
|
|
|
|
$expected_out = $block->out;
|
|
|
|
|
2011-03-06 18:19:54 +00:00
|
|
|
} else {
|
2019-02-05 00:12:54 +00:00
|
|
|
$expected_out = '';
|
2011-03-06 16:56:26 +00:00
|
|
|
}
|
|
|
|
|
2011-08-11 02:04:00 +00:00
|
|
|
#die $BuildRoot;
|
|
|
|
|
|
|
|
$stdout =~ s/\Q$BuildRoot\E/\$OPENRESTY_BUILD_DIR/g;
|
2011-12-29 03:14:10 +00:00
|
|
|
$stdout =~ s/\Q$DistRoot\E/\$OPENRESTY_DIR/g;
|
2011-08-11 02:04:00 +00:00
|
|
|
|
2019-02-05 00:12:54 +00:00
|
|
|
if (ref $expected_out_regex) {
|
|
|
|
like $stdout, $expected_out_regex, "$name - stdout like ok";
|
|
|
|
|
|
|
|
} else {
|
|
|
|
is $stdout, $expected_out, "$name - stdout ok";
|
|
|
|
}
|
|
|
|
|
2011-03-06 16:56:26 +00:00
|
|
|
is($stderr, $expected_err, "$name - stderr ok");
|
|
|
|
is($retval >> 8, $expected_exit, "$name - exit code ok");
|
2011-03-06 18:59:54 +00:00
|
|
|
|
2011-08-11 02:04:00 +00:00
|
|
|
my $makefile;
|
|
|
|
|
2011-03-06 18:59:54 +00:00
|
|
|
if (defined $block->makefile) {
|
|
|
|
open my $in, "Makefile" or
|
|
|
|
die "cannot open Makefile for reading: $!";
|
2011-08-11 02:04:00 +00:00
|
|
|
$makefile = do { local $/; <$in> };
|
2011-03-06 18:59:54 +00:00
|
|
|
close $in;
|
|
|
|
|
|
|
|
my $expected_makefile = $block->makefile;
|
2011-08-11 02:04:00 +00:00
|
|
|
#$expected_makefile =~ s/\$OPENRESTY_BUILD_DIR\b/$BuildRoot/gs;
|
|
|
|
|
|
|
|
$makefile =~ s/\Q$BuildRoot\E/\$OPENRESTY_BUILD_DIR/g;
|
2015-10-29 13:36:27 +00:00
|
|
|
$makefile =~ s/\Q$DistRoot\E/\$OPENRESTY_DIR/g;
|
2011-08-11 02:04:00 +00:00
|
|
|
|
|
|
|
is($makefile, $expected_makefile, "$name - Makefile ok");
|
|
|
|
}
|
|
|
|
|
|
|
|
push @SavedTests, {
|
|
|
|
cmd => $cmd,
|
|
|
|
name => $name,
|
|
|
|
exit => $retval >> 8,
|
|
|
|
err => $stderr,
|
|
|
|
out => $stdout,
|
|
|
|
makefile => $makefile,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
END {
|
|
|
|
if ($0 =~ /_$/) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
chdir "$RootDir";
|
|
|
|
#warn `pwd`;
|
2011-03-06 18:59:54 +00:00
|
|
|
|
2011-08-11 02:04:00 +00:00
|
|
|
my $outfile = $0 . '_';
|
|
|
|
if (-f $outfile) {
|
|
|
|
unlink $outfile;
|
2011-03-06 18:59:54 +00:00
|
|
|
}
|
2011-08-11 02:04:00 +00:00
|
|
|
|
|
|
|
open my $in, $0 or
|
|
|
|
die "cannot open $0 for reading: $!\n";
|
|
|
|
|
|
|
|
while (<$in>) {
|
|
|
|
if (/^--- (?:ONLY|LAST)$/) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
close $in;
|
|
|
|
|
|
|
|
open my $out, ">$outfile" or
|
|
|
|
die "cannot open $outfile for writing: $!\n";
|
|
|
|
|
|
|
|
open $in, $0 or
|
|
|
|
die "cannot open $0 for reading: $!\n";
|
|
|
|
while (<$in>) {
|
|
|
|
print $out $_;
|
|
|
|
if (/^__DATA__$/) {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close $in;
|
|
|
|
|
|
|
|
print $out "\n";
|
|
|
|
|
|
|
|
my $n = @SavedTests;
|
|
|
|
|
|
|
|
my $i = 0;
|
|
|
|
for my $block (@SavedTests) {
|
|
|
|
my $name = $block->{name};
|
|
|
|
my $cmd = $block->{cmd};
|
|
|
|
my $stdout = $block->{out};
|
|
|
|
my $makefile = $block->{makefile};
|
|
|
|
my $exit = $block->{exit};
|
|
|
|
my $err = $block->{err};
|
|
|
|
|
|
|
|
#$stdout =~ s/$BuildRoot/\$OPENRESTY_BUILD_DIR/g;
|
|
|
|
|
|
|
|
print $out <<"_EOC_";
|
|
|
|
=== $name
|
|
|
|
--- cmd: $cmd
|
|
|
|
_EOC_
|
2019-05-29 23:18:03 +00:00
|
|
|
if ($out) {
|
|
|
|
print $out "--- out\n$stdout";
|
|
|
|
|
|
|
|
if ($makefile || $err || $exit) {
|
|
|
|
print $out "\n";
|
|
|
|
}
|
|
|
|
}
|
2011-08-11 02:04:00 +00:00
|
|
|
|
|
|
|
if ($makefile) {
|
|
|
|
#$makefile =~ s/$BuildRoot\b/\$OPENRESTY_BUILD_DIR/g;
|
|
|
|
print $out "--- makefile\n$makefile";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($err) {
|
|
|
|
print $out "--- err\n$err";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($exit) {
|
|
|
|
print $out "--- exit: $exit\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($i++ < $n - 1) {
|
|
|
|
print $out "\n\n\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print $out "\n";
|
|
|
|
|
|
|
|
close $out;
|
|
|
|
|
|
|
|
warn "wrote $outfile\n";
|
2011-03-06 16:56:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub shell (@) {
|
|
|
|
system(@_);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub cd ($) {
|
|
|
|
my $dir = shift;
|
|
|
|
print("cd $dir\n");
|
|
|
|
chdir $dir or die "failed to cd $dir: $!\n";
|
|
|
|
}
|
|
|
|
|