File: 50-warn-undef.t

package info (click to toggle)
libprometheus-tiny-perl 0.011-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 180 kB
  • sloc: perl: 746; makefile: 2
file content (47 lines) | stat: -rw-r--r-- 1,028 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
#!perl

use warnings;
use strict;

use Test::More;
use Test::Warn;

use Prometheus::Tiny;

{
  my $p = Prometheus::Tiny->new;
  $p->set('some_metric', 10);
  warning_like
    { $p->set('some_metric') }
    qr/setting '.+' to non-numeric value, using 0 instead/,
    'setting undef value emits a warning';
  is $p->format, <<EOF, 'set metric undef formatted correctly';
some_metric 0
EOF
}

{
  my $p = Prometheus::Tiny->new;
  $p->set('some_metric', 10);
  warning_like
    { $p->add('some_metric') }
    qr/adjusting '.+' by non-numeric value, adding 0 instead/,
    'adding undef value emits a warning';
  is $p->format, <<EOF, 'add metric undef formatted correctly';
some_metric 10
EOF
}

{
  my $p = Prometheus::Tiny->new;
  $p->set('some_metric', 10);
  warning_like
    { $p->add('some_metric', 10, { foo => undef }) }
    qr/label '.+' has an undefined value, dropping it/,
    'undef label value emits a warning';
  is $p->format, <<EOF, 'add metric undef label formatted correctly';
some_metric 20
EOF
}

done_testing;