Test::Harness and test values.

Discussion in 'Perl Misc' started by yusuf, Aug 7, 2006.

  1. yusuf

    yusuf Guest

    Heres a file t.pl:

    #!/usr/bin/perl



    use Test::Harness;
    $Test::Harness::Verbose=true;
    $|=1;
    print "before\n";



    my $allok = runtests("tests.pl");






    print " all ok? :" . $allok ." \n";



    print "total ran: ".$total;
    print "\nfailed: ".$failed;

    and the file tests.pl is:

    #!/usr/bin/perl
    use Test::More tests => 1;



    ok( $foo eq $bar, 'foo is bar' );



    print "hello owlrd!";



    print STDERR "hello err";
    ok( $foo eq $bar, 'foo is bar2' );
    1;

    My problem is that in t.pl, the print "before" gets printed, but not
    the other print statements after the runtests(). I want to be able to
    determine after a test run, how many tests passed, failed and errored.
    So I can log them to a server.

    Thanks.
     
    yusuf, Aug 7, 2006
    #1
    1. Advertising

  2. yusuf

    yusuf Guest

    Ok, heres a cleaned up verion of t.pl:

    #!/usr/bin/perl



    use strict;
    use warnings;



    use Test::Harness;



    $Test::Harness::Verbose=1;



    $|=1;



    print "before\n";



    my @a = ("t2.pl");
    my $allok = runtests(@a);



    print " all ok? :" . $allok ." \n";

    and t2.pl:

    #!/usr/bin/perl



    use strict;
    use warnings;



    use Test::More tests => 1;



    ok(1==2);



    1;

    The question is, why doesn't the print after the runtests() function
    print out?
     
    yusuf, Aug 8, 2006
    #2
    1. Advertising

  3. yusuf

    yusuf Guest


    > I really don't think it is acceptable to post code with obvious problems
    > (the kind that would have been solved by following the posting
    > guidelines). Bye.


    Where can I read up on the guidelines?
     
    yusuf, Aug 8, 2006
    #3
  4. yusuf

    yusuf Guest


    > Your program dies after running runtests. You can,
    > however, trap the exception with eval:
    >
    > my $all_ok;
    >
    > eval {
    > $all_ok = runtests( @test_programs );
    > };
    >
    > warn "Something bad happened : $@" if $@;
    >
    > # Go on to print:
    >
    > print "Onward\n";
    >
    > __END__
    >
    > You probably want to use the
    > 'prove' utility rather than
    > using Test::Harness directly:
    >
    > http://search.cpan.org/~petdance/Test-Harness-2.62/bin/prove


    Thanks, I'll try it out. Also, I looked into prove, the thing I need is
    that once the tests are run, I need to determine what the passed and''
    failed amounts are so that I can log them to a server. I looked through
    the docs for Test::Harness, but coudln't find anything. Is there a way
    to get that dta out of runtests()?
     
    yusuf, Aug 8, 2006
    #4
  5. yusuf

    yusuf Guest


    >
    > my $all_ok;
    >
    > eval {
    > $all_ok = runtests( @test_programs );
    > };
    >
    > warn "Something bad happened : $@" if $@;
    >
    > # Go on to print:
    >
    > print "Onward\n";
    >
    > __END__
    >
    > You probably want to use the
    > 'prove' utility rather than
    > using Test::Harness directly:


    I tried it, and it printed out everything fine. So I don't understand
    why it didn't print it out before the eval {}, since there doesn't seem
    to have been any errors.
     
    yusuf, Aug 9, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. fabbl

    Test Harness Strategies

    fabbl, Apr 17, 2004, in forum: VHDL
    Replies:
    1
    Views:
    1,056
    Jim Lewis
    Apr 17, 2004
  2. Todd
    Replies:
    0
    Views:
    328
  3. Troy Denkinger

    Test Harness?

    Troy Denkinger, Mar 9, 2006, in forum: Ruby
    Replies:
    10
    Views:
    240
    Troy Denkinger
    Mar 10, 2006
  4. yusuf
    Replies:
    2
    Views:
    140
    yusuf
    Aug 7, 2006
  5. Test harness for scripts?

    , May 16, 2007, in forum: Perl Misc
    Replies:
    1
    Views:
    111
    Sisyphus
    May 17, 2007
Loading...

Share This Page