File: env-assert-public-report_errors.t

package info (click to toggle)
env-assert 0.010-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 172 kB
  • sloc: perl: 433; makefile: 2
file content (70 lines) | stat: -rw-r--r-- 1,927 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
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
#!perl
## no critic [ValuesAndExpressions::ProhibitConstantPragma]
use strict;
use warnings;
use Test2::V0;

use Env::Assert qw( report_errors );

use constant {
    ENV_ASSERT_MISSING_FROM_ENVIRONMENT    => 1,
    ENV_ASSERT_INVALID_CONTENT_IN_VARIABLE => 2,
    ENV_ASSERT_MISSING_FROM_DEFINITION     => 3,
};

subtest 'Public Subroutine report_errors()' => sub {

    {
        my %errors = (
            variables => {
                USER => {
                    type    => ENV_ASSERT_MISSING_FROM_DEFINITION,
                    message => 'Variable USER has invalid content',
                },
            },
        );
        my $expected = <<END_OF_TEXT;
Environment Assert: ERRORS:
    variables:
        USER: Variable USER has invalid content
END_OF_TEXT
        my $out = report_errors( \%errors );
        is( $out, $expected, 'Errors output correct' );
    }

    {
        my %errors = (
            variables => {
                USER => {
                    type    => ENV_ASSERT_MISSING_FROM_ENVIRONMENT,
                    message => 'Variable USER is missing from environment',
                },
                NEEDLESS_1 => {
                    type    => ENV_ASSERT_MISSING_FROM_DEFINITION,
                    message => 'Variable NEEDLESS_1 is missing from definition',
                },
            },
        );
        my $expected = <<END_OF_TEXT;
Environment Assert: ERRORS:
    variables:
        NEEDLESS_1: Variable NEEDLESS_1 is missing from definition
        USER: Variable USER is missing from environment
END_OF_TEXT
        my $out = report_errors( \%errors );
        is( $out, $expected, 'Errors output correct' );
    }

    {
        my %errors   = ();
        my $expected = <<END_OF_TEXT;
Environment Assert: ERRORS:
END_OF_TEXT
        my $out = report_errors( \%errors );
        is( $out, $expected, 'Errors output correct' );
    }

    done_testing;
};

done_testing;