| 1 |
use utf8; |
| 2 |
use strict; |
| 3 |
use warnings; |
| 4 |
use Test::More; |
| 5 |
use Test2::Plugin::UTF8; |
| 6 |
use Test2::API qw/test2_stack/; |
| 7 |
use Test2::Harness::Util::JSON qw/decode_json/; |
| 8 |
use Test2::Tools::Basic qw/skip_all/; |
| 9 |
use File::Spec; |
| 10 |
use Test2::Util qw/get_tid ipc_separator/; |
| 11 |
# HARNESS-DURATION-SHORT |
| 12 |
# HARNESS-NO-IO-EVENTS |
| 13 |
|
| 14 |
test2_stack()->top; |
| 15 |
my ($hub) = test2_stack()->all(); |
| 16 |
my $fmt = $hub->format; |
| 17 |
skip_all "This test requires the stream formatter" |
| 18 |
unless $fmt && $fmt->isa('Test2::Formatter::Stream'); |
| 19 |
|
| 20 |
print STDOUT "STDOUT: Mākaha\n"; |
| 21 |
note "NOTE: Mākaha"; |
| 22 |
ok(1, "ASSERT: Mākaha"); |
| 23 |
|
| 24 |
my $file = File::Spec->catfile($fmt->dir, join(ipc_separator() => 'events', $$, 0) . ".jsonl"); |
| 25 |
open(my $events_fh, '<:utf8', $file) or die "Could not open events file: $!"; |
| 26 |
open(my $stdout_fh, '<:utf8', File::Spec->catfile($ENV{TEST2_JOB_DIR}, 'stdout')) or die "Could not open STDOUT for reading: $!"; |
| 27 |
|
| 28 |
my @events = map { decode_json($_) } grep m/(NOTE|DIAG|ASSERT): /, <$events_fh>; |
| 29 |
my ($stdout) = grep m/STDOUT: /, <$stdout_fh>; |
| 30 |
|
| 31 |
is($stdout, "STDOUT: Mākaha\n", "Round trip STDOUT encoding/decoding"); |
| 32 |
|
| 33 |
is($events[0]->{facet_data}->{info}->[0]->{details}, "NOTE: Mākaha", "Round trip encoding/decoding a note"); |
| 34 |
is($events[1]->{facet_data}->{assert}->{details}, "ASSERT: Mākaha", "Round trip encoding/decoding an assert"); |
| 35 |
|
| 36 |
done_testing; |