1package Test2::Require::EnvVar; 2use strict; 3use warnings; 4 5use Carp qw/confess/; 6use base 'Test2::Require'; 7 8our $VERSION = '0.000162'; 9 10sub skip { 11 my $class = shift; 12 my ($var) = @_; 13 confess "no environment variable specified" unless $var; 14 return undef if $ENV{$var}; 15 return "This test only runs if the \$$var environment variable is set"; 16} 17 181; 19 20__END__ 21 22=pod 23 24=encoding UTF-8 25 26=head1 NAME 27 28Test2::Require::EnvVar - Only run a test when a specific environment variable 29is set. 30 31=head1 DESCRIPTION 32 33It is common practice to write tests that are only run when an environment 34variable is set. This module automates the (admittedly trivial) work of creating 35such a test. 36 37=head1 SYNOPSIS 38 39 use Test2::Require::EnvVar 'SOME_VAR'; 40 41 ... 42 43 done_testing; 44 45=head1 SOURCE 46 47The source code repository for Test2-Suite can be found at 48F<https://github.com/Test-More/Test2-Suite/>. 49 50=head1 MAINTAINERS 51 52=over 4 53 54=item Chad Granum E<lt>exodist@cpan.orgE<gt> 55 56=back 57 58=head1 AUTHORS 59 60=over 4 61 62=item Chad Granum E<lt>exodist@cpan.orgE<gt> 63 64=back 65 66=head1 COPYRIGHT 67 68Copyright 2018 Chad Granum E<lt>exodist@cpan.orgE<gt>. 69 70This program is free software; you can redistribute it and/or 71modify it under the same terms as Perl itself. 72 73See F<http://dev.perl.org/licenses/> 74 75=cut 76