changing the module name.
This commit is contained in:
parent
886a2b8b19
commit
f56a78841f
|
@ -1,4 +1,4 @@
|
||||||
package Owl::TestRunner v0.0.1;
|
package LPSC::Builder::TestRunner;
|
||||||
|
|
||||||
use v5.30.0;
|
use v5.30.0;
|
||||||
|
|
||||||
|
@ -16,8 +16,6 @@ use Capture::Tiny qw/tee_merged/;
|
||||||
use Term::ANSIColor qw/color/;
|
use Term::ANSIColor qw/color/;
|
||||||
|
|
||||||
my $db_file = path($0)->parent->child('test.db');
|
my $db_file = path($0)->parent->child('test.db');
|
||||||
my %test_files_success_status;
|
|
||||||
tie %test_files_success_status, 'DB_File', $db_file;
|
|
||||||
|
|
||||||
my @errors;
|
my @errors;
|
||||||
|
|
||||||
|
@ -33,8 +31,8 @@ my $ERROR_CODE_SOME_TEST_FAILED = 500;
|
||||||
);
|
);
|
||||||
|
|
||||||
sub new {
|
sub new {
|
||||||
my $class = shift;
|
my $class = shift;
|
||||||
my $self = bless {}, $class;
|
my $self = bless {}, $class;
|
||||||
|
|
||||||
my %params = $validator->(@_);
|
my %params = $validator->(@_);
|
||||||
|
|
||||||
|
@ -45,85 +43,88 @@ my $ERROR_CODE_SOME_TEST_FAILED = 500;
|
||||||
return $self;
|
return $self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
sub _options {
|
sub _options {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if ( !defined $self->{options} ) {
|
if ( !defined $self->{options} ) {
|
||||||
$self->{options} = {};
|
$self->{options} = {};
|
||||||
$self->_getopt;
|
$self->_getopt;
|
||||||
}
|
}
|
||||||
return $self->{options};
|
return $self->{options};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _getopt {
|
sub _getopt {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($opt, $usage) = describe_options(
|
my ( $opt, $usage ) = describe_options(
|
||||||
'./test_runner.pl %o',
|
'./test_runner.pl %o',
|
||||||
[ 'clean|c', "Cleans the previously succeded tests", ],
|
[ 'clean|c', "Cleans the previously succeded tests", ],
|
||||||
[ 'halt|h', "Halts on error", ],
|
[ 'halt|h', "Halts on error", ],
|
||||||
[],
|
[],
|
||||||
[ 'help', "print usage message and exit", { shortcircuit => 1 } ],
|
[ 'help', "print usage message and exit", { shortcircuit => 1 } ],
|
||||||
);
|
);
|
||||||
|
|
||||||
print($usage->text), die if $opt->help;
|
print( $usage->text ), die if $opt->help;
|
||||||
my $options = $self->_options;
|
my $options = $self->_options;
|
||||||
$options->{halt} = $opt->halt;
|
$options->{halt} = $opt->halt;
|
||||||
$options->{clean} = $opt->clean;
|
$options->{clean} = $opt->clean;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub run {
|
sub run {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
if ($self->_options->{clean}) {
|
if ( $self->_options->{clean} ) {
|
||||||
%test_files_success_status = ();
|
%test_files_success_status = ();
|
||||||
}
|
}
|
||||||
for my $test_file (@{$self->{test_files}}) {
|
for my $test_file ( @{ $self->{test_files} } ) {
|
||||||
if ($self->_test_already_succeded($test_file)) {
|
if ( $self->_test_already_succeded($test_file) ) {
|
||||||
say omited() . "$test_file last test was successful.";
|
say omited() . "$test_file last test was successful.";
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
my $return_code;
|
my $return_code;
|
||||||
my ($merged) = tee_merged {
|
my ($merged) = tee_merged {
|
||||||
$return_code = system $test_file;
|
$return_code = system $test_file;
|
||||||
};
|
};
|
||||||
$test_files_success_status{$test_file} = !$return_code;
|
my %test_files_success_status;
|
||||||
if ($return_code) {
|
tie %test_files_success_status, 'DB_File', $db_file;
|
||||||
push @errors, error() . "File $test_file\n" . $merged;
|
$test_files_success_status{$test_file} = !$return_code;
|
||||||
if ($self->_options->{halt}) {
|
if ($return_code) {
|
||||||
$self->show_errors;
|
push @errors, error() . "File $test_file\n" . $merged;
|
||||||
}
|
if ( $self->_options->{halt} ) {
|
||||||
}
|
$self->show_errors;
|
||||||
}
|
}
|
||||||
$self->show_errors;
|
}
|
||||||
|
}
|
||||||
|
$self->show_errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub show_errors {
|
sub show_errors {
|
||||||
for my $error (@errors) {
|
for my $error (@errors) {
|
||||||
say $error;
|
say $error;
|
||||||
}
|
}
|
||||||
if (@errors) {
|
if (@errors) {
|
||||||
exit $ERROR_CODE_SOME_TEST_FAILED;
|
exit $ERROR_CODE_SOME_TEST_FAILED;
|
||||||
}
|
}
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub omited {
|
sub omited {
|
||||||
return color('blue').'[[OMITED]] '.reset_color();
|
return color('blue') . '[[OMITED]] ' . reset_color();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub error {
|
sub error {
|
||||||
return color('red').'[[ERROR]] '.reset_color();
|
return color('red') . '[[ERROR]] ' . reset_color();
|
||||||
}
|
}
|
||||||
|
|
||||||
sub reset_color {
|
sub reset_color {
|
||||||
return color('reset');
|
return color('reset');
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _test_already_succeded {
|
sub _test_already_succeded {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
my $test = shift;
|
my $test = shift;
|
||||||
|
my %test_files_success_status;
|
||||||
return $test_files_success_status{$test};
|
tie %test_files_success_status, 'DB_File', $db_file;
|
||||||
|
|
||||||
|
return $test_files_success_status{$test};
|
||||||
}
|
}
|
||||||
1;
|
1;
|
||||||
|
|
Loading…
Reference in New Issue