Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Test-Simple CPAN distribution.

Report information
The Basics
Id: 21246
Status: resolved
Priority: 0/
Queue: Test-Simple

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: test in isolation for testing tests
When testing a test module one often wants to test failure. Trouble is you don't want this failure to be visible to the outside world (ie. cause the test to fail). Normally one does something awkward like: sub test_in_isolation { my $code = shift; my $output = $tb->output; my $failure_output = $tb->failure_output; my $todo_output = $tb->todo_output; my $current_test = $tb->current_test; my $tb = Test::Builder->builder; $tb->output( File::Spec->devnull ); $tb->failure_output( File::Spec->devnull ); $tb->todo_output( File::Spec->devnull ); my $result = $code->(); $tb->output($output); $tb->failure_output($failure_output); $tb->todo_output($todo_output); $tb->current_test($current_test); return $result; } ie. save the state of Test::Builder, do your evil, then reset it. It would be nice if TB did this for you, perhaps with named checkpoints. $tb->save_checkpoint("foo"); $tb->output( File::Spec->devnull ); $tb->failure_output( File::Spec->devnull ); $tb->todo_output( File::Spec->devnull ); fail("wibble"); $tb->restore_checkpoint("foo"); This is still a bit awkward. Perhaps a 'testing mode' would be handy which somehow returns the output streams and test result details while restoring the state of the test. my %results = $tb->test_in_isolation sub { fail("wibble"); }; print $results{output}; # capture from TB->output print $results{details}[0]{name}; # as TB->details print $results{summary}[0]; # as TB->summary
On Wed Aug 30 13:27:45 2006, MSCHWERN wrote: Show quoted text
> When testing a test module one often wants to test failure. Trouble is > you don't want this failure to be visible to the outside world (ie. > cause the test to fail). > > Normally one does something awkward like: > > > sub test_in_isolation { > my $code = shift; > > my $output = $tb->output; > my $failure_output = $tb->failure_output; > my $todo_output = $tb->todo_output; > my $current_test = $tb->current_test; > > my $tb = Test::Builder->builder; > $tb->output( File::Spec->devnull ); > $tb->failure_output( File::Spec->devnull ); > $tb->todo_output( File::Spec->devnull ); > > my $result = $code->(); > > $tb->output($output); > $tb->failure_output($failure_output); > $tb->todo_output($todo_output); > $tb->current_test($current_test); > > return $result; > } > > ie. save the state of Test::Builder, do your evil, then reset it. It > would be nice if TB did this for you, perhaps with named checkpoints. > > $tb->save_checkpoint("foo"); > $tb->output( File::Spec->devnull ); > $tb->failure_output( File::Spec->devnull ); > $tb->todo_output( File::Spec->devnull ); > fail("wibble"); > $tb->restore_checkpoint("foo"); > > This is still a bit awkward. Perhaps a 'testing mode' would be handy > which somehow returns the output streams and test result details while > restoring the state of the test. > > my %results = $tb->test_in_isolation sub { > fail("wibble"); > }; > > print $results{output}; # capture from TB->output > print $results{details}[0]{name}; # as TB->details > print $results{summary}[0]; # as TB->summary
Test2's intercept { ... } solves this problem.