File: 06-quiet.t

package info (click to toggle)
libdbix-runsql-perl 0.25-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 248 kB
  • sloc: perl: 786; sql: 26; makefile: 10
file content (54 lines) | stat: -rw-r--r-- 1,239 bytes parent folder | download
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
#!perl -w
use strict;
use Test::More;

use DBIx::RunSQL;
use Data::Dumper;

# Test against a "real" database if we have one:
if( ! eval { require DBD::SQLite;
             require 5.008; # for scalar open
             1;  }) {
    plan skip_all => $@;
    exit;
};

plan tests => 2;

# Redirect STDOUT to a variable
close STDOUT; # sssh
open STDOUT, '>', \my $output;

my $exitcode = DBIx::RunSQL->handle_command_line(
    "my-test-app",
    [
    '--quiet',
    '--dsn' => 'dbi:SQLite:dbname=:memory:',
    '--sql' => <<'SQL',
        create table foo (bar integer, baz varchar);
        insert into foo (bar,baz) values (1,'hello');
        insert into foo (bar,baz) values (2,'world');
        select * from foo;
SQL
    ]
);

isnt $output, '', "We get output if rows are found";

$output = '';
$exitcode = DBIx::RunSQL->handle_command_line(
    "my-test-app",
    [
    '--quiet',
    '--dsn' => 'dbi:SQLite:dbname=:memory:',
    '--sql' => <<'SQL',
        create table foo (bar integer, baz varchar);
        insert into foo (bar,baz) values (1,'hello');
        insert into foo (bar,baz) values (2,'world');
        select * from foo where 1=0;
SQL
    ]
);
is $output, '', "We get no output if no rows are found";

done_testing();