While writing tests for some of my code, I was faced with the issue of capturing what the code sends to STDOUT and STDERR. As I have not found a module to make it easy, I wrote a trivial code to do it. It is used like this:

        use Test::More tests => 2;
        use Seize qw(seize release);

my ($out, $err);

seize \$out, \$err; # from here on, STDOUT and STDERR are seized

        print "1\n";
        warn "2\n";
        print "3\n";
        eval { die "4\n"; }

release; # here STDOUT and STDERR are released

        is($out, "1\n3\n");
        is($err, "2\n3\n");


My doubt is if this deserves a module: maybe it would be better to use idioms commonly employed to this kind of task. Maybe there is some module I am overlooking that already does that.

If it is worthy, there's a bunch of things I would appreciate some
feedback on:
* does it make sense the use of 'seize' and 'release' as above
  (I am not an English native speaker and I am not sure).
* What would be a sensible name: IO::Seize, Test::Stdout?
* It is necessary that I understand better the interaction of the
  code being tested and how Test:: modules and Test::Harness works
* It would be better to make it a real Test:: module?




-- Adriano

Reply via email to