File: 05-object.t

package info (click to toggle)
libtest-command-perl 0.11-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 144 kB
  • sloc: perl: 712; makefile: 2
file content (94 lines) | stat: -rw-r--r-- 2,584 bytes parent folder | download | duplicates (5)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!perl

use Test::More tests => 38;

use Test::Command;

use FindBin;

## determine whether we can run perl or not

system qq($^X -e 1) and BAIL_OUT('error calling perl via system');

my $test_perl = Test::Command->new( cmd => qq($^X -le "print qq(foo\nbar); print STDERR qq(bar\nfoo)") );

ok(defined $test_perl, 'defined $test_perl');

is(ref $test_perl, 'Test::Command', 'ref $test_perl');

$test_perl->run;

is( $test_perl->exit_value, 0, "exit_value" );

$test_perl->exit_is_num(0);
$test_perl->exit_isnt_num(1);
$test_perl->exit_cmp_ok('<', 1);

SKIP:
   {
   skip("not sure about Win32 signal support", 2) if $^O eq 'MSWin32';
   is( $test_perl->signal_value, undef, "signal_value" );
   $test_perl->signal_is_undef;
   }

is( $test_perl->stdout_value, "foo\nbar\n", "stdout_value" );
is( Test::Command::_slurp($test_perl->stdout_file), "foo\nbar\n", "stdout_file" );
$test_perl->stdout_is_eq("foo\nbar\n");
$test_perl->stdout_isnt_eq("bar\nfoo\n");
{
local $^W;
$test_perl->stdout_is_num(0);
$test_perl->stdout_isnt_num(1);
}
$test_perl->stdout_like(qr/foo\nBAR/i);
$test_perl->stdout_unlike(qr/foo\nBAR/);
$test_perl->stdout_cmp_ok('ne', "bar\nfoo\n");
$test_perl->stdout_is_file("$FindBin::Bin/stdout.txt");

is( $test_perl->stderr_value, "bar\nfoo\n", "stderr_value" );
is( Test::Command::_slurp($test_perl->stderr_file), "bar\nfoo\n", "stderr_file" );
$test_perl->stderr_is_eq("bar\nfoo\n");
$test_perl->stderr_isnt_eq("foo\nbar\n");
{
local $^W;
$test_perl->stderr_is_num(0);
$test_perl->stderr_isnt_num(1);
}
$test_perl->stderr_like(qr/BAR\nFOO/i);
$test_perl->stderr_unlike(qr/BAR\nFOO/);
$test_perl->stderr_cmp_ok('ne', "foo\nbar\n");
$test_perl->stderr_is_file("$FindBin::Bin/stderr.txt");

## test object with ARRAY ref command

$test_perl = Test::Command->new( cmd => [$^X,
                                         '-le',
                                         'print qq(foo\nbar); print STDERR qq(bar\nfoo)' ] );

ok(defined $test_perl, 'defined $test_perl');

is(ref $test_perl, 'Test::Command', 'ref $test_perl');

## lazily run at first test

$test_perl->exit_is_num(0);
$test_perl->stdout_is_eq("foo\nbar\n");
$test_perl->stderr_is_eq("bar\nfoo\n");

package Test::Command::Derived;

use base Test::Command;

package main;

$test_perl = Test::Command::Derived->new( cmd => qq($^X -le "print qq(foo\nbar); print STDERR qq(bar\nfoo)") );

ok(defined $test_perl, 'defined $test_perl');

is(ref $test_perl, 'Test::Command::Derived', 'ref $test_perl');

$test_perl->run;

$test_perl->exit_is_num(0);
$test_perl->exit_isnt_num(1);
$test_perl->exit_cmp_ok('<', 1);