diff --git a/lib/Test2/API.pm b/lib/Test2/API.pm index 3f7b79b79..68d5dc676 100644 --- a/lib/Test2/API.pm +++ b/lib/Test2/API.pm @@ -3,7 +3,7 @@ use strict; use warnings; use Time::HiRes qw/time/; -use Test2::Util qw/USE_THREADS/; +use Test2::Util qw/USE_THREADS _env_get/; BEGIN { $ENV{TEST_ACTIVE} ||= 1; @@ -287,7 +287,8 @@ sub test2_ipc_get_timeout { $INST->ipc_timeout() } sub test2_ipc_enable_shm { 0 } sub test2_formatter { - if ($ENV{T2_FORMATTER} && $ENV{T2_FORMATTER} =~ m/^(\+)?(.*)$/) { + my $env_var = _env_get('T2_FORMATTER', ''); + if ($env_var =~ m/^(\+)?(.+)$/) { my $formatter = $1 ? $2 : "Test2::Formatter::$2"; my $file = pkg_to_file($formatter); require $file; diff --git a/lib/Test2/API/Instance.pm b/lib/Test2/API/Instance.pm index 39924fb3a..678366620 100644 --- a/lib/Test2/API/Instance.pm +++ b/lib/Test2/API/Instance.pm @@ -163,10 +163,10 @@ sub _finalize { unless ($self->{+FORMATTER}) { my ($formatter, $source); - if ($ENV{T2_FORMATTER}) { + if (my $env_val = _env_get('T2_FORMATTER')) { $source = "set by the 'T2_FORMATTER' environment variable"; - if ($ENV{T2_FORMATTER} =~ m/^(\+)?(.*)$/) { + if ($env_val =~ m/^(\+)?(.+)$/) { $formatter = $1 ? $2 : "Test2::Formatter::$2" } else { @@ -177,7 +177,8 @@ sub _finalize { ($formatter) = @{$self->{+FORMATTERS}}; $source = "Most recently added"; } - else { + + if (!$formatter) { $formatter = 'Test2::Formatter::TAP'; $source = 'default formatter'; }