xref: /openbsd-src/gnu/usr.bin/perl/cpan/Test-Simple/t/Legacy/utf8.t (revision 5759b3d249badf144a6240f7eec4dcf9df003e6b)
1#!/usr/bin/perl -w
2# HARNESS-NO-STREAM
3# HARNESS-NO-PRELOAD
4
5BEGIN {
6    if( $ENV{PERL_CORE} ) {
7        chdir 't';
8        @INC = '../lib';
9    }
10}
11
12use strict;
13use warnings;
14
15my $have_perlio;
16BEGIN {
17    # All together so Test::More sees the open discipline
18    $have_perlio = eval q[
19        require PerlIO;
20        PerlIO->VERSION(1.02); # required for PerlIO::get_layers
21        binmode *STDOUT, ":encoding(utf8)";
22        binmode *STDERR, ":encoding(utf8)";
23        require Test::More;
24        1;
25    ];
26}
27
28use Test::More;
29unless (Test::Builder->new->{Stack}->top->format->isa('Test::Builder::Formatter')) {
30    plan skip_all => 'Test cannot be run using this formatter';
31}
32
33if( !$have_perlio ) {
34    plan skip_all => "Don't have PerlIO 1.02";
35}
36else {
37    plan tests => 5;
38}
39
40SKIP: {
41    skip( "Need PerlIO for this feature", 3 )
42        unless $have_perlio;
43
44    my %handles = (
45        output          => \*STDOUT,
46        failure_output  => \*STDERR,
47        todo_output     => \*STDOUT
48    );
49
50    for my $method (keys %handles) {
51        my $src = $handles{$method};
52
53        my $dest = Test::More->builder->$method;
54
55        is_deeply { map { $_ => 1 } PerlIO::get_layers($dest) },
56                  { map { $_ => 1 } PerlIO::get_layers($src)  },
57                  "layers copied to $method";
58    }
59}
60
61
62# Test utf8 is ok.
63{
64    my $uni = "\x{11e}";
65
66    my @warnings;
67    local $SIG{__WARN__} = sub {
68        push @warnings, @_;
69    };
70
71    is( $uni, $uni, "Testing $uni" );
72    is_deeply( \@warnings, [] );
73}
74