From: Vincent Pit Date: Sun, 4 Sep 2011 21:32:06 +0000 (+0200) Subject: Tweak some optional module loading in tests X-Git-Tag: v0.47~24 X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FVariable-Magic.git;a=commitdiff_plain;h=788d90465f0c4180f7b27d63f355bbf260ecb972 Tweak some optional module loading in tests --- diff --git a/t/16-huf.t b/t/16-huf.t index 32f7677..af9e740 100644 --- a/t/16-huf.t +++ b/t/16-huf.t @@ -11,13 +11,15 @@ if (!VMG_UVAR) { plan skip_all => 'No nice uvar magic for this perl'; } -eval "use Hash::Util::FieldHash"; -if ($@) { - plan skip_all => 'Hash::Util::FieldHash required for testing uvar interaction'; -} else { - plan tests => 2 * 5 + 7 + 1; - defined and diag "Using Hash::Util::FieldHash $_" +{ + local $@; + if (eval { require Hash::Util::FieldHash; 1 }) { + plan tests => 2 * 5 + 7 + 1; + defined and diag "Using Hash::Util::FieldHash $_" for $Hash::Util::FieldHash::VERSION; + } else { + plan skip_all => 'Hash::Util::FieldHash required for testing uvar interaction' + } } use lib 't/lib'; diff --git a/t/25-copy.t b/t/25-copy.t index a18022f..7e13dfd 100644 --- a/t/25-copy.t +++ b/t/25-copy.t @@ -20,9 +20,9 @@ use Variable::Magic::TestValue; my $wiz = init_watcher 'copy', 'copy'; SKIP: { - eval "use Tie::Array"; + my $has_tie_array = do { local $@; eval { require Tie::Array; 1 } }; skip 'Tie::Array required to test copy magic on arrays' - => (2 * 5 + 3) + (2 * 2 + 1) if $@; + => (2 * 5 + 3) + (2 * 2 + 1) unless $has_tie_array; defined and diag "Using Tie::Array $_" for $Tie::Array::VERSION; tie my @a, 'Tie::StdArray'; @@ -55,8 +55,9 @@ SKIP: { } SKIP: { - eval "use Tie::Hash"; - skip 'Tie::Hash required to test copy magic on hashes' => 2 * 9 + 6 if $@; + my $has_tie_hash = do { local $@; eval { require Tie::Hash; 1 } }; + skip 'Tie::Hash required to test copy magic on hashes' + => 2 * 9 + 6 unless $has_tie_hash; defined and diag "Using Tie::Hash $_" for $Tie::Hash::VERSION; tie my %h, 'Tie::StdHash'; diff --git a/t/28-uvar.t b/t/28-uvar.t index 0eaf001..d44f9f1 100644 --- a/t/28-uvar.t +++ b/t/28-uvar.t @@ -51,8 +51,9 @@ $x = watch { $h{a} } { fetch => 1 }, 'fetch directly with also non uvar magic'; is $x, 1, 'uvar: fetch directly with also non uvar magic correctly'; SKIP: { - eval "use Tie::Hash"; - skip 'Tie::Hash required to test uvar magic on tied hashes' => 2 * 5 + 4 if $@; + my $has_tie_hash = do { local $@; eval { require Tie::Hash; 1 } }; + skip 'Tie::Hash required to test uvar magic on tied hashes' + => 2 * 5 + 4 unless $has_tie_hash; defined and diag "Using Tie::Hash $_" for $Tie::Hash::VERSION; tie my %h, 'Tie::StdHash'; diff --git a/t/30-scalar.t b/t/30-scalar.t index caf76c9..c92b186 100644 --- a/t/30-scalar.t +++ b/t/30-scalar.t @@ -105,11 +105,13 @@ watch { $h{b} = 4 } { }, 'hash element: set after delete'; SKIP: { my $SKIP; - unless (MGf_COPY) { + if (!MGf_COPY) { $SKIP = 'No copy magic for this perl'; } else { - eval "use Tie::Array"; - $SKIP = 'Tie::Array required to test clear magic on tied array values' if $@; + local $@; + unless (eval { require Tie::Array; 1 }) { + $SKIP = 'Tie::Array required to test clear magic on tied array values'; + } } skip $SKIP => 3 if $SKIP; diff --git a/t/32-hash.t b/t/32-hash.t index 1bbd300..a7408fc 100644 --- a/t/32-hash.t +++ b/t/32-hash.t @@ -76,11 +76,13 @@ watch { dispell %h, $wiz } { }, 'dispell'; SKIP: { my $SKIP; - unless (VMG_UVAR) { + if (!VMG_UVAR) { $SKIP = 'uvar magic'; } else { - eval "use B::Deparse"; - $SKIP = 'B::Deparse' if $@; + local $@; + unless (eval { require B::Deparse; 1 }) { + $SKIP = 'B::Deparse'; + } } if ($SKIP) { $SKIP .= ' required to test uvar/clear interaction fix';