first commit
This commit is contained in:
325
t/.perlcriticrc
Normal file
325
t/.perlcriticrc
Normal file
@ -0,0 +1,325 @@
|
||||
# You may disable specific policies appending the following annotation
|
||||
#
|
||||
# ## no critic (..., ...)
|
||||
#
|
||||
# to the corresponding code line. To direct perlcritic to ignore the
|
||||
# "## no critic" annotations, use the --force option.
|
||||
|
||||
# Policies shipped with Perl::Critic 1.125 were considered for the below
|
||||
# defintion of the new policy theme "critic".
|
||||
|
||||
severity = brutal
|
||||
theme = critic
|
||||
verbose = %f: %m at line %l, column %c. (Policy: %p)\n
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval]
|
||||
add_themes = critic
|
||||
allow_includes = 1
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitUselessTopic]
|
||||
# KNOWN BUGS: This policy flags a false positive on reverse() called in list
|
||||
# context, since reverse() in list context does not assume $_.
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::BuiltinFunctions::RequireSimpleSortBlock]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA]
|
||||
# Note: Some people prefer parent over base.
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::CodeLayout::ProhibitHardTabs]
|
||||
add_themes = critic
|
||||
allow_leading_tabs = 0
|
||||
|
||||
[Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse]
|
||||
add_themes = critic
|
||||
max_elsif = 1
|
||||
|
||||
[Perl::Critic::Policy::ControlStructures::ProhibitDeepNests]
|
||||
# Martin Fowler's book "Refactoring: Improving The Design of Existing Code".
|
||||
add_themes = critic
|
||||
max_nests = 5
|
||||
|
||||
[Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions]
|
||||
# Read the LIMITATIONS that this policy has.
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Documentation::PodSpelling]
|
||||
add_themes =
|
||||
|
||||
[Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators]
|
||||
add_themes = critic
|
||||
only_in_void_context = 1
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::ProhibitInteractiveTest]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::ProhibitJoinedReadline]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::RequireBriefOpen]
|
||||
# http://www.perlmonks.org/?node_id=1134785
|
||||
add_themes = critic
|
||||
lines = 9
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls]
|
||||
# Covers the policies
|
||||
# Perl::Critic::Policy::InputOutput::RequireCheckedClose and
|
||||
# Perl::Critic::Policy::InputOutput::RequireCheckedOpen
|
||||
add_themes = critic
|
||||
exclude_functions = print say
|
||||
functions = :builtins
|
||||
|
||||
[Perl::Critic::Policy::InputOutput::RequireEncodingWithUTF8Layer]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Miscellanea::ProhibitUselessNoCritic]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Modules::ProhibitAutomaticExportation]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Modules::ProhibitEvilModules]
|
||||
add_themes = critic
|
||||
modules = Class::ISA Error Pod::Plainer Shell Switch
|
||||
|
||||
[Perl::Critic::Policy::Modules::ProhibitExcessMainComplexity]
|
||||
# http://en.wikipedia.org/wiki/Cyclomatic_complexity
|
||||
add_themes = critic
|
||||
max_mccabe = 20
|
||||
|
||||
[Perl::Critic::Policy::Modules::ProhibitMultiplePackages]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Modules::RequireBarewordIncludes]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Modules::RequireEndWithOne]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Objects::ProhibitIndirectSyntax]
|
||||
add_themes = critic
|
||||
# The new() subroutine is configured by default; any additional forbid values
|
||||
# are in addition to new().
|
||||
forbid = create destroy
|
||||
|
||||
[Perl::Critic::Policy::RegularExpressions::ProhibitFixedStringMatches]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::RegularExpressions::ProhibitUnusualDelimiters]
|
||||
add_themes = critic
|
||||
allow_all_brackets = 0
|
||||
|
||||
[Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline]
|
||||
add_themes = critic
|
||||
allow_all_brackets = 0
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms]
|
||||
# Read the CAVEATS.
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity]
|
||||
# http://en.wikipedia.org/wiki/Cyclomatic_complexity
|
||||
add_themes = critic
|
||||
max_mccabe = 20
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef]
|
||||
# http://perlmonks.org/index.pl?node_id=741847
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitManyArgs]
|
||||
add_themes = critic
|
||||
max_arguments = 5
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitNestedSubs]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitReturnSort]
|
||||
# KNOWN BUGS: This Policy is not sensitive to the wantarray() function.
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitSubroutinePrototypes]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProhibitUnusedPrivateSubroutines]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::ProtectPrivateSubs]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::RequireArgUnpacking]
|
||||
add_themes = critic
|
||||
allow_delegation_to = SUPER:: NEXT::
|
||||
allow_subscripts = 0
|
||||
short_subroutine_statements = 0
|
||||
|
||||
[Perl::Critic::Policy::Subroutines::RequireFinalReturn]
|
||||
add_themes = critic
|
||||
terminal_funcs = return carp croak die exec exit goto throw
|
||||
|
||||
[Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict]
|
||||
add_themes = critic
|
||||
allow = refs
|
||||
|
||||
[Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings]
|
||||
add_themes = critic
|
||||
allow_with_category_restriction = 1
|
||||
|
||||
[Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride]
|
||||
add_themes = critic
|
||||
statements = 3
|
||||
|
||||
[Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals]
|
||||
add_themes = critic
|
||||
allow_if_string_contains_single_quote = 1
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls]
|
||||
add_themes = critic
|
||||
max_chain_length = 3
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers]
|
||||
# Not yet configured completely.
|
||||
add_themes = critic
|
||||
allowed_values = -1 0 1
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters]
|
||||
add_themes = critic
|
||||
back_quote_allowed_operators =
|
||||
double_quote_allowed_operators =
|
||||
single_quote_allowed_operators =
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion]
|
||||
add_themes = critic
|
||||
allow_version_without_use_on_same_line = 1
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators]
|
||||
add_themes = critic
|
||||
min_value = 10000
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Variables::ProhibitLocalVars]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Variables::ProhibitMatchVars]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Variables::ProhibitUnusedVariables]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Variables::RequireInitializationForLocalVars]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Variables::RequireLexicalLoopIterators]
|
||||
add_themes = critic
|
||||
|
||||
[Perl::Critic::Policy::Variables::RequireLocalizedPunctuationVars]
|
||||
add_themes = critic
|
||||
allow =
|
||||
|
||||
[Perl::Critic::Policy::Variables::RequireNegativeIndices]
|
||||
add_themes = critic
|
4
t/.proverc
Normal file
4
t/.proverc
Normal file
@ -0,0 +1,4 @@
|
||||
--lib
|
||||
--recurse
|
||||
--shuffle
|
||||
-I.
|
4
t/.proverc-cover
Normal file
4
t/.proverc-cover
Normal file
@ -0,0 +1,4 @@
|
||||
--lib
|
||||
--recurse
|
||||
--shuffle
|
||||
-I.
|
14
t/Test/Expander/Boilerplate.pm
Normal file
14
t/Test/Expander/Boilerplate.pm
Normal file
@ -0,0 +1,14 @@
|
||||
package t::Test::Expander::Boilerplate;
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
sub new {
|
||||
my ($class, @args) = @_;
|
||||
|
||||
return bless([\@args], $class);
|
||||
}
|
||||
|
||||
1;
|
12
t/Test/Expander/NoCLASS/NoMETHOD.t
Normal file
12
t/Test/Expander/NoCLASS/NoMETHOD.t
Normal file
@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
is($CLASS, undef, 'there is no class corresponding to this test file');
|
||||
|
||||
done_testing();
|
28
t/Test/Expander/_error.t
Normal file
28
t/Test/Expander/_error.t
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env perl
|
||||
## no critic (ProtectPrivateSubs RequireLocalizedPunctuationVars)
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Expander::Constants qw($ERROR_WAS);
|
||||
use constant TEST_CASES => {
|
||||
'no exception' => { exception => '', args => [], output => '' },
|
||||
'exception raised, no replacement required' => { exception => 'ABC', args => [], output => "${ERROR_WAS}ABC" },
|
||||
'exception raised, replacement required' => { exception => 'ABC', args => [qw(B b)], output => "${ERROR_WAS}AbC" },
|
||||
};
|
||||
use Test::Builder::Tester tests => scalar(keys(%{TEST_CASES()}));
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
foreach my $title (keys(%{TEST_CASES()})) {
|
||||
test_out("ok 1 - $title");
|
||||
$@ = TEST_CASES->{$title}->{exception};
|
||||
is(
|
||||
Test::Expander::_error(@{TEST_CASES->{$title}->{args}}),
|
||||
TEST_CASES->{$title}->{output},
|
||||
$title
|
||||
);
|
||||
test_test($title);
|
||||
}
|
24
t/Test/Expander/_newTestMessage.t
Normal file
24
t/Test/Expander/_newTestMessage.t
Normal file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env perl
|
||||
## no critic (ProtectPrivateSubs RequireLocalizedPunctuationVars)
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Expander::Constants qw($NEW_FAILED $NEW_SUCCEEDED);
|
||||
use constant TEST_CASES => {
|
||||
"'new' succeeded" => { exception => '', output => $NEW_SUCCEEDED },
|
||||
"'new' failed" => { exception => 'ABC', output => $NEW_FAILED },
|
||||
};
|
||||
use Test::Builder::Tester tests => scalar(keys(%{TEST_CASES()}));
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
foreach my $title (keys(%{TEST_CASES()})) {
|
||||
test_out("ok 1 - $title");
|
||||
$@ = TEST_CASES->{$title}->{exception};
|
||||
my $expected = TEST_CASES->{$title}->{output} =~ s/%s/.*/gr;
|
||||
like(Test::Expander::_newTestMessage('CLASS'), qr/$expected/, $title);
|
||||
test_test($title);
|
||||
}
|
99
t/Test/Expander/_setEnv.t
Normal file
99
t/Test/Expander/_setEnv.t
Normal file
@ -0,0 +1,99 @@
|
||||
#!/usr/bin/env perl
|
||||
## no critic (RequireLocalizedPunctuationVars)
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use File::chdir;
|
||||
|
||||
use Test::Expander -tempdir => {}, -srand => time;
|
||||
|
||||
can_ok($CLASS, $METHOD);
|
||||
|
||||
ok(-d $TEMP_DIR, "temporary directory '$TEMP_DIR' created");
|
||||
|
||||
my $classPath = $CLASS =~ s{::}{/}gr;
|
||||
my $testPath = path($TEMP_DIR)->child('t');
|
||||
$testPath->child($classPath)->mkpath;
|
||||
|
||||
{
|
||||
local $CWD = $testPath->parent->stringify; ## no critic (ProhibitLocalVars)
|
||||
|
||||
my $testFile = path('t')->child($classPath)->child($METHOD . '.t')->stringify;
|
||||
my $envFile = path('t')->child($classPath)->child($METHOD . '.env');
|
||||
|
||||
is(Test2::Plugin::SRand->from, 'import arg', "random seed is supplied as 'time'");
|
||||
|
||||
subtest 'env variable filled from a variable' => sub {
|
||||
our $var = 'abc';
|
||||
my $name = 'ABC';
|
||||
my $value = '$' . __PACKAGE__ . '::var';
|
||||
$envFile->spew("$name = $value\nJust a comment line");
|
||||
%ENV = (xxx => 'yyy');
|
||||
|
||||
ok(lives { $METHOD_REF->($METHOD, $CLASS, $testFile) }, 'successfully executed');
|
||||
is(\%ENV, { $name => lc($name) }, "'%ENV' has the expected content");
|
||||
};
|
||||
|
||||
subtest 'env variable filled by a self-implemented sub' => sub {
|
||||
my $name = 'ABC';
|
||||
my $value = __PACKAGE__ . "::testEnv(lc('$name'))";
|
||||
$envFile->spew("$name = $value");
|
||||
%ENV = (xxx => 'yyy');
|
||||
|
||||
ok(lives { $METHOD_REF->($METHOD, $CLASS, $testFile) }, 'successfully executed');
|
||||
is(\%ENV, { $name => lc($name) }, "'%ENV' has the expected content");
|
||||
};
|
||||
|
||||
subtest "env variable filled by a 'File::Temp::tempdir'" => sub {
|
||||
my $name = 'ABC';
|
||||
my $value = 'File::Temp::tempdir';
|
||||
$envFile->spew("$name = $value");
|
||||
%ENV = (xxx => 'yyy');
|
||||
|
||||
ok(lives { $METHOD_REF->($METHOD, $CLASS, $testFile) }, 'successfully executed');
|
||||
is([ keys(%ENV) ], [ $name ], "'%ENV' has the expected keys");
|
||||
ok(-d $ENV{$name}, 'temporary directory exists');
|
||||
};
|
||||
|
||||
subtest 'env file does not exist' => sub {
|
||||
$envFile->remove;
|
||||
%ENV = (xxx => 'yyy');
|
||||
|
||||
ok(lives { $METHOD_REF->($METHOD, $CLASS, $testFile) }, 'successfully executed');
|
||||
is(\%ENV, { xxx => 'yyy' }, "'%ENV' remained unchanged");
|
||||
};
|
||||
|
||||
subtest 'directory structure does not correspond to class hierarchy' => sub {
|
||||
$envFile->remove;
|
||||
%ENV = (xxx => 'yyy');
|
||||
|
||||
ok(lives { $METHOD_REF->($METHOD, 'ABC::' . $CLASS, $testFile) }, 'successfully executed');
|
||||
is(\%ENV, { xxx => 'yyy' }, "'%ENV' remained unchanged");
|
||||
};
|
||||
|
||||
subtest 'env files exist on multiple levels' => sub {
|
||||
path($envFile->parent . '.env')->spew("A = '1'\nB = '2'");
|
||||
path($envFile->parent->parent . '.env')->spew("C = '0'");
|
||||
$envFile->spew("C = '3'");
|
||||
%ENV = (xxx => 'yyy');
|
||||
|
||||
local $CWD = $TEMP_DIR; ## no critic (ProhibitLocalVars)
|
||||
ok(lives { $METHOD_REF->($METHOD, $CLASS, $testFile) }, 'successfully executed');
|
||||
is(\%ENV, { A => '1', B => '2', C => '3' }, "'%ENV' has the expected content");
|
||||
};
|
||||
|
||||
subtest 'env file invalid' => sub {
|
||||
my $name = 'ABC';
|
||||
my $value = 'abc->';
|
||||
$envFile->spew("$name = $value");
|
||||
|
||||
like(dies { $METHOD_REF->($METHOD, $CLASS, $testFile) }, qr/syntax error/, 'expected exception raised');
|
||||
};
|
||||
}
|
||||
|
||||
done_testing();
|
||||
|
||||
sub testEnv { return $_[0] } ## no critic (RequireArgUnpacking)
|
22
t/Test/Expander/_useImports.t
Normal file
22
t/Test/Expander/_useImports.t
Normal file
@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env perl
|
||||
## no critic (ProtectPrivateSubs)
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use constant TEST_CASES => {
|
||||
'module version required' => { input => [ '1.22.333' ], output => ' 1.22.333' },
|
||||
'single import but not a module version' => { input => [ 'x' ], output => '' },
|
||||
'multiple imports' => { input => [ qw(x y) ], output => '' },
|
||||
};
|
||||
use Test::Builder::Tester tests => scalar(keys(%{TEST_CASES()}));
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
foreach my $title (keys(%{TEST_CASES()})) {
|
||||
test_out("ok 1 - $title");
|
||||
is(Test::Expander::_useImports(TEST_CASES->{$title}->{input}), TEST_CASES->{$title}->{output}, $title);
|
||||
test_test($title);
|
||||
}
|
16
t/Test/Expander/compare_ok.t
Normal file
16
t/Test/Expander/compare_ok.t
Normal file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Builder::Tester tests => 1;
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
my $dir = path(__FILE__)->parent->child($METHOD);
|
||||
my $title = 'execution';
|
||||
test_out("ok 1 - $title");
|
||||
compare_ok($dir->child('got'), $dir->child('expected'), $title);
|
||||
test_test($title);
|
2
t/Test/Expander/compare_ok/expected
Normal file
2
t/Test/Expander/compare_ok/expected
Normal file
@ -0,0 +1,2 @@
|
||||
A
|
||||
BC
|
2
t/Test/Expander/compare_ok/got
Normal file
2
t/Test/Expander/compare_ok/got
Normal file
@ -0,0 +1,2 @@
|
||||
A
|
||||
BC
|
15
t/Test/Expander/dies_ok.t
Normal file
15
t/Test/Expander/dies_ok.t
Normal file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Builder::Tester tests => 1;
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
my $title = 'execution';
|
||||
test_out("ok 1 - $title");
|
||||
dies_ok(sub { die() }, $title);
|
||||
test_test($title);
|
98
t/Test/Expander/import.t
Normal file
98
t/Test/Expander/import.t
Normal file
@ -0,0 +1,98 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
my (@functions, @variables);
|
||||
BEGIN {
|
||||
use Const::Fast;
|
||||
use File::Temp qw(tempdir tempfile);
|
||||
use Path::Tiny qw(cwd path);
|
||||
use Test::Output;
|
||||
use Test::Warn;
|
||||
use Test2::Tools::Explain;
|
||||
use Test2::V0;
|
||||
@functions = (
|
||||
@{Const::Fast::EXPORT},
|
||||
@{Test::Files::EXPORT},
|
||||
@{Test::Output::EXPORT},
|
||||
@{Test::Warn::EXPORT},
|
||||
@{Test2::Tools::Explain::EXPORT},
|
||||
@{Test2::V0::EXPORT},
|
||||
qw(tempdir tempfile),
|
||||
qw(cwd path),
|
||||
qw(BAIL_OUT dies_ok is_deeply lives_ok new_ok require_ok use_ok),
|
||||
);
|
||||
@variables = qw($CLASS $METHOD $METHOD_REF $TEMP_DIR $TEMP_FILE);
|
||||
}
|
||||
|
||||
use Scalar::Readonly qw(readonly_off);
|
||||
use Test::Builder::Tester tests => @functions + @variables + 4;
|
||||
|
||||
use Test::Expander -target => 'Test::Expander',
|
||||
-tempdir => { CLEANUP => 1 },
|
||||
-tempfile => { UNLINK => 1 };
|
||||
use Test::Expander::Constants qw($INVALID_VALUE $UNKNOWN_OPTION);
|
||||
|
||||
foreach my $function (sort @functions) {
|
||||
my $title = "$CLASS->can('$function')";
|
||||
test_out("ok 1 - $title");
|
||||
can_ok($CLASS, $function);
|
||||
test_test($title);
|
||||
}
|
||||
|
||||
foreach my $variable (sort @variables) {
|
||||
my $title = "$CLASS exports '$variable'";
|
||||
test_out("ok 1 - $title");
|
||||
ok(eval("defined($variable)"), $title); ## no critic (ProhibitStringyEval)
|
||||
test_test($title);
|
||||
}
|
||||
|
||||
my $title;
|
||||
my $expected;
|
||||
|
||||
$title = "invalid option value of '-tempdir'";
|
||||
$expected = $INVALID_VALUE =~ s/%s/.+/gr;
|
||||
readonly_off($CLASS);
|
||||
readonly_off($METHOD);
|
||||
readonly_off($METHOD_REF);
|
||||
readonly_off($TEMP_DIR);
|
||||
readonly_off($TEMP_FILE);
|
||||
test_out("ok 1 - $title");
|
||||
like(dies { $CLASS->$METHOD(-tempdir => 1) }, qr/$expected/, $title);
|
||||
test_test($title);
|
||||
|
||||
$title = "invalid option value of '-tempfile'";
|
||||
$expected = $INVALID_VALUE =~ s/%s/.+/gr;
|
||||
readonly_off($CLASS);
|
||||
readonly_off($METHOD);
|
||||
readonly_off($METHOD_REF);
|
||||
readonly_off($TEMP_DIR);
|
||||
readonly_off($TEMP_FILE);
|
||||
test_out("ok 1 - $title");
|
||||
like(dies { $CLASS->$METHOD(-tempfile => 1) }, qr/$expected/, $title);
|
||||
test_test($title);
|
||||
|
||||
$title = 'unknown option with some value';
|
||||
$expected = $UNKNOWN_OPTION =~ s/%s/.+/gr;
|
||||
readonly_off($CLASS);
|
||||
readonly_off($METHOD);
|
||||
readonly_off($METHOD_REF);
|
||||
readonly_off($TEMP_DIR);
|
||||
readonly_off($TEMP_FILE);
|
||||
test_out("ok 1 - $title");
|
||||
like(dies { $CLASS->$METHOD(unknown => 1) }, qr/$expected/, $title);
|
||||
test_test($title);
|
||||
|
||||
$title = 'unknown option without value';
|
||||
$expected = $UNKNOWN_OPTION =~ s/%s/.+/r =~ s/%s//r;
|
||||
readonly_off($CLASS);
|
||||
readonly_off($METHOD);
|
||||
readonly_off($METHOD_REF);
|
||||
readonly_off($TEMP_DIR);
|
||||
readonly_off($TEMP_FILE);
|
||||
test_out("ok 1 - $title");
|
||||
like(dies { $CLASS->$METHOD('unknown') }, qr/$expected/, $title);
|
||||
test_test($title);
|
18
t/Test/Expander/is_deeply.t
Normal file
18
t/Test/Expander/is_deeply.t
Normal file
@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Clone qw(clone);
|
||||
use Test::Builder::Tester tests => 1;
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
my $title = 'execution';
|
||||
test_out("ok 1 - $title");
|
||||
my $got = bless({A => 0, B => [(0 .. 1)]}, 'some class');
|
||||
my $expected = clone($got);
|
||||
is_deeply($got, $expected, $title);
|
||||
test_test($title);
|
15
t/Test/Expander/lives_ok.t
Normal file
15
t/Test/Expander/lives_ok.t
Normal file
@ -0,0 +1,15 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Builder::Tester tests => 1;
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
my $title = 'execution';
|
||||
test_out("ok 1 - $title");
|
||||
lives_ok(sub {}, $title);
|
||||
test_test($title);
|
24
t/Test/Expander/new_ok.t
Normal file
24
t/Test/Expander/new_ok.t
Normal file
@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use constant {
|
||||
CLASS => 't::Test::Expander::Boilerplate',
|
||||
TEST_CASES => {
|
||||
'no args' => undef,
|
||||
'args supplied' => [ 0 .. 1 ],
|
||||
},
|
||||
};
|
||||
use Test::Builder::Tester tests => scalar(keys(%{TEST_CASES()}));
|
||||
|
||||
use Test::Expander;
|
||||
use t::Test::Expander::Boilerplate;
|
||||
|
||||
foreach my $title (keys(%{TEST_CASES()})) {
|
||||
test_out("ok 1 - An object of class '@{[CLASS]}' isa '@{[CLASS]}'");
|
||||
new_ok(CLASS, TEST_CASES->{$title}, $title);
|
||||
test_test($title);
|
||||
}
|
17
t/Test/Expander/require_ok.t
Normal file
17
t/Test/Expander/require_ok.t
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Builder::Tester tests => 1;
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
use constant CLASS => 't::Test::Expander::Boilerplate';
|
||||
|
||||
my $title = "require @{[CLASS]}";
|
||||
test_out("ok 1 - $title;");
|
||||
require_ok(CLASS);
|
||||
test_test($title);
|
16
t/Test/Expander/throws_ok.t
Normal file
16
t/Test/Expander/throws_ok.t
Normal file
@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Builder::Tester tests => 1;
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
my $title = 'execution';
|
||||
test_out("ok 1 - $title");
|
||||
my $expected = 'DIE TEST';
|
||||
throws_ok(sub { die($expected) }, $expected, $title);
|
||||
test_test($title);
|
17
t/Test/Expander/use_ok.t
Normal file
17
t/Test/Expander/use_ok.t
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env perl
|
||||
|
||||
use v5.14;
|
||||
use warnings
|
||||
FATAL => qw(all),
|
||||
NONFATAL => qw(deprecated exec internal malloc newline once portable redefine recursion uninitialized);
|
||||
|
||||
use Test::Builder::Tester tests => 1;
|
||||
|
||||
use Test::Expander;
|
||||
|
||||
use constant CLASS => 't::Test::Expander::Boilerplate';
|
||||
|
||||
my $title = "use @{[CLASS]}";
|
||||
test_out("ok 1 - $title;");
|
||||
use_ok(CLASS);
|
||||
test_test($title);
|
Reference in New Issue
Block a user