Skip to content

Instantly share code, notes, and snippets.

@exodist
Last active August 29, 2015 14:11
Show Gist options
  • Save exodist/5b0b9b21cfeda4323937 to your computer and use it in GitHub Desktop.
Save exodist/5b0b9b21cfeda4323937 to your computer and use it in GitHub Desktop.
Test::SkipWithout
package Test::SkipWithout;
use strict;
use warnings;
require Test::More;
sub import {
my $class = shift;
my ($module, $version) = @_;
my ($pkg, $file, $line) = caller;
return skip($module, $version, "$module did not load: $@")
unless eval qq{#line $line "$file"\nrequire $module; 1};
return unless $version;
return skip($module, $version, $@)
unless eval qq{#line $line "$file"\n\$module->VERSION(\$version)};
}
sub skip {
my ($module, $version, $reason) = @_;
Test::More::plan('skip_all' => $reason)
unless $ENV{RELEASE_TESTING} || $ENV{AUTHOR_TESTING};
my $name = $module;
$name .= " $version" if $version;
Test::More::fail($name);
Test::More::diag($reason);
exit;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment