File: 99_errors.t

package info (click to toggle)
libbenchmark-timer-perl 0.7112-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 312 kB
  • sloc: perl: 2,679; makefile: 8
file content (75 lines) | stat: -rwxr-xr-x 1,970 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# ========================================================================
# t/99_errors.t - test fatal and warn error cases
# Andrew Ho (andrew@zeuscat.com)
#
# In this test we exercise fatal conditions and check that they really
# do die with an error status.
#
# This script is intended to be run as a target of Test::Harness.
#
# Last modified April 20, 2001
# ========================================================================

use strict;
use Test::More tests => 6;
use Benchmark::Timer;

# ------------------------------------------------------------------------
# Check fatal condition where you call stop() but start() has NEVER run

eval {
    my $t = Benchmark::Timer->new;
    $t->stop;
};

# 1
like($@, qr/must call/, 'Must call start first');

# ------------------------------------------------------------------------
# Check fatal out of sync condition

eval {
    my $t = Benchmark::Timer->new;
    $t->start('tag');
    $t->stop;
    $t->stop;
};

# 2
like($@, qr/out of sync/, 'Out of sync');

# ------------------------------------------------------------------------
# Check fatal bad skip argument handling

eval { my $t = Benchmark::Timer->new( skip => undef ) };

# 3
like($@, qr/argument skip/, 'Argument skip 1');

eval { my $t = Benchmark::Timer->new( skip => 'foo' ) };

# 4
like($@, qr/argument skip/, 'Argument skip 2');

eval { my $t = Benchmark::Timer->new( skip => -1 ) };

# 5
like($@, qr/argument skip/, 'Argument skip 3');

# ------------------------------------------------------------------------
# Check warning on unrecognized arguments

use vars qw($last_warning);
undef $last_warning;
{
    local $SIG{__WARN__} = sub { $last_warning = shift };
    my $weird_arg = '__this_is_not_a_valid_argument__';
    my $t = Benchmark::Timer->new( $weird_arg => undef );

    # 6
    like($last_warning, qr/skipping unknown/, 'Invalid argument');
}


# ========================================================================
__END__