File Coverage: t/06-unset.t

# File Coverage

File: | t/06-unset.t
Coverage: | 95.4%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 | 1 1 1 |  |  | 1 |  | 2931 1 24 | use strict;
2 | 1 1 1 |  |  | 1 |  | 3 1 33 | use warnings;
3 |
4 | 1 1 1 |  |  | 1 |  | 254 812 82 | use FindBin qw/$Bin/;
5 | 1 1 1 |  |  | 1 |  | 232 497 4 | use lib qq{$Bin/../lib};
6 | 1 1 1 |  |  | 1 |  | 413 75705 5 | use Test::More;
7 |
8 | 1 1 1 |  |  | 1 |  | 506 1 3 | use OpenMP::Environment qw/:unset/;
9 | 1 1 1 |  |  | 1 |  | 4 1 214 | use OpenMP::Environment::Constants ();
10 |
11 | 1 |  |  |  |  | 63140 | my @constant_names = OpenMP::Environment::Constants::constant_names();
12 | 1 |  |  |  |  | 2 | my @environment_names = OpenMP::Environment::Constants::environment_names();
13 |
14 | 1 |  |  |  |  | 2 | is scalar(@constant_names), 25, q{25 DSL constants are defined};
15 | 1 |  |  |  |  | 292 | is scalar(@environment_names), 25, q{25 canonical environment names are defined};
16 |
17 | 1 |  |  |  |  | 216 | for my $i ( 0 .. $#constant_names ) {
18 | 25 |  |  |  |  | 4613 | my $constant = $constant_names[$i];
19 | 25 |  |  |  |  | 24 | my $ev = $environment_names[$i];
20 | 25 |  |  |  |  | 75 | my $code = __PACKAGE__->can($constant);
21 | 25 |  |  |  |  | 56 | ok $code, qq{$constant is imported by :unset};
22 | 25 |  |  |  |  | 4668 | is $code->(), $ev, qq{$constant resolves to $ev};
23 | 25 |  |  |  |  | 5060 | ok OpenMP::Environment::Constants::is_environment_name($ev), qq{$ev is recognized};
24 |
25 | 25 |  |  |  |  | 4761 | local $ENV{$ev} = qq{value-$i};
26 | 25 |  |  |  |  | 46 | is unset($ev), qq{value-$i}, qq{unset dispatches $ev and returns old value};
27 | 25 |  |  |  |  | 5525 | ok !exists $ENV{$ev}, qq{unset removes $ev};
28 |  |  |  |  |  |  | }
29 |
30 | 1 |  |  |  |  | 191 | ok !OpenMP::Environment::Constants::is_environment_name(q{OMP_NOT_REAL}), q{unsupported environment name is rejected by constants lookup};
31 |
32 | 1 1 0 |  |  |  |  | 183 4 0 | my $unknown_ok = eval { unset(q{OMP_NOT_REAL}); 1 };
33 | 1 |  |  |  |  | 4 | ok !$unknown_ok, q{unset rejects an unknown environment variable};
34 | 1 |  |  |  |  | 196 | like $@, qr/Unsupported OpenMP\/libgomp/, q{unknown unset explains the supported namespace};
35 |
36 |  |  |  |  |  |  | {
37 | 0 |  |  |  |  | 0 | package OpenMPEnvironmentNoImport;
38 | 1 1 1 |  |  | 1 |  | 4 1 2 | use OpenMP::Environment;
39 |  |  |  |  |  |  | }
40 | 1 1 |  |  |  |  | 198 13 | ok !OpenMPEnvironmentNoImport->can(q{unset}), q{unset is not exported by default};
41 | 1 |  |  |  |  | 192 | ok !OpenMPEnvironmentNoImport->can(q{omp_num_threads}), q{DSL constants are not exported by default};
42 |
43 |  |  |  |  |  |  | {
44 | 0 |  |  |  |  | 0 | package OpenMPEnvironmentUnsetOnly;
45 | 1 1 1 |  |  | 1 |  | 3 1 2 | use OpenMP::Environment qw/:unset/;
46 |  |  |  |  |  |  | }
47 | 1 1 |  |  |  |  | 184 12 | ok( OpenMPEnvironmentUnsetOnly->can(q{unset}), q{:unset exports unset} );
48 | 1 |  |  |  |  | 186 | ok( OpenMPEnvironmentUnsetOnly->can(q{omp_num_threads}), q{:unset exports constants} );
49 | 1 |  |  |  |  | 185 | ok( !OpenMPEnvironmentUnsetOnly->can(q{assert}), q{:unset does not export assert} );
50 |
51 |  |  |  |  |  |  | {
52 | 0 |  |  |  |  | 0 | package OpenMPEnvironmentExplicitUnset;
53 | 1 1 1 |  |  | 1 |  | 3 1 2 | use OpenMP::Environment qw/unset omp_num_threads/;
54 |  |  |  |  |  |  | }
55 | 1 1 |  |  |  |  | 182 28 | ok( OpenMPEnvironmentExplicitUnset->can(q{unset}), q{explicit unset import works} );
56 | 1 |  |  |  |  | 245 | is OpenMPEnvironmentExplicitUnset::omp_num_threads(), q{OMP_NUM_THREADS}, q{explicit constant import works};
57 |
58 | 1 1 1 1 |  |  | 1 |  | 252 5 1 4 | my $bad_import = eval q{package OpenMPEnvironmentBadImport; use OpenMP::Environment qw/not_a_symbol/; 1;};
59 | 1 |  |  |  |  | 4 | ok !$bad_import, q{unknown import is rejected};
60 | 1 |  |  |  |  | 191 | like $@, qr/not exported/, q{unknown import reports export error};
61 |
62 | 1 |  |  |  |  | 189 | local $ENV{OMP_NUM_THREADS} = 9;
63 | 1 |  |  |  |  | 2 | is unset omp_num_threads, 9, q{literal unset omp_num_threads DSL form works};
64 |
65 | 1 |  |  |  |  | 217 | my $env = OpenMP::Environment->new;
66 | 1 |  |  |  |  | 2 | $env->omp_num_threads = 7;
67 | 1 |  |  |  |  | 6 | is $env->unset_omp_num_threads, 7, q{legacy unset_omp_num_threads remains supported};
68 | 1 |  |  |  |  | 208 | ok !exists $ENV{OMP_NUM_THREADS}, q{legacy unsetter still deletes the environment variable};
69 |
70 | 1 |  |  |  |  | 187 | done_testing;
71 |