File: funcs.pl

package info (click to toggle)
libconvert-asn1-perl 0.34-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 468 kB
  • sloc: perl: 4,526; yacc: 544; makefile: 2
file content (61 lines) | stat: -rw-r--r-- 1,309 bytes parent folder | download | duplicates (6)
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
49
50
51
52
53
54
55
56
57
58
59
60
61

sub ntest ($$$) {
  my $ret = 1;
  if ($_[1] != $_[2]) {
    printf "#$_[0]: expecting $_[1]\n";
    printf "#$_[0]:       got $_[2]\n";
    printf "#line %d %s\n",(caller)[2,1];
    print "not ";
    $ret = 0;
  }
  print "ok $_[0]\n";
  $ret;
}

sub stest ($$$) {
  my $ret = 1;
  unless (defined $_[2] && $_[1] eq $_[2]) {
    printf "#$_[0]: expecting %s\n", $_[1] =~ /[^\.\d\w]/ ? "hex:".unpack("H*",$_[1]) : $_[1];
    printf "#$_[0]:       got %s\n", defined($_[2]) ? $_[2] =~  /[^\.\d\w]/ ? "hex:".unpack("H*",$_[2]) : $_[2] : 'undef';
    printf "#line %d %s\n",(caller)[2,1];
    print "not ";
    $ret = 0;
  }
  print "ok $_[0]\n";
  $ret;
}

sub btest ($$) {
  unless ($_[1]) {
    printf "#line %d %s\n",(caller)[2,1];
    print "not ";
  }
  print "ok $_[0]\n";
  $_[1]
}


sub rtest ($$$) {
  unless (eval { require Data::Dumper } ) {
    print "ok $_[0] # skip need Data::Dumper\n";
    return;
  }

  local $Data::Dumper::Sortkeys = 1;
  local $Data::Dumper::Useqq = 1;
  my $expect = Data::Dumper::Dumper($_[1]);
  my $got = Data::Dumper::Dumper($_[2]);
  my $ok = $expect eq $got;

  unless ($ok) {
    printf "#$_[0]: expecting %s\n", $expect;
    printf "#$_[0]:       got %s\n", $got;
    printf "#line %d %s\n",(caller)[2,1];
    print "not ";
  }
  print "ok $_[0]\n";
  $ok;
}

1;