Search code examples
perltestingstderrmojolicious

Why *STDERR in this perl test is empty?


I have the following chunk of code copied from Mojolicious (mojo/log.t). The application which I am testing does $app->log->warn('whatever');. Unfortunately when I run the test as part of make test, STDERR happens to be empty. When I run it with prove -lv t/basic.t it succeeds. What's wrong with my program. Full source code of the tested program is here Thank you!

my $buffer = '';
{
  open my $handle, '>', \$buffer;
  local *STDERR = $handle;
  require Blog;
  my $blog = Blog->new;
  $blog->startup();
}
like $buffer, qr/"routes" key must point to an ARRAY/,
  'right warning about ARRAY reference';

Solution

  • [Edited] You may need to set the environment variable MOJO_LOG_LEVEL to warn. The way Mojo checks the level of logging is such that $ENV{MOJO_LOG_LEVEL} (fatal by default if using Test::Mojo) has the priority over the level set in the app.

    I used version 7.59 of Mojolicious to check these things.