On Mar 15, 2005, at 6:45 AM, Nathan Gray wrote:
I think it would be really nice for failed, todo, and skipped tests to log their $expected and $got values, with any $desc or $context information to a log file (probably test.log).
I also think it would be very nice to be able to use other operators, such as gt, lt, or isa.
is($got, $expected, $desc, operator => 'gt');
Personally, I think a more familiar form, like Test::More::cmp_ok would be better.
cmp_ok($got, 'gt', $expected, $desc);
It should be easy enough to implement.
- Stevan
Or something like that.
Anyway, I was just trying to implement logging to a file, first. But I keep running into errors. At this point, I don't know if it is my bad perl6 or pugs sand pits.
This is the error I am getting:
$ pugs -c ext/Test/lib/Test.pm
*** Error:
unexpected "s"
expecting adverb, term postfix, operator, postfix conditional, ternary conditional, ";", "}" or end of input
at ext/Test/lib/Test.pm at line 105, column 1
A gentle prod in the right direction would be appreciated. The line 105 refers to the 'sub write_log' line.
This is what I'm trying to add to Test.pm:
my $log_file = '';
sub log_file (Str $filename) returns Str is export { $log_file = $filename; return $log_file; }
sub write_log (+$got, +$expected, Str +$desc, Str +$errstr, Str +$context, Str +$operator = 'eq') returns Bool {
# return 0 but true unless $log_file; # not yet implemented
return 1 unless $log_file;
# until we have 'given'/'when'
my $status = 'FAILED';
if (index($?CALLER::CALLER::SUBNAME, 'todo') >= 0) {
$status = 'TODO';
} elsif (index($?CALLER::CALLER::SUBNAME, 'skip') >= 0) {
$status = 'SKIPPED';
}
if (my $out = open(">>$log_file")) {
$out.say $?CALLER::CALLER::FILE ~ " $loop $status";
$out.say $desc if $desc;
$out.say $errstr if $errstr;
$out.say $context if $context;
$out.say '### Expected ###';
$out.say $expected;
$out.say '### Actual Results ###';
$out.say $got, "\n";
$out.close;
return 1;
}
return 0;
}
Thank you,
-kolibrie