Author: [email protected]
Date: Fri Feb  6 01:47:28 2009
New Revision: 683

Modified:
    trunk/HACKING
    trunk/t/   (props changed)
    trunk/t/lib/NYTProfTest.pm
    trunk/t/test01.t
    trunk/t/test02.t
    trunk/t/test03.t
    trunk/t/test05.t
    trunk/t/test06.t
    trunk/t/test07.t
    trunk/t/test08.t
    trunk/t/test09.t
    trunk/t/test10.t
    trunk/t/test11.t
    trunk/t/test12.t
    trunk/t/test13.t
    trunk/t/test14.t
    trunk/t/test16.t
    trunk/t/test20-streval.t
    trunk/t/test21-streval3.t
    trunk/t/test22-strevala.t
    trunk/t/test30-fork.0.t
    trunk/t/test40pmc.t
    trunk/t/test50-disable.t
    trunk/t/test51-enable.t
    trunk/t/test60-subname.t
    trunk/t/test61-submerge.t
    trunk/t/test70-subexcl.t
    trunk/t/test80-recurs.t

Log:
Remove no_plan from tests, allow additional tests (see example in  
t/test01.t)

Modified: trunk/HACKING
==============================================================================
--- trunk/HACKING       (original)
+++ trunk/HACKING       Fri Feb  6 01:47:28 2009
@@ -55,6 +55,24 @@
     time with a .x suffix: t/test##-description.x
     You still need to verify the .x.new file of course!

+4) Create a test script like this:
+
+     use strict;
+     use Test::More;
+     use lib qw(t/lib);
+     use NYTProfTest;
+
+     run_test_group;
+
+   You can add additional tests as parameters to run_test_group:
+
+     run_test_group(2 => sub {
+         my ($profile, $env) = @_;
+         is $profile->foo, 'bar', "...";
+         is $profile->baz, 'bax', "...";
+     });
+
+
  Note:  While writing a test, it is helpful to be able to run it directly,
  without the test harness.  This allows you to view more output stdout and
  stderr.  Fortunately, its easy to do:
@@ -94,15 +112,6 @@
  ----

  *** For build/test
