File: 05warn.t

package info (click to toggle)
libtest-databaserow-perl 2.04-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch
  • size: 296 kB
  • ctags: 177
  • sloc: perl: 3,062; makefile: 2
file content (68 lines) | stat: -rw-r--r-- 1,387 bytes parent folder | download | duplicates (3)
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
62
63
64
65
66
67
68
#!/usr/bin/perl -w

use strict;

# check if we can run Test::Warn
BEGIN
{
  eval { require Test::Warn; Test::Warn->import };
  if ($@)
  {
    print "1..0 # Skipped: no Test::Warn\n";
    exit;
  }
}

$Test::DatabaseRow::dbh = FakeDBI->new();

use Test::More tests => 2;
use Test::DatabaseRow;

# eek, how confusing is this?  This should produce two
# oks, one for the row_ok and one for not finding any
# warnings in it

warning_is { row_ok(sql   => "foo\nbar\nbaz",
		    tests => [ "fooid" => 123,
			       "wibble" => undef,],
		     label => "inside test",);
} "", "no warnings when dealing with undef/NULL";

# fake database package
package FakeDBI;
sub new { my $class = shift; return bless { @_, Name => "bob" }, $class };
sub quote { return "qtd<$_[1]>" };

sub prepare
{
  my $this = shift;

  # die if we need to
  if ($this->fallover)
    { die "Khaaaaaaaaaaaaan!" }

  return FakeSTH->new($this);
}

sub nomatch  { return $_[0]->{nomatch} }
sub fallover { return $_[0]->{fallover} }

package FakeSTH;
sub new { return bless { parent => $_[1] }, $_[0] };
sub execute { return 1 };
sub fetchrow_hashref
{
  my $this = shift;
  my $parent = $this->{parent};

  # return undef after the first call)
  if ($this->{called})
    { return }
  else
    { $this->{called} = 1 }

  return
    ($parent->nomatch)
     ?  undef
     : { fooid => 123, name => "fred", wibble => undef}
}