Remove broken links for hip communications inc.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / cmp_ok.t
1 #!/usr/bin/perl -w
2
3 BEGIN {
4     if( $ENV{PERL_CORE} ) {
5         chdir 't';
6         @INC = ('../lib', 'lib', '../lib/Test/Simple/t/lib');
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;
32     my $ok = cmp_ok($left, $cmp, $right, "cmp_ok");
33     $TB->is_num(!!$ok, !!$expect{ok}, "  right return");
34     
35     my $diag = $err->read;
36     if( !$ok and $expect{error} ) {
37         $diag =~ s/^# //mg;
38         $TB->like( $diag, qr/\Q$expect{error}\E/, "  expected error" );
39     }
40     elsif( $ok ) {
41         $TB->is_eq( $diag, '', "  passed without diagnostic" );
42     }
43     else {
44         $TB->ok(1, "  failed without diagnostic");
45     }
46 }
47
48
49 use Test::More;
50 Test::More->builder->no_ending(1);
51
52 require MyOverload;
53 my $cmp = Overloaded::Compare->new("foo", 42);
54 my $ify = Overloaded::Ify->new("bar", 23);
55
56 my @Tests = (
57     [1, '==', 1],
58     [1, '==', 2],
59     ["a", "eq", "b"],
60     ["a", "eq", "a"],
61     [1, "+", 1],
62     [1, "-", 1],
63
64     [$cmp, '==', 42],
65     [$cmp, 'eq', "foo"],
66     [$ify, 'eq', "bar"],
67     [$ify, "==", 23],
68 );
69
70 plan tests => scalar @Tests;
71 $TB->plan(tests => @Tests * 2);
72
73 for my $test (@Tests) {
74     try_cmp_ok(@$test);
75 }