summaryrefslogtreecommitdiff
path: root/cpan/Devel-PPPort/t/testutil.pl
blob: 4fc7d667a6bf2f4cb71600eedfafe9cc5be34201 (plain)
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
{
  my $__ntest;
  my $__total;

  sub plan {
    @_ == 2 or die "usage: plan(tests => count)";
    my $what = shift;
    $what eq 'tests' or die "cannot plan anything but tests";
    $__total = shift;
    defined $__total && $__total > 0 or die "need a positive number of tests";
    print "1..$__total\n";
  }

  sub skip {
    my $reason = shift;
    ++$__ntest;
    print "ok $__ntest # skip: $reason\n"
  }

  sub ok ($;$$) {
    local($\,$,);
    my $ok = 0;
    my $result = shift;
    if (@_ == 0) {
      $ok = $result;
    } else {
      $expected = shift;
      if (!defined $expected) {
        $ok = !defined $result;
      } elsif (!defined $result) {
        $ok = 0;
      } elsif (ref($expected) eq 'Regexp') {
        die "using regular expression objects is not backwards compatible";
      } else {
        $ok = $result eq $expected;
      }
    }
    ++$__ntest;
    if ($ok) {
      print "ok $__ntest\n"
    }
    else {
      print "not ok $__ntest\n"
    }
  }
}

1;