-
-Refactor the subs in t/20.runtests.t into a library of subs in a
-t/lib/NYTProfTest.pm module. We should aim to be able to write new tests as
-traditional t/*.t files that use NYTProfTest and call the subs to do the  
work.
-This will free us from the constraints imposed by the current harness.
-Specifically there's no way to directly test the data model methods.
-Once refactored we'd be able to simply add
-       is $profile->foo, bar, 'foo should be bar';
-to the .t file.

  Add (very) basic nytprofhtml test (ie it runs and produces output)


Modified: trunk/t/lib/NYTProfTest.pm
==============================================================================
--- trunk/t/lib/NYTProfTest.pm  (original)
+++ trunk/t/lib/NYTProfTest.pm  Fri Feb  6 01:47:28 2009
@@ -16,6 +16,11 @@
  use Devel::NYTProf::Util qw(strip_prefix_from_paths);


+my $profile_datafile = 'nytprof_t.out';     # non-default to test override  
works
+
+my $tests_per_extn = {p => 1, rdt => 1, x => 3};
+
+
  my %opts = (
      profperlopts => '-d:NYTProf',
      html         => $ENV{NYTPROF_TEST_HTML},
@@ -23,15 +28,9 @@
  GetOptions(\%opts, qw/p=s I=s v|verbose d|debug html open profperlopts=s  
leave=i use_db_sub=i/)
      or exit 1;

-$opts{v} ||= $opts{d};
+$opts{v}    ||= $opts{d};
  $opts{html} ||= $opts{open};

-my $opt_perl         = $opts{p};
-my $opt_include      = $opts{I};
-my $opt_leave        = $opts{leave};
-my $opt_use_db_sub   = $opts{use_db_sub};
-my $profile_datafile = 'nytprof_t.out';     # non-default to test override  
works
-
  # note some env vars that might impact the tests
  $ENV{$_} && warn "$_=$ENV{$_}\n" for qw(PERL5DB PERL5OPT PERL_UNICODE  
PERLIO);

@@ -48,9 +47,6 @@

  chdir('t') if -d 't';

-my $tests_per_extn = {p => 1, rdt => 1, x => 3};
-
-my $path_sep = $Config{path_sep} || ':';
  if (-d '../blib') {
      unshift @INC, '../blib/arch', '../blib/lib';
  }
@@ -58,14 +54,15 @@
  my $nytprofcsv  = "$bindir/nytprofcsv";
  my $nytprofhtml = "$bindir/nytprofhtml";

-my $perl5lib = $opt_include || join($path_sep, @INC);
-my $perl     = $opt_perl    || $^X;
+my $path_sep = $Config{path_sep} || ':';
+my $perl5lib = $opts{I} || join($path_sep, @INC);
+my $perl     = $opts{p} || $^X;

  # turn ./perl into ../perl, because of chdir(t) above.
  $perl = ".$perl" if $perl =~ m|^\./|;

-my @test_opt_leave      = (defined $opt_leave)      ? ($opt_leave)      :  
(1, 0);
-my @test_opt_use_db_sub = (defined $opt_use_db_sub) ? ($opt_use_db_sub) :  
(0, 1);
+my @test_opt_leave      = (defined $opts{leave})      ?  
($opts{leave})      : (1, 0);
+my @test_opt_use_db_sub = (defined $opts{use_db_sub}) ?  
($opts{use_db_sub}) : (0, 1);

  # build @env_combinations
  my @env_combinations;
@@ -81,19 +78,21 @@


  sub run_test_group {
-    my ($group) = @_;
+    my ($test_count, $test_code) = @_;

-    unless ($group) {
-        # obtain group from file name
-        my $file = (caller)[1];
-        if ($file =~ /([^\/\\]+)\.t$/) {
-            $group = $1;
-        } else {
-            croak "Can't determine test group";
-        }
+    # no warnings "undefined value";
+    $test_count ||= 0;
+    $test_count = 0 unless $test_code;
+
+    # obtain group from file name
+    my $group;
+    if ((caller)[1] =~ /([^\/\\]+)\.t$/) {
+        $group = $1;
+    } else {
+        croak "Can't determine test group";
      }

-    my @tests = grep { -f $_ } map { join('.', $group, $_) }  
keys %$tests_per_extn;
+    my @tests = grep { -f $_ } map { join('.', $group, $_) } sort  
keys %$tests_per_extn;

      if ($opts{v}) {
          print "tests: @tests\n";
@@ -102,6 +101,10 @@
          print "nytprofcvs: $nytprofcsv\n";
      }

+    my $tests_per_env = number_of_tests(@tests) + $test_count;
+
+    plan tests => 1 + $tests_per_env * @env_combinations;
+
      # Windows emulates the executable bit based on file extension only
      ok($^O eq "MSWin32" ? -f $nytprofcsv : -x $nytprofcsv, "Found  
nytprofcsv as $nytprofcsv");

@@ -109,11 +112,22 @@
          for my $test (@tests) {
              run_test_with_env($test, $env);
          }
+
+        if ($test_code) {
+            my $profile = eval { Devel::NYTProf::Data->new({filename =>  
$profile_datafile}) };
+            if ($@) {
+                diag($@);
+                fail("extra tests group '$group'") foreach (1 ..  
$test_count);
+                return;
+            }
+
+            $test_code->($profile, $env);
+        }
      }
  }

  sub run_test_with_env {
-    my ($test, $env) = @_;
+    my ($test, $env, $test_code) = @_;

      my %env = (%$env, %NYTPROF_TEST);
      local $ENV{NYTPROF} = join ":", map {"$_=$env{$_}"} sort keys %env;

Modified: trunk/t/test01.t
==============================================================================
--- trunk/t/test01.t    (original)
+++ trunk/t/test01.t    Fri Feb  6 01:47:28 2009
@@ -1,6 +1,9 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;

-run_test_group;
+run_test_group(1 => sub {
+                   my ($profile, $env) = @_;
+                   isa_ok($profile, 'Devel::NYTProf::Data');
+               });

Modified: trunk/t/test02.t
==============================================================================
--- trunk/t/test02.t    (original)
+++ trunk/t/test02.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test03.t
==============================================================================
--- trunk/t/test03.t    (original)
+++ trunk/t/test03.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test05.t
==============================================================================
--- trunk/t/test05.t    (original)
+++ trunk/t/test05.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test06.t
==============================================================================
--- trunk/t/test06.t    (original)
+++ trunk/t/test06.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test07.t
==============================================================================
--- trunk/t/test07.t    (original)
+++ trunk/t/test07.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test08.t
==============================================================================
--- trunk/t/test08.t    (original)
+++ trunk/t/test08.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test09.t
==============================================================================
--- trunk/t/test09.t    (original)
+++ trunk/t/test09.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test10.t
==============================================================================
--- trunk/t/test10.t    (original)
+++ trunk/t/test10.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test11.t
==============================================================================
--- trunk/t/test11.t    (original)
+++ trunk/t/test11.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test12.t
==============================================================================
--- trunk/t/test12.t    (original)
+++ trunk/t/test12.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test13.t
==============================================================================
--- trunk/t/test13.t    (original)
+++ trunk/t/test13.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test14.t
==============================================================================
--- trunk/t/test14.t    (original)
+++ trunk/t/test14.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test16.t
==============================================================================
--- trunk/t/test16.t    (original)
+++ trunk/t/test16.t    Fri Feb  6 01:47:28 2009
@@ -4,6 +4,5 @@
  use NYTProfTest;

  plan skip_all => "needs perl >= 5.10" unless $] >= 5.010;
-plan 'no_plan';

  run_test_group;

Modified: trunk/t/test20-streval.t
==============================================================================
--- trunk/t/test20-streval.t    (original)
+++ trunk/t/test20-streval.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test21-streval3.t
==============================================================================
--- trunk/t/test21-streval3.t   (original)
+++ trunk/t/test21-streval3.t   Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test22-strevala.t
==============================================================================
--- trunk/t/test22-strevala.t   (original)
+++ trunk/t/test22-strevala.t   Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test30-fork.0.t
==============================================================================
--- trunk/t/test30-fork.0.t     (original)
+++ trunk/t/test30-fork.0.t     Fri Feb  6 01:47:28 2009
@@ -4,6 +4,5 @@
  use NYTProfTest;

  plan skip_all => "doesn't work with fork() emulation" if $^O eq "MSWin32";
-plan 'no_plan';

  run_test_group;

Modified: trunk/t/test40pmc.t
==============================================================================
--- trunk/t/test40pmc.t (original)
+++ trunk/t/test40pmc.t Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test50-disable.t
==============================================================================
--- trunk/t/test50-disable.t    (original)
+++ trunk/t/test50-disable.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test51-enable.t
==============================================================================
--- trunk/t/test51-enable.t     (original)
+++ trunk/t/test51-enable.t     Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test60-subname.t
==============================================================================
--- trunk/t/test60-subname.t    (original)
+++ trunk/t/test60-subname.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test61-submerge.t
==============================================================================
--- trunk/t/test61-submerge.t   (original)
+++ trunk/t/test61-submerge.t   Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test70-subexcl.t
==============================================================================
--- trunk/t/test70-subexcl.t    (original)
+++ trunk/t/test70-subexcl.t    Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


Modified: trunk/t/test80-recurs.t
==============================================================================
--- trunk/t/test80-recurs.t     (original)
+++ trunk/t/test80-recurs.t     Fri Feb  6 01:47:28 2009
@@ -1,5 +1,5 @@
  use strict;
-use Test::More qw(no_plan);
+use Test::More;
  use lib qw(t/lib);
  use NYTProfTest;


--~--~---------~--~----~------------~-------~--~----~
You've received this message because you are subscribed to
the Devel::NYTProf Development User group.

Group hosted at:  http://groups.google.com/group/develnytprof-dev
Project hosted at:  http://perl-devel-nytprof.googlecode.com
CPAN distribution:  http://search.cpan.org/dist/Devel-NYTProf

To post, email:  [email protected]
To unsubscribe, email:  [email protected]
-~----------~----~----~----~------~----~------~--~---

Reply via email to