File: test-tester.t

package info (click to toggle)
libtest-timer-perl 2.12-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 268 kB
  • sloc: perl: 201; makefile: 2
file content (138 lines) | stat: -rw-r--r-- 3,536 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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
## no critic (RequireVersionVar RequireExplicitPackage RequireEndWithOne ProhibitEmptyQuotes)

use warnings;
use strict;
use Test::Tester;
use Test::More;

use Test::Timer;

use FindBin qw($Bin);
use lib "$Bin/../t";

use Test::Timer::Test qw(_sleep);

$Test::Timer::alarm = 5;

check_test(
    sub {
        time_ok( sub { _sleep(1); }, 2, 'time_ok, passing test' );
    },
    { ok => 1, name => 'time_ok, passing test', depth => 2, diag => '' },
    'Succeeding test of time_ok'
);

check_test(
    sub {
        time_ok( sub { _sleep(2); }, 1, 'time_ok, failing test' );
    },
    {   ok    => 0,
        name  => 'time_ok, failing test',
        depth => 2,
        diag  =>
            qr/Test ran \d+ seconds and exceeded specified threshold of 1 seconds/
    },
    'Failing test of time_ok'
);

check_test(
    sub {
        time_nok( sub { _sleep(1); }, 3, 'time_nok, failing test' );
    },
    {   ok    => 0,
        name  => 'time_nok, failing test',
        depth => 1,
        diag  =>
            qr/Test ran \d+ seconds and did not exceed specified threshold of 3 seconds/
    },
    'Failing test of time_nok'
);

check_test(
    sub {
        time_nok( sub { _sleep(3); }, 1, 'time_nok, passing test' );
    },
    { ok => 1, name => 'time_nok, passing test', depth => 1, diag => '' },
    'Passing test of time_nok'
);

check_test(
    sub {
        time_between( sub { _sleep(1); }, 0, 3,
            'time_between, passing test' );
    },
    { ok => 1, name => 'time_between, passing test', depth => 1, diag => '' },
    'Passing test of time_between'
);

check_test(
    sub {
        time_between( sub { _sleep(3); }, 1, 2,
            'time_between, failing test' );
    },
    {   ok    => 0,
        name  => 'time_between, failing test',
        depth => 1,
        diag  =>
            qr/Test ran \d+ seconds and did not execute within specified interval 1 - 2 seconds/
    },
    'Failing test of time_between'
);

check_test(
    sub {
        time_atmost( sub { _sleep(1); }, 2, 'time_atmost, passing test' );
    },
    { ok => 1, name => 'time_atmost, passing test', depth => 1, diag => '' },
    'Succeeding test of time_atmost'
);

check_test(
    sub {
        time_atmost( sub { _sleep(2); }, 1, 'time_atmost, failing test' );
    },
    {   ok    => 0,
        name  => 'time_atmost, failing test',
        depth => 1,
        diag  =>
            qr/Test ran \d+ seconds and exceeded specified threshold of 1 seconds/
    },
    'Failing test of time_atmost'
);

check_test(
    sub {
        time_atleast( sub { _sleep(1); }, 3, 'time_atleast, failing test' );
    },
    {   ok    => 0,
        name  => 'time_atleast, failing test',
        depth => 1,
        diag  =>
            qr/Test ran \d+ seconds and did not exceed specified threshold of 3 seconds/
    },
    'Failing test of time_atleast'
);

check_test(
    sub {
        time_atleast( sub { _sleep(2); }, 1, 'time_atleast, passing test' );
    },
    { ok => 1, name => 'time_atleast, passing test', depth => 1, diag => '' },
    'Passing test of time_atleast'
);

check_test(
    sub {
        time_between( sub { _sleep(10); },
            1, 3, 'time_between, long running test, should time out' );
    },
    {   ok    => 0,
        name  => 'time_between, long running test, should time out',
        depth => 1,
        diag  =>
            qr/Execution ran \d+ seconds and did not execute within specified interval 1 - 3 seconds/
    },
    'failing long running test of time_between with timeout'
);

done_testing();