]> git.vpit.fr Git - perl/modules/Test-Leaner.git/blob - t/02-fallback.t
Fall back to Test::More when PERL_TEST_LEANER_USES_TEST_MORE is set
[perl/modules/Test-Leaner.git] / t / 02-fallback.t
1 #!perl -T
2
3 use strict;
4 use warnings;
5
6 BEGIN { $ENV{PERL_TEST_LEANER_USES_TEST_MORE} = 1 }
7
8 use Test::Leaner;
9
10 BEGIN {
11  my $loaded;
12  if ($INC{'Test/More.pm'}) {
13   $loaded = 1;
14  } else {
15   $loaded = 0;
16   require Test::More;
17   Test::More->import;
18  }
19  Test::More::plan(tests => 1 + 4 * 15 + 3 * 3 + 2 * 8);
20  Test::More::is($loaded, 1, 'Test::More has been loaded');
21 }
22
23 sub get_subroutine {
24  my ($stash, $name) = @_;
25
26  my $glob = $stash->{$name};
27  return undef unless $glob;
28
29  return *$glob{CODE};
30 }
31
32 my $leaner_stash = \%Test::Leaner::;
33 my $more_stash   = \%Test::More::;
34 my $this_stash   = \%main::;
35
36 my @exported = qw<
37  plan
38  skip
39  done_testing
40  pass
41  fail
42  ok
43  is
44  isnt
45  like
46  unlike
47  cmp_ok
48  is_deeply
49  diag
50  note
51  BAIL_OUT
52 >;
53
54 for (@exported) {
55  my $more_variant     = get_subroutine($more_stash, $_);
56
57  my $leaner_variant   = get_subroutine($leaner_stash, $_);
58  Test::More::ok(defined $leaner_variant,
59                                        "Test::Leaner variant of $_ is defined");
60  my $imported_variant = get_subroutine($this_stash, $_);
61  Test::More::ok(defined $imported_variant, "imported variant of $_ is defined");
62
63  SKIP: {
64   Test::More::skip('Need leaner and imported variants to be defined' => 2)
65                    unless defined $leaner_variant
66                       and defined $imported_variant;
67
68   if (defined $more_variant) {
69    Test::More::is($leaner_variant, $more_variant,
70                   "Test::Leaner variant of $_ is Test::More variant");
71    Test::More::is($imported_variant, $more_variant,
72                   "imported variant of $_ is Test::More variant");
73   } else {
74    Test::More::is($imported_variant, $leaner_variant,
75                   "imported variant of $_ is Test::Leaner variant");
76    {
77     local $@;
78     eval { $leaner_variant->() };
79     Test::More::like($@, qr/^\Q$_\E is not implemented.*at \Q$0\E line \d+/,
80                          "Test::Leaner of $_ variant croaks");
81    }
82   }
83  }
84 }
85
86 my @only_in_test_leaner = qw<
87  tap_stream
88  diag_stream
89  THREADSAFE
90 >;
91
92 for (@only_in_test_leaner) {
93  Test::More::ok(exists $leaner_stash->{$_},
94                 "$_ still exists in Test::Leaner");
95  Test::More::ok(!exists $more_stash->{$_},
96                 "$_ was not imported into Test::More");
97  Test::More::ok(!exists $this_stash->{$_},
98                 "$_ was not imported into main");
99 }
100
101 my @only_in_test_more = qw<
102  use_ok
103  require_ok
104  can_ok
105  isa_ok
106  new_ok
107  subtest
108  explain
109  todo_skip
110 >;
111
112 for (@only_in_test_more) {
113  my $more_variant = get_subroutine($more_stash, $_);
114
115  SKIP: {
116   Test::More::skip("$_ is not implemented in this version of Test::More" => 2)
117                    unless defined $more_variant;
118
119   Test::More::ok(!exists $leaner_stash->{$_},
120                  "$_ was not imported into Test::Leaner");
121   Test::More::ok(!exists $this_stash->{$_},
122                  "$_ was not imported into main");
123  }
124 }