mirror of
https://github.com/openresty/openresty.git
synced 2024-10-13 00:29:41 +00:00
added test scaffold t::Config.
This commit is contained in:
66
t/Config.pm
Normal file
66
t/Config.pm
Normal file
@ -0,0 +1,66 @@
|
||||
package t::Config;
|
||||
|
||||
use Test::Base -Base;
|
||||
use IPC::Run3 qw( run3 );
|
||||
|
||||
our @EXPORT = qw(
|
||||
run_tests
|
||||
);
|
||||
|
||||
sub run_tests;
|
||||
sub run_test ($);
|
||||
sub shell (@);
|
||||
sub cd ($);
|
||||
|
||||
sub run_tests {
|
||||
my $ver = `bash util/ver`;
|
||||
chomp $ver;
|
||||
|
||||
cd "ngx_openresty-$ver";
|
||||
|
||||
for my $block (blocks()) {
|
||||
run_test($block);
|
||||
}
|
||||
}
|
||||
|
||||
sub run_test ($) {
|
||||
my $block = shift;
|
||||
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 = '';
|
||||
}
|
||||
|
||||
my $expected_out = $block->out;
|
||||
if (!defined $expected_out) {
|
||||
$expected_out = '';
|
||||
}
|
||||
|
||||
is($stdout, $expected_out, "$name - stdout ok");
|
||||
is($stderr, $expected_err, "$name - stderr ok");
|
||||
is($retval >> 8, $expected_exit, "$name - exit code ok");
|
||||
}
|
||||
|
||||
sub shell (@) {
|
||||
system(@_);
|
||||
}
|
||||
|
||||
sub cd ($) {
|
||||
my $dir = shift;
|
||||
print("cd $dir\n");
|
||||
chdir $dir or die "failed to cd $dir: $!\n";
|
||||
}
|
||||
|
Reference in New Issue
Block a user