File: bools.t

package info (click to toggle)
libtest-differences-perl 0.72-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 192 kB
  • sloc: perl: 498; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,862 bytes parent folder | download
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
55
use strict;
use warnings;

use lib 't/lib';
use Test::Differences::TestUtils::Capture;

use Test::More;
use Test::Differences;

use Data::Dumper;
# same options at Test::Differences guts use
$Data::Dumper::Deparse   = 1;
$Data::Dumper::Indent    = 1;
$Data::Dumper::Purity    = 0;
$Data::Dumper::Terse     = 1;
$Data::Dumper::Deepcopy  = 1;
$Data::Dumper::Quotekeys = 0;
$Data::Dumper::Useperl   = 1;
$Data::Dumper::Sortkeys  = 0;

my $stderr = capture_error { system (
    $^X, (map { "-I$_" } (@INC)),
    qw(-Mstrict -Mwarnings -MTest::More -MTest::Differences),
    '-e', '
        END { done_testing(); }
        eq_or_diff(1, !!1);
    '
) };

# check both perl version and D::D version - while 5.38 comes with a compatible
# Data::Dumper, the user might have an older version installed if their app's
# deps pin to an older version
if($] >= 5.038000 && $Data::Dumper::VERSION >= 2.188) {
    ok(1 == !!1, "sanity check: 1 and !!1 are numerically the same on this perl");
    ok(''.1 == ''.(!!1), "sanity check: 1 and !!1 stringify the same on this perl");
    isnt(Dumper(1), Dumper(!!1), "sanity check: 1 and !!1 are Data::Dumper-ly different on this perl");
    is($stderr,
'#   Failed test at -e line 3.
# +---+-----+----------+
# | Ln|Got  |Expected  |
# +---+-----+----------+
# *  1|1    |!!1       *
# +---+-----+----------+
# Looks like you failed 1 test of 1.
',
    "spotted that 1 and !! are different");
} else {
    ok(1 == !!1, "sanity check: 1 and !!1 are numerically the same on this perl");
    ok(''.1 == ''.(!!1), "sanity check: 1 and !!1 stringify the same on this perl");
    is(Dumper(1), Dumper(!!1), "sanity check: 1 and !!1 are Data::Dumper-ly the same on this perl");
    is($stderr, '', "got no error output for a boolean true vs 1 on Ye Olde Perls");
    eq_or_diff(1, !!1, 'say that 1 and !!1 are the same');
}

done_testing;