Anonymous avatar Anonymous committed 285e40c

Refactored the tot() assignment.

Comments (0)

Files changed (3)

modules/Test-Shlomif-Harness/lib/Test/Shlomif/Harness/Obj.pm

     Verbose
     dir_files
     failed_tests
+    test_files
     tot
     width
 ));
 
 sub _get_simple_params
 {
-    return [qw(Debug Leaked_Dir Verbose)];
+    return
+        [qw(
+            Debug
+            Leaked_Dir
+            Verbose
+            test_files
+       )];
 }
 
 sub _init_simple_params
     local ($\, $,);
 
     my($failedtests) =
-        $self->_run_all_tests('test_files' => $args{'test_files'});
+        $self->_run_all_tests();
     $self->_show_results();
 
     my $ok = $self->_all_ok($self->tot());
 
 =item B<_run_all_tests>
 
-  my($total, $failed) = _run_all_tests(test_files => \@test_files);
+  my($total, $failed) = _run_all_tests();
 
-Runs all the given C<@test_files> (as C<runtests()>) but does it
+Runs all the test_files defined for the object but does it
 quietly (no report).  $total is a hash ref summary of all the tests
 run.  Its keys and values are this:
 
     $self->_recheck_dir_files();
 }
 
+sub _get_tot_counter_fields
+{
+    my $self = shift;
+    return [qw(bonus max ok files  bad  good sub_skipped todo skipped bench)];
+}
+
+sub _get_tot_counter_kv
+{
+    my $self = shift;
+    return [map { $_ => 0 } @{$self->_get_tot_counter_fields()}];
+}
+
+sub _get_tot_counter_tests
+{
+    my $self = shift;
+    return [tests => (scalar @{$self->test_files()})];
+}
+
+sub _init_tot
+{
+    my $self = shift;
+    # Test-wide totals.
+    $self->tot({
+            @{$self->_get_tot_counter_kv()},
+            @{$self->_get_tot_counter_tests()},
+            });
+}
+
 sub _run_all_tests {
     my $self = shift;
     my (%args) = @_;
 
-    my $tests = $args{'test_files'};
+    my $tests = $self->test_files();
 
     _autoflush(\*STDOUT);
     _autoflush(\*STDERR);
 
     $self->failed_tests({});
 
-    # Test-wide totals.
-    $self->tot({
-                bonus    => 0,
-                max      => 0,
-                ok       => 0,
-                files    => 0,
-                bad      => 0,
-                good     => 0,
-                tests    => (scalar @$tests),
-                sub_skipped  => 0,
-                todo     => 0,
-                skipped  => 0,
-                bench    => 0,
-            });
+    $self->_init_tot();
 
     $self->_init_dir_files();
     my $run_start_time = new Benchmark;

modules/Test-Shlomif-Harness/t/inc_taint.t

 
 tie *NULL, 'Dev::Null' or die $!;
 select NULL;
-my $obj = Test::Shlomif::Harness::Obj->new();
-my($failed) = $obj->_run_all_tests(
+my $obj = Test::Shlomif::Harness::Obj->new(    
     test_files =>
     [
            $ENV{PERL_CORE}
             : 't/sample-tests/inc_taint'
     ],
 );
+
+my($failed) = $obj->_run_all_tests();
 select STDOUT;
 
 # TEST

modules/Test-Shlomif-Harness/t/test-harness.t

     eval {
         select NULL;    # _run_all_tests() isn't as quiet as it should be.
         local $SIG{__WARN__} = sub { $warning .= join '', @_; };
-        $obj = Test::Shlomif::Harness::Obj->new();
+        $obj = Test::Shlomif::Harness::Obj->new(test_files => [$test_path]);
         ($failed) = 
-          $obj->_run_all_tests(test_files => [$test_path]);
+          $obj->_run_all_tests();
         $totals = $obj->tot();
     };
     select STDOUT;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.