File Coverage

blib/lib/Test/Env.pm
Criterion Covered Total %
statement 20 21 95.2
branch 4 4 100.0
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 30 31 96.7


line stmt bran cond sub pod time code
1             package Test::Env;
2 3     3   781184 use strict;
  3         6  
  3         207  
3              
4 3     3   20 use vars qw(@EXPORT $VERSION);
  3         8  
  3         220  
5              
6 3     3   19 use Exporter qw(import);
  3         6  
  3         186  
7              
8             @EXPORT = qw(env_ok);
9             $VERSION = '1.088';
10              
11 3     3   19 use Test::Builder;
  3         9  
  3         861  
12              
13             my $Test = Test::Builder->new();
14              
15             =encoding utf8
16              
17             =head1 NAME
18              
19             Test::Env - test the environment
20              
21             =head1 SYNOPSIS
22              
23             use Test::More tests => 1;
24             use Test::Env;
25              
26             env_ok( 'PERL5LIB', "./blib/lib" );
27              
28             =head1 DESCRIPTION
29              
30             =head2 Functions
31              
32             =over 4
33              
34             =item env_ok( NAME, VALUE )
35              
36             Ok if the environment variable NAME is VALUE.
37              
38             =cut
39              
40             sub env_ok($$) {
41 3     3 1 178247 my $name = shift;
42 3         7 my $value = shift;
43              
44 3 100       16 unless( exists $ENV{$name} ) {
    100          
45 1         8 $Test->ok(0);
46 1         1222 $Test->diag( "Environment variable [$name] missing!\n",
47             "\tExpected [$value]\n" );
48             }
49 0         0 elsif( $ENV{$name} ne $value ) {
50 1         6 $Test->ok(0);
51 1         1425 $Test->diag( "Environment variable [$name] has wrong value!\n",
52             "\tExpected [$value]\n",
53             "\tGot [$ENV{$name}]\n" );
54             }
55             else
56             {
57 1         8 $Test->ok(1);
58             }
59             }
60              
61             =back
62              
63             =head1 SOURCE AVAILABILITY
64              
65             This source is in GitHub:
66              
67             https://github.com/briandfoy/test-env
68              
69             =head1 AUTHOR
70              
71             brian d foy, C<< >>
72              
73             =head1 COPYRIGHT AND LICENSE
74              
75             Copyright © 2002-2025, brian d foy . All rights reserved.
76              
77             This program is free software; you can redistribute it and/or modify
78             it under the terms of the Artistic License 2.0.
79              
80             =cut
81              
82              
83             "Roscoe";