Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
quick cleanups of the testsuite code
- Loading branch information
1 parent
1f28bf8
commit f6be7b0
Showing
6 changed files
with
122 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class Rosella::Failure { | ||
has $!fault; | ||
has $!test_case; | ||
|
||
our method fault($value?) { | ||
if pir::defined__IP($value) { | ||
$!fault := $value; | ||
} | ||
$!fault; | ||
} | ||
|
||
our method test_case($value?) { | ||
if pir::defined__IP($value) { | ||
$!test_case := $value; | ||
} | ||
$!test_case; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1,123 @@ | ||
# Copyright (C) 2010, Austin Hastings. See accompanying LICENSE file, or | ||
# http://www.opensource.org/licenses/artistic-license-2.0.php for license. | ||
|
||
class Rosella::Failure { | ||
has $!fault; | ||
has $!test_case; | ||
|
||
our method fault($value?) { | ||
if pir::defined__IP($value) { | ||
$!fault := $value; | ||
class Rosella::Result { | ||
has @!errors; | ||
has @!failures; | ||
has @!listeners; | ||
has $!should_stop; | ||
has $!num_tests; | ||
has $!planned_tests; | ||
|
||
our method should_stop($value?) { | ||
if pir::defined($value) { | ||
$!should_stop := $value; | ||
} | ||
$!fault; | ||
$!should_stop; | ||
} | ||
|
||
our method test_case($value?) { | ||
if pir::defined__IP($value) { | ||
$!test_case := $value; | ||
our method num_tests($value?) { | ||
if pir::defined($value) { | ||
$!num_tests := $value; | ||
} | ||
$!test_case; | ||
$!num_tests; | ||
} | ||
} | ||
|
||
class Rosella::Result; | ||
|
||
has @!errors; | ||
has @!failures; | ||
has @!listeners; | ||
has $!should_stop; | ||
has $!num_tests; | ||
has $!planned_tests; | ||
|
||
our method should_stop($value?) { | ||
if pir::defined($value) { | ||
$!should_stop := $value; | ||
our method add_error($test, $error) { | ||
self.add_fault($test, $error, :notify('add_error'), :queue(@!errors)); | ||
} | ||
$!should_stop; | ||
} | ||
|
||
our method num_tests($value?) { | ||
if pir::defined($value) { | ||
$!num_tests := $value; | ||
our method add_failure($test, $failure) { | ||
self.add_fault($test, $failure, :notify('add_failure'), :queue(@!failures)); | ||
} | ||
$!num_tests; | ||
} | ||
|
||
our method add_error($test, $error) { | ||
self.add_fault($test, $error, :notify('add_error'), :queue(@!errors)); | ||
} | ||
my method add_fault($test, $exception, :$notify, :$queue) { | ||
my $failure := Rosella::build(Rosella::Failure); | ||
$failure.fault($exception); | ||
$failure.test_case($test); | ||
|
||
our method add_failure($test, $failure) { | ||
self.add_fault($test, $failure, :notify('add_failure'), :queue(@!failures)); | ||
} | ||
$queue.push($failure); | ||
self.notify_listeners($notify, $failure); | ||
} | ||
|
||
my method add_fault($test, $exception, :$notify, :$queue) { | ||
my $failure := Rosella::Failure.new(); | ||
$failure.fault($exception); | ||
$failure.test_case($test); | ||
our method add_listener($listener) { | ||
@!listeners := @!listeners.push($listener); | ||
self; | ||
} | ||
|
||
$queue.push($failure); | ||
self.notify_listeners($notify, $failure); | ||
} | ||
our method end_test($test) { | ||
self.notify_listeners('end_test', $test); | ||
} | ||
|
||
our method add_listener($listener) { | ||
@!listeners := @!listeners.push($listener); | ||
self; | ||
} | ||
our method error_count() { | ||
pir::elements(@!errors); | ||
} | ||
|
||
our method end_test($test) { | ||
self.notify_listeners('end_test', $test); | ||
} | ||
our method failure_count() { | ||
pir::elements(@!failures); | ||
} | ||
|
||
our method error_count() { | ||
pir::elements(@!errors); | ||
} | ||
my method notify_listeners($method, $arg) { | ||
for @!listeners { | ||
my $object := $_; | ||
Q:PIR { | ||
.local pmc object, meth, arg | ||
object = find_lex '$object' | ||
meth = find_lex '$method' | ||
arg = find_lex '$arg' | ||
our method failure_count() { | ||
pir::elements(@!failures); | ||
} | ||
$I0 = isa meth, 'Sub' | ||
unless $I0 goto call_string | ||
my method notify_listeners($method, $arg) { | ||
for @!listeners { | ||
my $object := $_; | ||
Q:PIR { | ||
.local pmc object, meth, arg | ||
object = find_lex '$object' | ||
meth = find_lex '$method' | ||
arg = find_lex '$arg' | ||
object.meth(arg) | ||
$I0 = isa meth, 'Sub' | ||
unless $I0 goto call_string | ||
object.meth(arg) | ||
call_string: | ||
$S0 = meth | ||
object.$S0(arg) | ||
}; | ||
} | ||
|
||
call_string: | ||
$S0 = meth | ||
object.$S0(arg) | ||
}; | ||
self; | ||
} | ||
|
||
self; | ||
} | ||
|
||
our method plan_tests($num_tests) { | ||
# Ignore repeats in hierarchy of suites. | ||
unless $!planned_tests { | ||
$!planned_tests := $num_tests; | ||
self.notify_listeners: 'plan_tests', $num_tests; | ||
our method plan_tests($num_tests) { | ||
# Ignore repeats in hierarchy of suites. | ||
unless $!planned_tests { | ||
$!planned_tests := $num_tests; | ||
self.notify_listeners: 'plan_tests', $num_tests; | ||
} | ||
} | ||
} | ||
|
||
our method remove_listener($listener) { | ||
my $index := 0; | ||
our method remove_listener($listener) { | ||
my $index := 0; | ||
|
||
while $index < self.listeners.elems { | ||
if self.listeners[$index] =:= $listener { | ||
self.listeners.delete($index); | ||
} | ||
else { | ||
$index++; | ||
while $index < self.listeners.elems { | ||
if self.listeners[$index] =:= $listener { | ||
self.listeners.delete($index); | ||
} | ||
else { | ||
$index++; | ||
} | ||
} | ||
} | ||
|
||
self; | ||
} | ||
self; | ||
} | ||
|
||
our method run_count() { | ||
self.num_tests; | ||
} | ||
our method run_count() { | ||
self.num_tests; | ||
} | ||
|
||
our method start_test($test) { | ||
self.num_tests(self.num_tests + $test.num_tests); | ||
self.notify_listeners('start_test', $test); | ||
} | ||
our method start_test($test) { | ||
self.num_tests(self.num_tests + $test.num_tests); | ||
self.notify_listeners('start_test', $test); | ||
} | ||
|
||
our method stop() { | ||
self.should_stop(1); | ||
self; | ||
} | ||
our method stop() { | ||
self.should_stop(1); | ||
self; | ||
} | ||
|
||
our method was_successful() { | ||
self.error_count == 0 && self.failure_count == 0; | ||
our method was_successful() { | ||
self.error_count == 0 && self.failure_count == 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters