Skip to content
Browse files

Start redoing the Harness class API so that we don't need to manually…

… create a view or a testrun factory for basic usage
  • Loading branch information...
1 parent 9e46b95 commit eb7bc71952162892c8515fed4c3368832c4d6f5d @Whiteknight committed Sep 4, 2011
Showing with 82 additions and 52 deletions.
  1. +67 −13 src/harness/Harness.winxed
  2. +15 −39 t/harness
View
80 src/harness/Harness.winxed
@@ -9,19 +9,65 @@ namespace Rosella
*/
class Harness
{
- function Harness() { }
+ var testrun_factory;
+ var default_view;
+ var saved_runs;
+
+ function Harness()
+ {
+ self.testrun_factory = new Rosella.Harness.TestRun.Factory();
+ self.saved_runs = [];
+ }
+
+ /* Routines for adding tests to the harness
+ */
+
+ function add_testfile_type(string name, var type)
+ {
+ self.testrun_factory.add_testfile_type(name, type);
+ return self;
+ }
+
+ function add_test_dirs(string testfile_type_s, var dirs [slurpy],
+ var options [slurpy,named])
+ {
+ self.testrun_factory.add_test_dirs(testfile_type_s, dirs:[flat],
+ options:[flat,named]);
+ return self;
+ }
+
+ function add_test_files(string testfile_type_s, var files [slurpy],
+ var options [slurpy,named])
+ {
+ self.testrun_factory.add_test_files(testfile_type_s, files:[flat],
+ options:[flat,named]);
+ return self;
+ }
+
+ function setup_test_run(var view [optional], int has_view [opt_flag])
+ {
+ if (!has_view || view == null)
+ view = self.default_view();
+ var run = self.testrun_factory.create();
+ view.add_run(run, 0);
+ push(self.saved_runs, run);
+ return run;
+ }
/* Routines for Running the Harness
*/
function default_view()
{
- return new Rosella.Harness.View();
+ if (self.default_view == null)
+ self.default_view = new Rosella.Harness.View();
+ return self.default_view;
}
// Run the harness. Optionally take a custom view, and a handful of
// other named options.
- function run(var test_run, var view,
+ function run(var test_runs [optional], int has_runs [opt_flag],
+ var view [optional], int has_view [opt_flag],
int run_inline [named,optional], int has_ri [opt_flag],
int line_length [named,optional], int has_ll [opt_flag],
int debug [named,optional], int has_dbg [opt_flag])
@@ -32,21 +78,29 @@ namespace Rosella
line_length = 0;
if (!has_dbg)
debug = 0;
- return self.run_internal(test_run, view, run_inline, debug);
+ if (has_view == 0 || view == null)
+ view = self.default_view();
+ if (has_runs == 0 || test_runs == null)
+ test_runs = self.saved_runs;
+ return self.run_internal(test_runs, view, run_inline, debug);
}
// Interal routine to run the harness
- function run_internal(var test_run, var view, int run_inline, int debug)
+ function run_internal(var test_runs, var view, int run_inline, int debug)
{
- for (var test in test_run.tests()) {
- view.start_test(test);
- test.run(view, debug, run_inline);
- test_run.update_test_stats(test);
- view.end_test(test);
+ for (var test_run in test_runs) {
+ for (var test in test_run.tests()) {
+ view.start_test(test);
+ test.run(view, debug, run_inline);
+ test_run.update_test_stats(test);
+ view.end_test(test);
+ }
+ test_run.mark_completed();
+ view.test_run_complete(test_run);
+ if (!test_run.run_was_success())
+ return 0;
}
- test_run.mark_completed();
- view.test_run_complete(test_run);
- return test_run.run_was_success();
+ return 1;
}
}
}
View
54 t/harness
@@ -5,45 +5,31 @@ INIT {
my @argv := pir::getinterp__P()[2];
my $dummy := pir::shift__PP(@argv);
-
-my $factory := Rosella::construct(Rosella::Harness::TestRun::Factory);
my $harness := Rosella::construct(Rosella::Harness);
-my $testview := $harness.default_view();
-
-my @test_runs := [];
if (pir::elements(@argv)) {
for @argv -> $dir {
my $type := "NQP";
if ($dir eq "template") {
$type := "Winxed";
}
- $factory.add_test_dirs($type, "t/$dir", :recurse(1));
- my $run := $factory.create();
- pir::push(@test_runs, $run);
- $testview.add_run($run, 0);
+ $harness.add_test_dirs($type, "t/$dir", :recurse(1)).setup_test_run();
}
} else {
# Core tests (If these fail, we don't attempt anything else)
- $factory.add_test_dirs("NQP",
+ $harness.add_test_dirs("NQP",
"t/core"
- );
- my $run := $factory.create();
- pir::push(@test_runs, $run);
- $testview.add_run($run, 0);
+ ).setup_test_run();
# Winxed tests
# These are some basic sanity tests to prove we can also write tests in
# winxed.
- $factory.add_test_dirs("Winxed",
+ $harness.add_test_dirs("Winxed",
"t/winxed_test"
- );
- $run := $factory.create();
- pir::push(@test_runs, $run);
- $testview.add_run($run, 0);
+ ).setup_test_run();
# Stable library tests
- $factory.add_test_dirs("NQP",
+ $harness.add_test_dirs("NQP",
"t/tap_harness", # "harness", can't shadow t/harness program
"t/test",
"t/action",
@@ -57,31 +43,21 @@ if (pir::elements(@argv)) {
"t/path",
"t/string",
:recurse(1)
- );
- $run := $factory.create();
- pir::push(@test_runs, $run);
- $testview.add_run($run, 0);
+ ).setup_test_run();
# Unstable library tests
- $factory.add_test_dirs("NQP",
+ $harness.add_test_dirs("NQP",
"t/prototype",
:recurse(1)
- );
- $factory.add_test_dirs("Winxed",
+ ).add_test_dirs("Winxed",
"t/template",
:recurse(1)
- );
- $run := $factory.create();
- pir::push(@test_runs, $run);
- $testview.add_run($run, 0);
+ ).setup_test_run();
}
-for @test_runs -> $run {
- my $result := $harness.run($run, $testview);
- if (!$result) {
- $testview.show_results();
- pir::exit(1);
- }
+my $result := $harness.run();
+$harness.default_view.show_results();
+if (!$result) {
+ pir::exit(1);
}
-$testview.show_results();
-#pir::exit(0);
+

0 comments on commit eb7bc71

Please sign in to comment.
Something went wrong with that request. Please try again.