File: msec.t

package info (click to toggle)
libtime-format-perl 1.16-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 300 kB
  • sloc: perl: 653; makefile: 4
file content (39 lines) | stat: -rw-r--r-- 843 bytes parent folder | download | duplicates (2)
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
#!/perl

# Replicate the bug where microseconds and  milliseconds show up as negative numbers.

use strict;
use Test::More tests => 41;

BEGIN { $Time::Format::NOXS = 1 }
BEGIN { use_ok 'Time::Format', qw(:all) }
my $hr_ok;
BEGIN { $hr_ok = eval('use Time::HiRes qw(usleep); 1') }

SKIP:
{
    skip 'Time::HiRes not available', 40  unless $hr_ok;

    my @vals;
    for (1..20)
    {
        push @vals, "$_: $time{'yyyy/mm/dd hh:mm:ss.mmm'}    -- milli";
        push @vals, "$_: $time{'yyyy/mm/dd hh:mm:ss.uuuuuu'} -- micro";

        if ($hr_ok)
        {
            usleep(180_000);  # 180 ms
        }
        else
        {
            sleep 2;
        }
    }

    my $count = 0;
    foreach my $str (@vals)
    {
        ++$count;
        ok $str !~ /\d\.-\d/, "Bug test $count ($str)";
    }
}