added basic tests and reindex script
This commit is contained in:
Родитель
97dd3cdeaf
Коммит
d4b754a8b1
|
@ -0,0 +1,36 @@
|
|||
# vi:ft=perl
|
||||
use lib 'lib';
|
||||
use Test::Nginx::Socket;
|
||||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => blocks() * repeat_each() * 2;
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: internal only
|
||||
--- config
|
||||
location /lua {
|
||||
set_by_lua $res "function fib(n) if n > 2 then return fib(n-1)+fib(n-2) else return 1 end end return fib(10)";
|
||||
echo $res;
|
||||
}
|
||||
--- request
|
||||
GET /lua
|
||||
--- response_body
|
||||
55
|
||||
|
||||
|
||||
|
||||
=== TEST 2: internal script with argument
|
||||
--- config
|
||||
location /lua {
|
||||
set_by_lua $res "return ngx.arg[1]+ngx.arg[2]" $arg_a $arg_b;
|
||||
echo $res;
|
||||
}
|
||||
--- request
|
||||
GET /lua?a=1&b=2
|
||||
--- response_body
|
||||
3
|
||||
|
|
@ -0,0 +1,64 @@
|
|||
#!/usr/bin/perl
|
||||
#: reindex.pl
|
||||
#: reindex .t files for Test::Base based test files
|
||||
#: Copyright (c) 2006 Agent Zhang
|
||||
#: 2006-04-27 2006-05-09
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
#use File::Copy;
|
||||
use Getopt::Std;
|
||||
|
||||
my %opts;
|
||||
getopts('hb:', \%opts);
|
||||
if ($opts{h} or ! @ARGV) {
|
||||
die "Usage: reindex [-b 0] t/*.t\n";
|
||||
}
|
||||
|
||||
my $init = $opts{b};
|
||||
$init = 1 if not defined $init;
|
||||
|
||||
my @files = map glob, @ARGV;
|
||||
for my $file (@files) {
|
||||
next if -d $file or $file !~ /\.t_?$/;
|
||||
reindex($file);
|
||||
}
|
||||
|
||||
sub reindex {
|
||||
my $file = $_[0];
|
||||
open my $in, $file or
|
||||
die "Can't open $file for reading: $!";
|
||||
my @lines;
|
||||
my $counter = $init;
|
||||
my $changed;
|
||||
while (<$in>) {
|
||||
s/\r$//;
|
||||
my $num;
|
||||
s/ ^ === \s+ TEST \s+ (\d+)/$num=$1; "=== TEST " . $counter++/xie;
|
||||
next if !defined $num;
|
||||
if ($num != $counter-1) {
|
||||
$changed++;
|
||||
}
|
||||
} continue {
|
||||
push @lines, $_;
|
||||
}
|
||||
close $in;
|
||||
my $text = join '', @lines;
|
||||
$text =~ s/(?x) \n+ === \s+ TEST/\n\n\n\n=== TEST/ixsg;
|
||||
$text =~ s/__(DATA|END)__\n+=== TEST/__${1}__\n\n=== TEST/;
|
||||
#$text =~ s/\n+$/\n\n/s;
|
||||
if (! $changed and $text eq join '', @lines) {
|
||||
warn "reindex: $file:\tskipped.\n";
|
||||
return;
|
||||
}
|
||||
#File::Copy::copy( $file, "$file.bak" );
|
||||
open my $out, "> $file" or
|
||||
die "Can't open $file for writing: $!";
|
||||
binmode $out;
|
||||
print $out $text;
|
||||
close $out;
|
||||
|
||||
warn "reindex: $file:\tdone.\n";
|
||||
}
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
#!/bin/bash
|
||||
script_dir=$(dirname $0)
|
||||
root=$(readlink -f $script_dir/..)
|
||||
cd $root
|
||||
git submodule update --init
|
||||
$script_dir/reindex $root/t/*.t
|
||||
export PATH=$root/work/sbin:$PATH
|
||||
killall nginx
|
||||
prove -I$root/t/test-nginx/lib $root/t/*.t
|
||||
|
|
Загрузка…
Ссылка в новой задаче