From: Karen Etheridge Date: Sat, 28 Aug 2010 18:32:03 +0000 (-0700) Subject: use Test::Requires in tests X-Git-Tag: 0.28~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Storage.git;a=commitdiff_plain;h=0b1731882300cdb05aa9fe09716da7a9a03cd00d use Test::Requires in tests --- diff --git a/Makefile.PL b/Makefile.PL index dd9e177..43c4ac2 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -45,6 +45,7 @@ build_requires 'Test::More' => '0.88'; build_requires 'Test::Deep' => '0'; build_requires 'Test::Exception' => '0'; build_requires 'Test::TempDir' => '0.02'; +build_requires 'Test::Requires' => '0.05'; author_requires 'Test::Pod' => '1.14'; author_requires 'Test::Pod::Coverage' => '1.08'; diff --git a/t/002_basic_io.t b/t/002_basic_io.t index 06a3322..538ec14 100644 --- a/t/002_basic_io.t +++ b/t/002_basic_io.t @@ -10,9 +10,11 @@ use File::Spec::Functions; my $dir = tempdir; -BEGIN { - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; +use Test::Requires { + 'JSON::Any' => 0.01, # skip all if not installed +}; + +BEGIN { plan tests => 10; use_ok('MooseX::Storage'); } diff --git a/t/010_basic_json.t b/t/010_basic_json.t index db190fc..7f405e8 100644 --- a/t/010_basic_json.t +++ b/t/010_basic_json.t @@ -5,11 +5,12 @@ use warnings; use Test::More; -BEGIN { - eval "use Test::JSON"; - plan skip_all => "Test::JSON is required for this test" if $@; - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; +use Test::Requires { + 'Test::JSON' => 0.01, # skip all if not installed + 'JSON::Any' => 0.01, +}; + +BEGIN { plan tests => 12; use_ok('MooseX::Storage'); } diff --git a/t/011_basic_json_w_utf8.t b/t/011_basic_json_w_utf8.t index 346325e..64cef7c 100644 --- a/t/011_basic_json_w_utf8.t +++ b/t/011_basic_json_w_utf8.t @@ -5,20 +5,22 @@ use warnings; use Test::More; +use Test::Requires { + 'Encode' => 0.01, # skip all if not installed + 'JSON::Any' => 0.01, +}; + BEGIN { - eval "use Encode"; - plan skip_all => "Encode is required for this test" if $@; - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; # NOTE: # this is because JSON::XS is # the only one which really gets # utf8 correct # - SL - BEGIN { + BEGIN { $ENV{JSON_ANY_ORDER} = qw(XS); $ENV{JSON_ANY_CONFIG} = "utf8=1"; - } + } + plan tests => 16; use_ok('MooseX::Storage'); } diff --git a/t/012_param_json.t b/t/012_param_json.t index e694e1b..1a3bb20 100644 --- a/t/012_param_json.t +++ b/t/012_param_json.t @@ -5,14 +5,14 @@ use warnings; use Test::More; -BEGIN { - local $@; - plan skip_all => "MooseX::Storage::Format::JSONpm required for this test" - unless eval "require MooseX::Storage::Format::JSONpm; 1"; -} +use Test::Requires { + 'MooseX::Storage::Format::JSONpm' => 0.01, # skip all if not installed +}; -plan tests => 6; -use_ok('MooseX::Storage'); +BEGIN { + plan tests => 6; + use_ok('MooseX::Storage'); +} { package Foo; diff --git a/t/020_basic_yaml.t b/t/020_basic_yaml.t index 9f60bf9..1cb5137 100644 --- a/t/020_basic_yaml.t +++ b/t/020_basic_yaml.t @@ -5,13 +5,13 @@ use warnings; use Test::More; +use Test::Requires { + 'YAML::Any' => 0.01, # skip all if not installed + 'YAML' => 0.01, + 'Test::Without::Module' => 0.01, +}; + BEGIN { - eval "use YAML::Any"; - plan skip_all => "YAML::Any is required for this test" if $@; - eval "require YAML"; - plan skip_all => "YAML is required for this test" if $@; - eval "require Test::Without::Module"; - plan skip_all => "Test::Without::Module is required for this test" if $@; Test::Without::Module->import(YAML::Any->order); Test::Without::Module->unimport('YAML'); plan tests => 10; diff --git a/t/020_basic_yaml_syck.t b/t/020_basic_yaml_syck.t index d94fcd2..19d086c 100644 --- a/t/020_basic_yaml_syck.t +++ b/t/020_basic_yaml_syck.t @@ -5,13 +5,13 @@ use warnings; use Test::More; +use Test::Requires { + 'YAML::Any' => 0.01, # skip all if not installed + 'YAML::Syck' => 0.01, + 'Test::Without::Module' => 0.01, +}; + BEGIN { - eval "use YAML::Any"; - plan skip_all => "YAML::Any is required for this test" if $@; - eval "require YAML::Syck"; - plan skip_all => "YAML::Syck is required for this test" if $@; - eval "require Test::Without::Module"; - plan skip_all => "Test::Without::Module is required for this test" if $@; Test::Without::Module->import(YAML::Any->order); Test::Without::Module->unimport('YAML::Syck'); plan tests => 10; @@ -19,7 +19,6 @@ BEGIN { } { - package Foo; use Moose; use MooseX::Storage; diff --git a/t/020_basic_yaml_xs.t b/t/020_basic_yaml_xs.t index 42d1d07..8f19177 100644 --- a/t/020_basic_yaml_xs.t +++ b/t/020_basic_yaml_xs.t @@ -5,13 +5,13 @@ use warnings; use Test::More; +use Test::Requires { + 'YAML::Any' => 0.01, # skip all if not installed + 'YAML::XS' => 0.01, + 'Test::Without::Module' => 0.01, +}; + BEGIN { - eval "use YAML::Any"; - plan skip_all => "YAML::Any is required for this test" if $@; - eval "require YAML::XS"; - plan skip_all => "YAML::XS is required for this test" if $@; - eval "require Test::Without::Module"; - plan skip_all => "Test::Without::Module is required for this test" if $@; Test::Without::Module->import(YAML::Any->order); Test::Without::Module->unimport('YAML::XS'); plan tests => 10; @@ -19,7 +19,6 @@ BEGIN { } { - package Foo; use Moose; use MooseX::Storage; diff --git a/t/030_with_checksum.t b/t/030_with_checksum.t index 9892500..f123821 100644 --- a/t/030_with_checksum.t +++ b/t/030_with_checksum.t @@ -7,17 +7,18 @@ use Test::More; use Test::Exception; use Test::Deep; +use Test::Requires { + 'Digest' => 0.01, # skip all if not installed + 'Digest::SHA1' => 0.01, + 'JSON::Any' => 0.01, +}; + BEGIN { - eval "use Digest; use Digest::SHA1"; - plan skip_all => "Digest and Digest::SHA1 is required for this test" if $@; - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 26; use_ok('MooseX::Storage'); } { - package Foo; use Moose; use MooseX::Storage; diff --git a/t/060_basic_deferred.t b/t/060_basic_deferred.t index c8bbe33..59d3c83 100644 --- a/t/060_basic_deferred.t +++ b/t/060_basic_deferred.t @@ -7,13 +7,13 @@ use warnings; use Test::More; use Storable; +use Test::Requires { + 'Test::JSON' => 0.01, # skip all if not installed + 'JSON::Any' => 0.01, + 'YAML::Any' => 0.01, +}; + BEGIN { - eval "use Test::JSON"; - plan skip_all => "Test::JSON is required for this test" if $@; - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; - eval "use YAML::Any"; - plan skip_all => "YAML::Any is required for this test" if $@; plan tests => 31; use_ok('MooseX::Storage'); } @@ -21,7 +21,6 @@ BEGIN { diag('Using implementation: ', YAML::Any->implementation); { - package Foo; use Moose; use MooseX::Storage; diff --git a/t/061_basic_deferred_w_io.t b/t/061_basic_deferred_w_io.t index 512c97e..d7403a2 100644 --- a/t/061_basic_deferred_w_io.t +++ b/t/061_basic_deferred_w_io.t @@ -9,11 +9,12 @@ use File::Spec::Functions; my $dir = tempdir; +use Test::Requires { + 'IO::AtomicFile' => 0.01, # skip all if not installed + 'JSON::Any' => 0.01, +}; + BEGIN { - eval "use IO::AtomicFile"; - plan skip_all => "IO::AtomicFile is required for this test" if $@; - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 20; use_ok('MooseX::Storage'); } diff --git a/t/100_io.t b/t/100_io.t index 8874409..78e3dc8 100644 --- a/t/100_io.t +++ b/t/100_io.t @@ -8,10 +8,12 @@ use Test::TempDir; use File::Spec::Functions; my $dir = tempdir; -BEGIN { - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; - plan tests => 10; +use Test::Requires { + 'JSON::Any' => 0.01, # skip all if not installed +}; + +BEGIN { + plan tests => 10; use_ok('MooseX::Storage'); } diff --git a/t/101_io_atomic.t b/t/101_io_atomic.t index 55373a5..3e629d9 100644 --- a/t/101_io_atomic.t +++ b/t/101_io_atomic.t @@ -8,11 +8,12 @@ use File::Temp qw(tempdir); use File::Spec::Functions; my $dir = tempdir( CLEANUP => 1 ); +use Test::Requires { + 'JSON::Any' => 0.01, # skip all if not installed + 'IO::AtomicFile' => 0.01, +}; + BEGIN { - eval "use IO::AtomicFile"; - plan skip_all => "IO::AtomicFile is required for this test" if $@; - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; plan tests => 10; use_ok('MooseX::Storage'); } diff --git a/t/104_io_w_utf8.t b/t/104_io_w_utf8.t index 6cc5ec5..5993f6d 100644 --- a/t/104_io_w_utf8.t +++ b/t/104_io_w_utf8.t @@ -8,18 +8,21 @@ use File::Temp qw(tempdir); use File::Spec::Functions; my $dir = tempdir( CLEANUP => 1 ); +use Test::Requires { + 'JSON::Any' => 0.01, # skip all if not installed + 'IO::AtomicFile' => 0.01, +}; + BEGIN { - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; # NOTE: # this is because JSON::XS is # the only one which really gets # utf8 correct # - SL - BEGIN { + BEGIN { $ENV{JSON_ANY_ORDER} = qw(XS); $ENV{JSON_ANY_CONFIG} = "utf8=1"; - } + } plan tests => 8; use_ok('MooseX::Storage'); } diff --git a/t/105_io_atomic_w_utf8.t b/t/105_io_atomic_w_utf8.t index d831409..fd584c2 100644 --- a/t/105_io_atomic_w_utf8.t +++ b/t/105_io_atomic_w_utf8.t @@ -8,20 +8,21 @@ use Test::TempDir; use File::Spec::Functions; my $dir = tempdir; +use Test::Requires { + 'JSON::Any' => 0.01, # skip all if not installed + 'IO::AtomicFile' => 0.01, +}; + BEGIN { - eval "use IO::AtomicFile"; - plan skip_all => "IO::AtomicFile is required for this test" if $@; - eval "use JSON::Any"; - plan skip_all => "JSON::Any is required for this test" if $@; # NOTE: # this is because JSON::XS is # the only one which really gets # utf8 correct # - SL - BEGIN { + BEGIN { $ENV{JSON_ANY_ORDER} = qw(XS); $ENV{JSON_ANY_CONFIG} = "utf8=1"; - } + } plan tests => 8; use_ok('MooseX::Storage'); } diff --git a/t/300_overloaded.t b/t/300_overloaded.t index d17593b..b38ea7f 100644 --- a/t/300_overloaded.t +++ b/t/300_overloaded.t @@ -3,12 +3,9 @@ use warnings; use Test::More; use Test::Exception; -BEGIN { - eval { require JSON::Any } or do { - plan skip_all => "JSON::Any is required for this test"; - exit 0; - } -} +use Test::Requires { + 'JSON::Any' => 0.01, # skip all if not installed +}; { package Thing;