Skip to content

Commit

Permalink
Merge b903360 into 7e73c53
Browse files Browse the repository at this point in the history
  • Loading branch information
bayashi committed Feb 21, 2020
2 parents 7e73c53 + b903360 commit 78d6870
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 0 deletions.
22 changes: 22 additions & 0 deletions lib/Test/Arrow.pm
Expand Up @@ -11,6 +11,19 @@ our @ISA = qw/Test::Builder::Module/;

my $CLASS = __PACKAGE__;

sub import {
my $pkg = shift;
my %args = map { $_ => 1 } @_;

my $binary = delete $args{binary} or delete $args{binary_mode}
or delete $args{not_utf8} or delete $args{'-utf8'} or delete $args{'-utf'};
if (!$binary) {
binmode $pkg->builder->$_, ':utf8' for qw(failure_output todo_output output);
require utf8;
utf8->import;
}
}

sub new {
bless {}, shift;
}
Expand Down Expand Up @@ -241,6 +254,15 @@ The opposite DSL.
B<Test::Arrow> is a testing helper as object-oriented operation. Perl5 has a lot of testing libraries. These libraries have nice DSL ways. However, sometimes we hope the Object as similar to ORM. It may slightly sound strange. But it'd be better to clarify operations and it's easy to understand what/how it is. Although there are so many arrows.
=head1 IMPORT OPTIONS
=head2 binary
By default, C<Test::Arrow> sets utf8 pragma globally to avoid warnings such as "Wide charactors". If you don't want it, then you should pass 'binary' option on use.
use Test::Arrow 'binary'; # utf8 pragma off
=head1 METHODS
=head3 new
Expand Down
28 changes: 28 additions & 0 deletions t/02_utf8.t
@@ -0,0 +1,28 @@
# Inspired by Test::More::UTF8
use strict;
use warnings;

use Test::Arrow; # Turn on utf8 pragma.

my $arr = Test::Arrow->new;

$arr->ok(utf8::is_utf8("а"));

my $sym = "\x{410}";

my @warns;

local $SIG{__WARN__} = sub { push @warns, shift; };

{
Test::Arrow->builder->failure_output->print("# $sym\n");
$arr->ok(!@warns, 'failure_output') or $arr->diag('Have warning: ' . shift @warns);

Test::Arrow->builder->todo_output->print("# $sym\n");
$arr->ok(!@warns, 'todo_output') or $arr->diag('Have warning: ' . shift @warns);

Test::Arrow->builder->output->print("# $sym\n");
$arr->ok(!@warns, 'output') or $arr->diag('Have warning: ' . shift @warns);
}

$arr->done_testing;
38 changes: 38 additions & 0 deletions t/03_binary.t
@@ -0,0 +1,38 @@
# Inspired by Test::More::UTF8
use strict;
use warnings;

use Test::Arrow 'binary'; # Turn off utf8 pragma.

my $arr = Test::Arrow->new;

$arr->ok(!utf8::is_utf8("а"));

my $sym = "\x{430}";

my @warns;

local $SIG{__WARN__} = sub { push @warns, shift; };

{
@warns = ();
Test::Arrow->builder->failure_output->print("# $sym\n");
$arr->ok(scalar @warns == 1, 'failure_output is not utf8')
or $arr->diag('Have warning: ' . shift @warns);
}

{
@warns = ();
Test::Arrow->builder->todo_output->print("# $sym\n");
$arr->ok(scalar @warns == 1, 'todo_output is not utf8')
or $arr->diag('Have warning: ' . shift @warns);
}

{
@warns = ();
Test::Arrow->builder->output->print("# $sym\n");
$arr->ok(scalar @warns == 1, 'output is not utf8')
or $arr->diag('Have warning: ' . shift @warns);
}

$arr->done_testing;

0 comments on commit 78d6870

Please sign in to comment.