Upgrade to Test-Simple-0.82.
[p5sagit/p5-mst-13.2.git] / lib / Test / Simple / t / cmp_ok.t
CommitLineData
6b38a9b9 1#!/usr/bin/perl -w
ccbd73a4 2# $Id: /mirror/googlecode/test-more/t/cmp_ok.t 57943 2008-08-18T02:09:22.275428Z brooklyn.kid51 $
6b38a9b9 3
4BEGIN {
5 if( $ENV{PERL_CORE} ) {
6 chdir 't';
7 @INC = ('../lib', 'lib');
8 }
9 else {
10 unshift @INC, 't/lib';
11 }
12}
13
14use strict;
15
16require Test::Simple::Catch;
17my($out, $err) = Test::Simple::Catch::caught();
18local $ENV{HARNESS_ACTIVE} = 0;
19
20require Test::Builder;
21my $TB = Test::Builder->create;
22$TB->level(0);
23
24sub try_cmp_ok {
25 my($left, $cmp, $right) = @_;
26
27 my %expect;
28 $expect{ok} = eval "\$left $cmp \$right";
29 $expect{error} = $@;
30 $expect{error} =~ s/ at .*\n?//;
31
32 local $Test::Builder::Level = $Test::Builder::Level + 1;
33 my $ok = cmp_ok($left, $cmp, $right);
34 $TB->is_num(!!$ok, !!$expect{ok});
35
36 my $diag = $err->read;
37 if( !$ok and $expect{error} ) {
38 $diag =~ s/^# //mg;
39 $TB->like( $diag, "/\Q$expect{error}\E/" );
40 }
41 elsif( $ok ) {
42 $TB->is_eq( $diag, '' );
43 }
44 else {
45 $TB->ok(1);
46 }
47}
48
49
50use Test::More;
51Test::More->builder->no_ending(1);
52
53my @Tests = (
54 [1, '==', 1],
55 [1, '==', 2],
56 ["a", "eq", "b"],
57 ["a", "eq", "a"],
58 [1, "+", 1],
59 [1, "-", 1],
60);
61
62# These don't work yet.
63if( 0 ) {
64#if( eval { require overload } ) {
65 require MyOverload;
66
67 my $cmp = Overloaded::Compare->new("foo", 42);
68 my $ify = Overloaded::Ify->new("bar", 23);
69
70 push @Tests, (
71 [$cmp, '==', 42],
72 [$cmp, 'eq', "foo"],
73 [$ify, 'eq', "bar"],
74 [$ify, "==", 23],
75 );
76}
77
78plan tests => scalar @Tests;
79$TB->plan(tests => @Tests * 2);
80
81for my $test (@Tests) {
82 try_cmp_ok(@$test);
83}