Test::Harness and test values.

Y

yusuf

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.
 
Y

yusuf

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?
 
Y

yusuf

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?
 
Y

yusuf

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()?
 
Y

yusuf

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top