Commit | Line | Data |
6b38a9b9 |
1 | #!/usr/bin/perl -w |
2 | |
3 | BEGIN { |
4 | if( $ENV{PERL_CORE} ) { |
5 | chdir 't'; |
eaa08151 |
6 | @INC = ('../lib', 'lib', '../lib/Test/Simple/t/lib'); |
6b38a9b9 |
7 | } |
8 | else { |
9 | unshift @INC, 't/lib'; |
10 | } |
11 | } |
12 | |
13 | use strict; |
14 | |
15 | require Test::Simple::Catch; |
16 | my($out, $err) = Test::Simple::Catch::caught(); |
17 | local $ENV{HARNESS_ACTIVE} = 0; |
18 | |
19 | require Test::Builder; |
20 | my $TB = Test::Builder->create; |
21 | $TB->level(0); |
22 | |
23 | sub try_cmp_ok { |
24 | my($left, $cmp, $right) = @_; |
25 | |
26 | my %expect; |
27 | $expect{ok} = eval "\$left $cmp \$right"; |
28 | $expect{error} = $@; |
29 | $expect{error} =~ s/ at .*\n?//; |
30 | |
31 | local $Test::Builder::Level = $Test::Builder::Level + 1; |
82d700dc |
32 | my $ok = cmp_ok($left, $cmp, $right, "cmp_ok"); |
33 | $TB->is_num(!!$ok, !!$expect{ok}, " right return"); |
6b38a9b9 |
34 | |
35 | my $diag = $err->read; |
36 | if( !$ok and $expect{error} ) { |
37 | $diag =~ s/^# //mg; |
82d700dc |
38 | $TB->like( $diag, qr/\Q$expect{error}\E/, " expected error" ); |
6b38a9b9 |
39 | } |
40 | elsif( $ok ) { |
82d700dc |
41 | $TB->is_eq( $diag, '', " passed without diagnostic" ); |
6b38a9b9 |
42 | } |
43 | else { |
82d700dc |
44 | $TB->ok(1, " failed without diagnostic"); |
6b38a9b9 |
45 | } |
46 | } |
47 | |
48 | |
49 | use Test::More; |
50 | Test::More->builder->no_ending(1); |
51 | |
82d700dc |
52 | require MyOverload; |
53 | my $cmp = Overloaded::Compare->new("foo", 42); |
54 | my $ify = Overloaded::Ify->new("bar", 23); |
55 | |
6b38a9b9 |
56 | my @Tests = ( |
57 | [1, '==', 1], |
58 | [1, '==', 2], |
59 | ["a", "eq", "b"], |
60 | ["a", "eq", "a"], |
61 | [1, "+", 1], |
62 | [1, "-", 1], |
6b38a9b9 |
63 | |
82d700dc |
64 | [$cmp, '==', 42], |
65 | [$cmp, 'eq', "foo"], |
66 | [$ify, 'eq', "bar"], |
67 | [$ify, "==", 23], |
68 | ); |
6b38a9b9 |
69 | |
70 | plan tests => scalar @Tests; |
71 | $TB->plan(tests => @Tests * 2); |
72 | |
73 | for my $test (@Tests) { |
74 | try_cmp_ok(@$test); |
75 | } |