File: 50-warn-undef.t

package info (click to toggle)
libprometheus-tiny-perl 0.010-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 180 kB
  • sloc: perl: 730; makefile: 2
file content (35 lines) | stat: -rw-r--r-- 706 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
#!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
}

done_testing;