1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
use Test2::Bundle::Extended -target => 'Test2::Tools::Encoding';
require Test2::Formatter::TAP;
use File::Temp qw/tempfile/;
{
package Temp;
use Test2::Tools::Encoding;
main::imported_ok(qw/set_encoding/);
}
my $warnings;
intercept {
$warnings = warns {
use utf8;
my ($fh, $name);
my $ct = 100;
until ($fh) {
--$ct or die "Failed to get temp file after 100 tries";
($fh, $name) = eval { tempfile() };
}
Test2::API::test2_stack->top->format(
Test2::Formatter::TAP->new(
handles => [$fh, $fh, $fh],
),
);
set_encoding('utf8');
ok(1, '†');
unlink($name) or print STDERR "Could not remove temp file $name: $!\n";
};
};
ok(!$warnings, "set_encoding worked");
my $exception;
intercept {
$exception = dies {
set_encoding('utf8');
};
};
like(
$exception,
qr/Unable to set encoding on formatter '<undef>'/,
"Cannot set encoding without a formatter"
);
done_testing;
|