Test-Expander-2.5.1/0000755000175100017540000000000014664645404013254 5ustar jurijjurijTest-Expander-2.5.1/t/0000755000175100017540000000000014664645404013517 5ustar jurijjurijTest-Expander-2.5.1/t/Test/0000755000175100017540000000000014664645404014436 5ustar jurijjurijTest-Expander-2.5.1/t/Test/Expander/0000755000175100017540000000000014664645404016204 5ustar jurijjurijTest-Expander-2.5.1/t/Test/Expander/NoCLASS/0000755000175100017540000000000014664645404017346 5ustar jurijjurijTest-Expander-2.5.1/t/Test/Expander/NoCLASS/MyModule.pm0000644000175100017540000000036414457002760021432 0ustar jurijjurijpackage t::Test::Expander::NoCLASS::MyModule; use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); sub my_func { return close( 1 ) } 1; Test-Expander-2.5.1/t/Test/Expander/NoCLASS/NoMETHOD_only.t0000644000175100017540000000061614510062076022040 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -target => 'Test::Expander'; plan( 2 ); ok( exists( $main::{ CLASS } ), 'there is a class corresponding to this test file' ); ok( !exists( $main::{ METHOD } ), 'there is no method corresponding to this test file' ); Test-Expander-2.5.1/t/Test/Expander/NoCLASS/mock_builtin.t0000644000175100017540000000102014457161566022205 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Builder::Tester tests => 1; use FindBin; use lib "$FindBin::Bin/../../../.."; my $title = "mock 'close'"; use Test::Expander -builtins => { close => sub { $title } }, -method => 'my_func', -target => 't::Test::Expander::NoCLASS::MyModule'; test_out( "ok 1 - $title" ); is( $METHOD_REF->(), $title, $title ); test_test( $title ); done_testing(); Test-Expander-2.5.1/t/Test/Expander/NoCLASS/NoMETHOD.t0000644000175100017540000000043014510062057020770 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; plan( 1 ); ok( !exists( $main::{ CLASS } ), 'there is no class corresponding to this test file' ); Test-Expander-2.5.1/t/Test/Expander/_error.t0000644000175100017540000000204114560462230017643 0ustar jurijjurij## no critic (ProtectPrivateSubs RequireLocalizedPunctuationVars) use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander::Constants qw( $MSG_ERROR_WAS ); use constant TEST_CASES => { 'no exception' => { exception => '', args => [], output => '' }, 'exception raised, no replacement required' => { exception => 'ABC', args => [], output => $MSG_ERROR_WAS . 'ABC' }, 'exception raised, replacement required' => { exception => 'ABC', args => [ qw( B b ) ], output => $MSG_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 ); } Test-Expander-2.5.1/t/Test/Expander/dies_ok.t0000644000175100017540000000051014446063053017772 0ustar jurijjurijuse strict; 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 ); Test-Expander-2.5.1/t/Test/Expander/_new_test_message.t0000644000175100017540000000155114445373060022057 0ustar jurijjurij## no critic (ProtectPrivateSubs RequireLocalizedPunctuationVars) use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander::Constants qw( $FMT_NEW_FAILED $FMT_NEW_SUCCEEDED ); use constant TEST_CASES => { "'new' succeeded" => { exception => '', output => $FMT_NEW_SUCCEEDED }, "'new' failed" => { exception => 'ABC', output => $FMT_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::_new_test_message( 'CLASS' ), qr/$expected/, $title ); test_test( $title ); } Test-Expander-2.5.1/t/Test/Expander/restore_failure_handler.t0000644000175100017540000000035114536344706023256 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; plan( 1 ); lives_ok { $CLASS->$METHOD } 'executed'; Test-Expander-2.5.1/t/Test/Expander/is_deeply.t0000644000175100017540000000073214436615157020347 0ustar jurijjurijuse strict; 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 $got = bless( { A => 0, B => [ ( 0 .. 1 ) ] }, 'some class' ); my $expected = bless( { A => 0, B => [ ( 0 .. 1 ) ] }, 'some class' ); is_deeply( $got, $expected, $title ); test_test( $title ); Test-Expander-2.5.1/t/Test/Expander/import.t0000644000175100017540000002363014664644416017711 0ustar jurijjurijuse strict; 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 Test2::Tools::Explain; use Test2::V0; @functions = ( @{ Const::Fast::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 $TEST_FILE ); } use Term::ANSIColor qw( colored ); use Scalar::Readonly qw( readonly_off ); use Test::Builder::Tester tests => @functions + @variables + ( exists( $ENV{ HARNESS_PERL_SWITCHES } ) ? 12 : 17 ); # use Test::Builder::Tester tests => @functions + @variables + 17; use Test::Expander -target => 'Test::Expander', -tempdir => { CLEANUP => 1 }, -tempfile => { UNLINK => 1 }; use Test::Expander::Constants qw( $FMT_INVALID_DIRECTORY $FMT_INVALID_VALUE $FMT_SET_TO $FMT_REQUIRE_DESCRIPTION $FMT_UNKNOWN_OPTION $NOTE ); 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, $expected ); $title = "invalid value type of '-builtins'"; $expected = $FMT_INVALID_VALUE =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -builtins => [] ) } qr/$expected/, $title; test_test( $title ); $title = 'invalid type of a particular builtin mock'; $expected = $FMT_INVALID_VALUE =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -builtins => { xxx => 'yyy' } ) } qr/$expected/, $title; test_test( $title ); $title = "invalid value type of '-lib'"; $expected = $FMT_INVALID_VALUE =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -lib => {} ) } qr/$expected/, $title; test_test( $title ); $title = "invalid directory type within '-lib'"; $expected = $FMT_INVALID_DIRECTORY =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -lib => [ {} ] ) } qr/$expected/, $title; test_test( $title ); $title = "invalid directory value within '-lib'"; $expected = $FMT_INVALID_DIRECTORY =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -lib => [ 'ref(' ] ) } qr/$expected/, $title; test_test( $title ); path( $TEMP_DIR )->child( 'my_root' )->mkdir; path( $TEMP_DIR )->child( qw( my_root foo.pm ) )->spew( "package foo;\n1;\n" ); $title = "valid value of '-lib' containing expression to be substituted, '-bail' set (successfully executed)"; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); { my $mock_importer = mock 'Importer' => ( override => [ import_into => sub {} ] ); my $mock_test2 = mock 'Test2::V0' => ( override => [ import => sub {} ] ); my $mock_this = mock $CLASS => ( override => [ _export_symbols => sub {} ] ); is( $CLASS->$METHOD( -lib => [ 'path( $TEMP_DIR )->child( qw( my_root ) )->stringify' ], -bail => 1 ), undef, $title ); } test_test( $title ); $title = sprintf( $FMT_REQUIRE_DESCRIPTION, 'foo', '' ); test_out( "ok 1 - $title" ); require_ok( 'foo', $title ); test_test( $title ); $title = "invalid value of '-method'"; $expected = $FMT_INVALID_VALUE =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -method => {} ) } qr/$expected/, $title; test_test( $title ); $title = "invalid value of '-tempdir'"; $expected = $FMT_INVALID_VALUE =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -tempdir => 1 ) } qr/$expected/, $title; test_test( $title ); $title = "invalid value of '-tempfile'"; $expected = $FMT_INVALID_VALUE =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( -tempfile => 1 ) } qr/$expected/, $title; test_test( $title ); $title = 'unknown option with some value'; $expected = $FMT_UNKNOWN_OPTION =~ s/%s/.+/gr; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( unknown => 1 ) } qr/$expected/, $title; test_test( $title ); $title = 'unknown option without value'; $expected = $FMT_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 ); readonly_off( $TEST_FILE ); test_out( "ok 1 - $title" ); throws_ok { $CLASS->$METHOD( 'unknown' ) } qr/$expected/, $title; test_test( $title ); # For reasons I do not understand, yet, unless ( exists( $ENV{ HARNESS_PERL_SWITCHES } ) ) { # this fails during coverage evaluation $title = "valid '-method', '-target' => undef (return value)"; $expected = undef; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( join( "\n", sprintf( "# $FMT_SET_TO", '$CLASS', $CLASS ), sprintf( "# $FMT_SET_TO", '$TEMP_DIR', $TEMP_DIR ), sprintf( "# $FMT_SET_TO", '$TEMP_FILE', $TEMP_FILE ), sprintf( "# $FMT_SET_TO", '$TEST_FILE', path( __FILE__ )->absolute ), "ok 1 - $title", ) ); { my $mock_importer = mock 'Importer' => ( override => [ import_into => sub {} ] ); my $mock_test2 = mock 'Test2::V0' => ( override => [ import => sub {} ] ); is( dies { $CLASS->$METHOD( -color => { exported => undef, unexported => undef }, -method => 'dummy', -target => undef ) }, $expected, $title ); } test_test( $title ); $title = "undetectable '-method' (method name unassigned)"; $expected = undef; test_out( "ok 1 - $title" ); is( $METHOD, $expected, $title ); test_test( $title ); $title = "omitted '-method', '-target' => undef (return value)"; $expected = undef; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); test_out( join( "\n", sprintf( "# $FMT_SET_TO", colored( '$CLASS', 'green' ), $CLASS ), sprintf( "# $FMT_SET_TO", colored( '$TEMP_DIR', 'green' ), $TEMP_DIR ), sprintf( "# $FMT_SET_TO", colored( '$TEMP_FILE', 'green' ), $TEMP_FILE ), sprintf( "# $FMT_SET_TO", colored( '$TEST_FILE', 'green' ), path( __FILE__ )->absolute ), "ok 1 - $title", ) ); { my $mock_importer = mock 'Importer' => ( override => [ import_into => sub {} ] ); my $mock_test2 = mock 'Test2::V0' => ( override => [ import => sub {} ] ); is( dies { $CLASS->import( -color => { exported => 'green', unexported => 'red' }, -method => undef, -target => undef ) }, $expected, $title ); } test_test( $title ); $title = "omitted '-method', '-target' => undef (assigned method name)"; $expected = undef; test_out( "ok 1 - $title" ); is( $METHOD, $expected, $title ); test_test( $title ); $title = "test file absent (command line option '-e' simulated)"; readonly_off( $CLASS ); readonly_off( $METHOD ); readonly_off( $METHOD_REF ); readonly_off( $TEMP_DIR ); readonly_off( $TEMP_FILE ); readonly_off( $TEST_FILE ); $CLASS = $METHOD = $METHOD_REF = $TEMP_DIR = $TEMP_FILE = $TEST_FILE = undef; no warnings qw( once ); test_out( sprintf( '# ' . $Test::Expander::FMT_UNSET_VAR, colored( '$CLASS', 'red' ) ), "ok 1 - $title" ); { my $mock_PathTiny = mock 'Path::Tiny' => ( override => [ exists => sub {} ] ); my $mock_importer = mock 'Importer' => ( override => [ import_into => sub {} ] ); my $mock_test2 = mock 'Test2::V0' => ( override => [ import => sub {} ] ); my $mock_this = mock 'Test::Expander' => ( override => [ _export_rest_symbols => sub {}, _mock_builtins => sub {}, _parse_options => sub { {} }, _set_env => sub {}, ] ); is( Test::Expander->import( -target => undef ), undef, $title ); } test_test( $title ); } Test-Expander-2.5.1/t/Test/Expander/bail_on_failure.t0000644000175100017540000000035114536422214021470 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; plan( 1 ); lives_ok { $METHOD_REF->() } 'executed'; Test-Expander-2.5.1/t/Test/Expander/require_ok.t0000644000175100017540000000055614436615320020533 0ustar jurijjurijuse strict; 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 => 'IO::Select'; my $title = "require @{ [ CLASS ] }"; test_out( "ok 1 - $title;" ); require_ok( CLASS ); test_test( $title ); Test-Expander-2.5.1/t/Test/Expander/_colorize.t0000644000175100017540000000071314663151137020351 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; plan( 2 ); const my $VALUE => 'value'; my $colorizing; $colorizing = 'unknown'; is( $METHOD_REF->( $VALUE, $colorizing ), $VALUE, 'unknown colorizing' ); $colorizing = 'exported'; like( $METHOD_REF->( $VALUE, $colorizing ), qr/^.+$VALUE.+$/, 'known colorizing' ); Test-Expander-2.5.1/t/Test/Expander/_subtest_conditional.t0000644000175100017540000000207114536343446022603 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander; my $subtestSkipped; my $mock = mock 'Test2::API::Context' => ( override => [ skip => sub { ok( $subtestSkipped, 'subtest skipped' ) } ] ); plan( 3 ); subtest 'other subtest choosen' => sub { plan( 2 ); local @ARGV = ( '--subtest_number' => '1/0' ); Test::Expander::_subtest_selection(); $subtestSkipped = 1; lives_ok { $METHOD_REF->( sub { ok( !$subtestSkipped, 'subtest entered' ) }, 'name' ) } 'executed'; }; subtest 'subtest by number' => sub { plan( 2 ); local @ARGV = ( '--subtest_name' => '[A-Z]' ); Test::Expander::_subtest_selection(); $subtestSkipped = 0; lives_ok { $METHOD_REF->( sub { ok( !$subtestSkipped, 'original entered' ) }, 'name' ) } 'executed'; }; subtest 'subtest by name with any capital letter e.g. A' => sub { plan( 2 ); $subtestSkipped = 0; lives_ok { $METHOD_REF->( sub { ok( !$subtestSkipped, 'original entered' ) }, 'NAME' ) } 'executed'; }; Test-Expander-2.5.1/t/Test/Expander/use_ok.t0000644000175100017540000000054614436615404017655 0ustar jurijjurijuse strict; 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 => 'IO::Select'; my $title = "use @{ [ CLASS ] }"; test_out( "ok 1 - $title;" ); use_ok( CLASS ); test_test( $title ); Test-Expander-2.5.1/t/Test/Expander/new_ok.t0000644000175100017540000000116214440367666017656 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use constant { CLASS => 'IO::Select', TEST_CASES => { 'no args' => undef, 'args supplied' => [ 0 .. 1 ], }, }; use Test::Builder::Tester tests => scalar( keys( %{ TEST_CASES() } ) ); use Test::Expander; eval( "use @{ [ CLASS ] }" ); 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 ); } Test-Expander-2.5.1/t/Test/Expander/_determine_testee.env0000644000175100017540000000003014460720322022356 0ustar jurijjurijNEW_ENV_VAR = $TEMP_DIR Test-Expander-2.5.1/t/Test/Expander/_set_env.t0000644000175100017540000001243214510061724020160 0ustar jurijjurij## no critic (RequireLocalizedPunctuationVars) use strict; 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; use Test::Expander::Constants qw( $FMT_INVALID_ENV_ENTRY ); plan( 12 ); $METHOD //= '_set_env'; $METHOD_REF //= $CLASS->can( $METHOD ); can_ok( $CLASS, $METHOD ); ok( -d $TEMP_DIR, "temporary directory '$TEMP_DIR' created" ); my $class_path = $CLASS =~ s{::}{/}gr; my $test_path = path( $TEMP_DIR )->child( 't' ); $test_path->child( $class_path )->mkpath; { local $CWD = $test_path->parent->stringify; ## no critic (ProhibitLocalVars) my $test_file = path( 't' )->child( $class_path )->child( $METHOD . '.t' )->stringify; my $env_file = path( 't' )->child( $class_path )->child( $METHOD . '.env' ); is( Test2::Plugin::SRand->from, 'import arg', "random seed is supplied as 'time'" ); ok( lives { $METHOD_REF->( $CLASS, $test_file ) }, 'no test file detected' ); path( $test_file )->touch; subtest '1st env variable filled from a variable, 2nd one kept from %ENV, 3rd one ignored' => sub { plan( 2 ); our $var = 'abc'; my $name = 'ABC'; my $value = '$' . __PACKAGE__ . '::var'; $env_file->spew( "$name = $value\nJust a comment line\nX\nY" ); %ENV = ( XXX => 'yyy', X => 'A' ); ok( lives { $METHOD_REF->( $CLASS, $test_file ) }, 'successfully executed' ); my $expected = { $name => lc( $name ), X => 'A' }; $expected->{ PWD } = $ENV{ PWD } if exists( $ENV{ PWD } ); is( \%ENV, $expected, "'%ENV' has the expected content" ); }; subtest 'env variable filled by a self-implemented sub' => sub { plan( 2 ); my $name = 'ABC'; my $value = __PACKAGE__ . "::testEnv( lc( '$name' ) )"; $env_file->spew( "$name = $value" ); %ENV = ( XXX => 'yyy' ); ok( lives { $METHOD_REF->( $CLASS, $test_file ) }, 'successfully executed' ); my $expected = { $name => lc( $name ) }; $expected->{ PWD } = $ENV{ PWD } if exists( $ENV{ PWD } ); is( \%ENV, $expected, "'%ENV' has the expected content" ); }; subtest "env variable filled by a 'File::Temp::tempdir'" => sub { plan( 3 ); my $name = 'ABC'; my $value = 'File::Temp::tempdir'; $env_file->spew( "$name = $value" ); %ENV = ( XXX => 'yyy' ); ok( lives { $METHOD_REF->( $CLASS, $test_file ) }, 'successfully executed' ); my %expected = ( $name => $value ); $expected{ PWD } = $ENV{ PWD } if exists( $ENV{ PWD } ); is( [ sort keys( %ENV ) ], [ sort keys( %expected ) ], "'%ENV' has the expected keys" ); ok( -d $ENV{ $name }, 'temporary directory exists' ); }; subtest 'env file does not exist' => sub { plan( 2 ); $env_file->remove; %ENV = ( XXX => 'yyy' ); ok( lives { $METHOD_REF->( $CLASS, $test_file ) }, 'successfully executed' ); my $expected = { XXX => 'yyy' }; $expected->{ PWD } = $ENV{ PWD } if exists( $ENV{ PWD } ); is( \%ENV, $expected, "'%ENV' remained unchanged" ); }; subtest 'directory structure does not correspond to class hierarchy' => sub { plan( 2 ); $env_file->remove; %ENV = ( XXX => 'yyy' ); ok( lives { $METHOD_REF->( 'ABC::' . $CLASS, $test_file ) }, 'successfully executed' ); my $expected = { XXX => 'yyy' }; $expected->{ PWD } = $ENV{ PWD } if exists( $ENV{ PWD } ); is( \%ENV, $expected, "'%ENV' remained unchanged" ); }; subtest 'multiple levels of env files, cascade usage of their entries, overwrite entry' => sub { plan( 2 ); path( $env_file->parent->parent . '.env' )->spew( "C = '0'" ); path( $env_file->parent . '.env' )->spew( "A = '1'\nB = '2'\nD = \$ENV{ A } . \$ENV{ C }" ); $env_file->spew( "C = '3'" ); %ENV = ( XXX => 'yyy' ); local $CWD = $TEMP_DIR; ## no critic (ProhibitLocalVars) ok( lives { $METHOD_REF->( $CLASS, $test_file ) }, 'successfully executed' ); my $expected = { A => '1', B => '2', C => '3', D => '10' }; $expected->{ PWD } = $ENV{ PWD } if exists( $ENV{ PWD } ); is( \%ENV, $expected, "'%ENV' has the expected content" ); path( $env_file->parent->parent . '.env' )->remove; path( $env_file->parent . '.env' )->remove; }; subtest 'env file with invalid syntax' => sub { plan( 1 ); my $name = 'ABC'; my $value = 'abc->'; $env_file->spew( "$name = $value" ); my $expected = $FMT_INVALID_ENV_ENTRY =~ s/%d/0/r =~ s/%s/$env_file/r =~ s/%s/$name = $value/r =~ s/%s/.+/r; like( dies { $METHOD_REF->( $CLASS, $test_file ) }, qr/$expected/, 'expected exception raised' ); }; subtest 'env file with undefined values' => sub { plan( 1 ); my $name = 'ABC'; my $value = '$undefined'; $env_file->spew( "$name = $value" ); my $expected = $FMT_INVALID_ENV_ENTRY =~ s/%d/0/r =~ s/%s/$env_file/r =~ s/%s/$name = $value/r =~ s/%s/.+/r =~ s/(\$)/\\$1/r; like( dies { $METHOD_REF->( $CLASS, $test_file ) }, qr/$expected/m, 'expected exception raised' ); }; } sub testEnv { return $_[ 0 ] } ## no critic (RequireArgUnpacking) Test-Expander-2.5.1/t/Test/Expander/_subtest_selection.t0000644000175100017540000000205714510302634022253 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test2::V0 -target => 'Test::Expander'; use Test::Expander::Constants qw( $FMT_INVALID_SUBTEST_NUMBER ); plan( 4 ); Test2::Tools::Subtest::subtest_streamed 'enforced usage of subtest_streamed for better test coverage' => sub { plan( 1 ); local @ARGV = ( '--subtest_number' => '1/0/' ); my $expected = sprintf( $FMT_INVALID_SUBTEST_NUMBER, '1/0/' ); like( dies { Test::Expander::_subtest_selection() }, qr/$expected/, 'choose subtest by invalid number' ); }; { local @ARGV = ( '--subtest_name' => 'valid RegEx' ); is( Test::Expander::_subtest_selection(), undef, 'choose subtest by valid RegEx' ); } { local @ARGV = ( '--subtest_name' => '[invalid RegEx' ); is( Test::Expander::_subtest_selection(), undef, 'choose subtest by invalid RegEx' ); } { local @ARGV = ( '--subtest_number' => '1/0/2' ); is( Test::Expander::_subtest_selection(), undef, 'choose subtest by valid number' ); } Test-Expander-2.5.1/t/Test/Expander/_export_most_symbols.t0000644000175100017540000000144714663154332022663 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -tempfile => {}; use Scalar::Readonly qw( readonly_off ); my $mockThis = mock $CLASS => ( override => [ _export_symbols => sub {} ] ); plan( 2 ); readonly_off( $Test::Expander::TEST_FILE ); subtest 'test file exists' => sub { plan( 2 ); lives_ok { $METHOD_REF->( $TEMP_FILE ) } 'executed'; is( $Test::Expander::TEST_FILE, $TEMP_FILE, q('$TEMP_FILE' set) ); }; subtest 'test file does not exist' => sub { plan( 2 ); path( $TEMP_FILE )->remove; $Test::Expander::TEST_FILE = ''; lives_ok { $METHOD_REF->( $TEMP_FILE ) } 'executed'; is( $Test::Expander::TEST_FILE, '', q('$TEMP_FILE' not set) ); }; Test-Expander-2.5.1/t/Test/Expander/_determine_testee.t0000644000175100017540000000066314510061407022043 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -method => undef; plan( 3 ); ok( exists( $main::{ CLASS } ), 'class determined' ); ok( !exists( $main::{ METHOD } ), 'no method determined' ); ok( !exists( $ENV{ NEW_ENV_VAR } ), 'environment variable unset due to undefined value from .env file' ); Test-Expander-2.5.1/t/Test/Expander/_parse_options.t0000644000175100017540000000041314510061535021376 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Expander -target => undef; plan( 1 ); ok( !exists( $main::{ CLASS } ), 'no class determined' ); Test-Expander-2.5.1/t/Test/Expander/lives_ok.t0000644000175100017540000000131414462513543020175 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Builder::Tester tests => 2; use Test::Expander; use Test::Expander::Constants qw( $MSG_UNEXPECTED_EXCEPTION ); my $title = 'execution succeeds'; test_out( "ok 1 - $title" ); lives_ok( sub {}, $title ); test_test( $title ); $title = 'execution fails'; test_out( "ok 1 - $title" ); my $error = 'DIE TEST'; my $mock_this = mock $CLASS => ( override => [ diag => sub { is( $_[ 0 ], $MSG_UNEXPECTED_EXCEPTION . $error . "\n", $title ) }, ok => sub ($;$@) { 1 }, ], ); lives_ok { die( $error . "\n" ) } $title; test_test( $title ); Test-Expander-2.5.1/t/Test/Expander/throws_ok.t0000644000175100017540000000121414436615361020402 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Test::Builder::Tester tests => 2; use Test::Expander; my ( $expected, $title ); $title = 'RegEx expected (stringified exception comparison )'; test_out( "ok 1 - $title" ); $expected = qr/DIE TEST/; throws_ok( sub { die( $expected ) }, $expected, $title ); test_test( $title ); $title = 'scalar expected (exception class comparison)'; test_out( "ok 1 - $title" ); $expected = 'DIE_TEST'; throws_ok( sub { die( bless( {}, $expected ) ) }, $expected, $title ); test_test( $title ); Test-Expander-2.5.1/t/Test/Expander/_use_imports.t0000644000175100017540000000142414510061325021062 0ustar jurijjurijuse strict; 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::_use_imports( TEST_CASES->{ $title }->{ input } ), TEST_CASES->{ $title }->{ output }, $title ); test_test( $title ); } Test-Expander-2.5.1/t/.perlcriticrc0000644000175100017540000002317614510061264016200 0ustar jurijjurij# 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 Test-Expander-2.5.1/t/.proverc0000644000175100017540000000003214457161677015200 0ustar jurijjurij--lib --recurse --shuffle Test-Expander-2.5.1/t/.proverc-cover0000644000175100017540000000003214535572322016302 0ustar jurijjurij--lib --recurse --shuffle Test-Expander-2.5.1/Changes0000644000175100017540000000716214664645226014557 0ustar jurijjurijChangelog for Test-Expander 2.5.1 2024-08-31 - Defatalize 'define once only' warning during direct symbol table access. 2.5.0 2024-02-10 - Support control of colorization report belogning to the read-only variables $CLASS, $METHOD, and $METHOD_REF. 2.4.0 2024-02-07 - Report unset and unexported read-only variables $CLASS, $METHOD, and $METHOD_REF. 2.3.2 2023-12-21 - Improve documentation by adding of synopsis case regarding '-bail' option and explicit code blocks. 2.3.1 2023-12-18 - Adjust list of required modules, remove redundant comments. 2.3.0 2023-12-13 - Add bail on failure both as '-bail' option and as function 'bail_on_failure' accompanied by 'restore_on_failure'. 2.2.0 2023-10-08 - Stringify directory containing test file before replacement of slash with double colon avoiding blessed value in $CLASS in case there is no one double colon. - Implement support of subtest selection. 2.1.5 2023-08-02 - Skip assignment and export of $TEST_FILE variable if the command line option '-e' is used. 2.1.4 2023-07-28 - Skip assignment of environment variables in case of undefined value. 2.1.3 2023-07-27 - Fix implementation of '-target => undef'. 2.1.2 2023-07-24 - Improve documentation by introduction of CAVEATS topic. 2.1.1 2023-07-23 - Remove deprecated "given-when" statement. - Use "FindBin" module instead of ".proverc" for testers avoiding "prove". 2.1.0 2023-07-22 - Implement "builtins" option. - Support cascading usage of environment variables in .env files. 2.0.4 2023-07-14 - Fix PWD issue specific for MS Windows only. 2.0.3 2023-07-13 - Fix Kwalitee issues. 2.0.2 2023-07-11 - Increase required version of Path::Tiny to 0.125 to make possible the usage of mkdir. 2.0.1 2023-06-21 - If any of the variables $CLASS, $METHOD, $METHOD_REF, $TEMP_DIR, and $TEMP_FILE is undefined, it is not exported. - Modules Test::Cmd, Test::Files, Test::Output, and Test::Warn are no longer loaded and their functions are not exported by Test::Expander. - Unexpedted exceptions detected by "lives_ok" are logged to the screen using "diag". - Options "-lib" and "-method" introduced. - Option "-target" supports "undef" as value if no testee module should be loaded automatically. - Names of functions and variables made more perlish. 1.1.1 2022-04-10 - "no warnings qw(redundant)" replaced with "no warnings" because the category "redundant" is not supported by older Perl versions. 1.1.0 2022-04-10 - Fix version number (minor version increased due to new feature "keeping of environment variables specified in .env files without values"). 1.0.7 2022-04-09 - Allow keeping of environment variables specified in .env files without values. - Log exception in case lives_ok fails. - Fix minimum required version of Path::Tiny to 0.122. 1.0.6 2022-03-02 - throws_ok fixed properly considering the difference between RegEx and scalar as expected value. 1.0.5 2021-11-11 - Skip unit tests of $METHOD / $METHOD_REF if these variables are undefined. - Improve logging of $METHOD_REF. 1.0.4 2021-11-10 - Make unit tests independent from directory structure (avoid automated determination of $METHOD / $METHOD_REF). - Log exported and environment variables to STDOUT after their setup. 1.0.3 2021-11-07 - Use 'IO::Select' instead of self-implemented dummy class for testing. - Propagate $VERSION to the submodule. 1.0.2 2021-11-05 - Deactivate experimental features depending on Perl version. 1.0.1 2021-11-04 - Test configuration fixed. - Documentation improved. 1.0.0 2021-11-01 - Initial release Test-Expander-2.5.1/lib/0000755000175100017540000000000014664645404014022 5ustar jurijjurijTest-Expander-2.5.1/lib/Test/0000755000175100017540000000000014664645404014741 5ustar jurijjurijTest-Expander-2.5.1/lib/Test/Expander/0000755000175100017540000000000014664645404016507 5ustar jurijjurijTest-Expander-2.5.1/lib/Test/Expander/Constants.pm0000644000175100017540000000666114663150367021030 0ustar jurijjurijpackage Test::Expander::Constants; our $VERSION = '2.5.1'; ## no critic (RequireUseStrict, RequireUseWarnings) use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use B qw( svref_2object ); use Const::Fast; use Exporter qw( import ); use PadWalker qw( peek_our ); use Scalar::Readonly qw( readonly_on ); use Test2::Tools::Basic; readonly_on( $VERSION ); const our $DIE => sub { die( sprintf( $_[ 0 ], @_[ 1 .. $#_ ] ) ) }; const our $EXCEPTION_PREFIX => 'BEGIN failed--compilation aborted at '; const our $FALSE => 0; const our $FMT_INVALID_COLOR => "Color '%s' requested for %s variables is not supported\n"; const our $FMT_INVALID_DIRECTORY => "Invalid directory name / expression '%s' supplied with option '-lib'%s\n"; const our $FMT_INVALID_ENV_ENTRY => "Erroneous line %d of '%s' containing '%s': %s\n"; const our $FMT_INVALID_VALUE => "Option '%s' passed along with invalid value '%s'\n"; const our $FMT_INVALID_SUBTEST_NUMBER => "\nInvalid subtest number: '%s'\n"; const our $FMT_KEEP_ENV_VAR => "Keep environment variable '%s' containing '%s' because it is not reassigned in file '%s'"; const our $FMT_NEW_FAILED => '%s->new died.%s'; const our $FMT_NEW_SUCCEEDED => "An object of class '%s' isa '%s'"; const our $FMT_REPLACEMENT => $EXCEPTION_PREFIX . '%s line %s.'; const our $FMT_REQUIRE_DESCRIPTION => 'require %s;%s'; const our $FMT_REQUIRE_IMPLEMENTATION => 'package %s; require %s'; const our $FMT_SEARCH_PATTERN => $EXCEPTION_PREFIX . '.*$'; const our $FMT_SET_ENV_VAR => "Set environment variable '%s' to '%s' from file '%s'"; const our $FMT_SET_TO => "Set %s to '%s'"; const our $FMT_SKIP_ENV_VAR => "Skip environment variable '%s' because its value from file '%s' is undefined"; const our $FMT_UNKNOWN_OPTION => "Unknown option '%s' => '%s' supplied.\n"; const our $FMT_UNSET_VAR => "Read-only variable '%s' is not set and not imported"; const our $FMT_USE_DESCRIPTION => 'use %s;%s'; const our $FMT_USE_IMPLEMENTATION => 'package %s; use %s%s; 1'; const our $MSG_BAIL_OUT => 'Test failed.'; const our $MSG_ERROR_WAS => ' Error was: '; const our $MSG_UNEXPECTED_EXCEPTION => 'Unexpectedly caught exception: '; const our $NOTE => sub { my ( $format, @args ) = @_; note( sprintf( $format, @args ) ) }; const our $REGEX_ANY_EXTENSION => qr/ \. [^.]+ $/x; const our $REGEX_CLASS_HIERARCHY_LEVEL => qr/^( \w+ ) (?: :: ( .+ ) )?/x; const our $REGEX_TOP_DIR_IN_PATH => qr{^ ( [^/]+ ) }x; const our $REGEX_VERSION_NUMBER => qr/^ \d+ (?: \. \d+ )* $/x; const our $TRUE => 1; const our %COLORS => ( exported => 'cyan', unexported => 'magenta' ); const our %MOST_CONSTANTS_TO_EXPORT => ( '$CLASS' => sub { $_[ 0 ] }, '$TEMP_DIR' => sub { $_[ 0 ] }, '$TEMP_FILE' => sub { $_[ 0 ] }, '$TEST_FILE' => sub { $_[ 0 ] }, ); const our %REST_CONSTANTS_TO_EXPORT => ( '$METHOD' => sub { $_[ 0 ] }, '$METHOD_REF' => sub { '\&' . $_[ 1 ] . '::' . svref_2object( $_[ 0 ] )->GV->NAME }, ); push( our @EXPORT_OK, keys( %{ peek_our( 0 ) } ) ); 1; Test-Expander-2.5.1/lib/Test/Expander.pod0000644000175100017540000006761714561656741017236 0ustar jurijjurij=pod =head1 NAME B - Expansion of test functionalities that appear to be frequently used while testing. =head1 SYNOPSIS # Tries to automatically determine, which class / module and method / subroutine are to be tested, # creates neither a temporary directory, nor a temporary file: use Test::Expander; # Tries to automatically determine, which class / module and method / subroutine are to be tested. # The determined (and hence exported) values are displayed in green, # the undetermined (and hence unexported) ones in red: use Test::Expander -color => { exported => 'green', unexported => 'red' }; # Tries to automatically determine, which class / module and method / subroutine are to be tested. # Both determined and undetermined values are displayed uncolorized: use Test::Expander -color => { exported => undef, unexported => undef }; # Tries to automatically determine, which class / module and method / subroutine are to be tested, # creates both a temporary directory and a temporary file preventing their removal after execution: use Test::Expander -tempdir => { CLEANUP => 0 }, -tempfile => { UNLINK => 0 }; # Tries to automatically determine, which class / module and method / subroutine are to be tested, # creates neither a temporary directory, nor a temporary file, # passes the option '-srand' to Test2::V0 changing the random seed to the current time in seconds: use Test::Expander -srand => time; # Class is supplied explicitly, tries to automatically determine method / subroutine to be tested, # creates a temporary directory with name corresponing to the template supplied, does not create temporary file: use Test::Expander -target => 'My::Class', -tempdir => { TEMPLATE => 'my_dir.XXXXXXXX' }; # Does not try to determine, which class / module and method / subroutine are to be tested, # creates neither a temporary directory, nor a temporary file: use Test::Expander -target => undef; # Tries to automatically determine, which class / module is to be tested, # does not determine method / subroutine to be tested, # creates neither a temporary directory, nor a temporary file: use Test::Expander -method => undef; # Tries to automatically determine, which class / module is to be tested, # does not create temporary file, creates a temporary directory and # adds directories 'dir0' and 'dir1' located therein on top of the directory list used by the Perl interpreter # for search of modules to be loaded. In other words, "unshifts" these directories to the @INC array: # PLEASE CONSIDER THE SINGLE QUOTES APPLIED BELOW! use Test::Expander -lib => [ 'path( $TEMP_DIR )->child( qw( dir0 ) )->stringify', 'path( $TEMP_DIR )->child( qw( dir1 ) )->stringify', ], -tempdir => {}; # Override the builtin 'close' in the name space of explicitly supplied class / module to be tested: my $close_success; use Test::Expander -builtins => { close => sub { $close_success ? CORE::close( shift ) : 0 } }, -target => 'My::Class'; # Activates immediate stop of test execution if any assertion fails: use Test::Expander -bail => 1; =head1 DESCRIPTION The primary objective of B is to provide additional convenience while testing based on L considering boilerplate aspects that seem to be important (to the author) in notable number of cases. These are among other things: =over 2 =item Repeated application of class / module and / or method / function to be tested. This, of course, can be stored in additional variables declared somewhere at the very beginning of test. Doing so, any refactoring including renaming of this class and / or method leads to the necessity to find and then to update all test files containing these names. If, however, both of these values can be determined from the path and base name of the current test file and saved in the exported read-only variables B<$CLASS> and B<$METHOD>, the only effort necessary in case of such renaming is a single change of path and / or base name of the corresponding test file. An additional benefit of suggested approach is a better readability of tests, where chunks like Foo::Bar->baz( $arg0, $arg1 ) now look like $CLASS->$METHOD( $arg0, $arg1 ) and hence clearly manifest that this chunk is about the testee. =item The frequent necessity of introduction of temporary directory and / or temporary file usually leads to the usage of modules L or L providing the methods / funtions B and B. This, however, can significantly be simplified (and the size of test file can be reduced) requesting such introduction via the options supported by B: use Test::Expander -tempdir => {}, -tempfile => {}; =item Another fuctionality frequently used in tests relates to the work with files and directories: reading, writing, creation, etc. Because almost all features required in such cases are provided by L, some functions of this module are also exported from B. =item To provide a really environment-independent testing, we might need a possibility to run our tests in a clean environment, where only explicitly mentioned environment variables are set and environment variables from the "outside world" cannot affect the execution of tests. This can also be achieved manually by manipulation of B<%ENV> hash at the very beginning of tests. However, even ignoring the test code inflation, this might be (in fact - is) necessary in many tests belonging to one and the same module, so that a possibility to outsource the definition of test environment provided by B makes tests smaller, more maintainable, and much more reliable. =item I stole the idea of subtest selection from L. That's why the subtest selection supported by B is partially compatible with the implementation provided by L. The term "partially" means that the option C<--subtest> can only be applied to selection by name not by number. In general the subtest selection allows the execution of required subtests identified by their names and / or by their numbers before test running. At the command-line L runs your test script and the subtest selection is based on the values given to the options C<--subtest_name> (alias C<--subtest> - in the L style) and C<--subtest_number>. Both options can be applied repeatedly and mixed together so that some tests can be selected by names and other ones by numbers. In both cases the options have to be supplied as arguments to the test script. To do so separate the arguments from prove's own arguments with the arisdottle (C<::>). =item Another idea inspired by other module namely by L is the idea of immediate stop of test file execution if one of the tests fails. This feature can be applied both for the whole test file using the B<-bail> option use Test::Expander -bail => 1; and for a part of it using the functions B and B to activate and deactivate this reaction, correspondingly. =over 2 =item Selection by name The selection by name means that the value supplied along with C<--subtest_name> option is compared with all subtest names in your test and only those, which names match this value in terms of regular expression, will be executed. If this value cannot be treated as a valid regular expression, meta characters therein are properly quoted so that the RegEx match is in any case possible. Assuming the test script B contains use strict; use warnings; use Test::Expander; plan( 3 ); subtest 'my higher level subtest without RegEx meta characters in name' => sub { # some test function calls }; subtest 'my next higher level subtest' => sub { subtest 'my embedded subtest' => sub { subtest 'my deepest subtest' => sub { # some test function calls }; # some test function calls }; # some test function calls }; # some test function calls subtest 'my subtest with [' => sub { # some test function calls }; Then, if the subtest B with all embedded subtests and the subtest B should be executed, the corresponding L call can look like one of the following variants: prove -v -b t/basic.t :: --subtest_name 'next|embedded|deepest' --subtest_name '[' prove -v -b t/basic.t :: --subtest_name 'next' --subtest_name 'embedded' --subtest_name 'deepest' --subtest_name '[' This kind of subtest selection is pretty convenient but has a significant restriction: you cannot select an embedded subtest without its higher-level subtests. I.e. if you would try to run the following command prove -v -b t/basic.t :: --subtest_name 'deepest' --subtest_name '[' the subtest B including all embedded subtests will be skipped, so that even the subtest B will not be executed although this was your goal. This restriction, however, can be avoided using the subtest selection by number. =item Selection by number The selection by number means that the value supplied along with C<--subtest_number> option is the sequence of numbers representing required subtest in the test file. Let's add to the source code of B some comments illustrating the numbers of each subtest: use strict; use warnings; use Test::Expander; plan( 3 ); subtest 'my higher level subtest without RegEx meta characters in name' => sub { # subtest No. 0 # some test function calls }; subtest 'my next higher level subtest' => sub { # subtest No. 1 subtest 'my embedded subtest' => sub { # subtest No. 0 in subtest No. 1 subtest 'my deepest subtest' => sub { # subtest No. 0 in subtest No. 0 in subtest No. 1 # some test function calls }; # some test function calls }; # some test function calls }; # some test function calls subtest 'my subtest with [' => sub { # subtest No. 2 # some test function calls }; Taking this into consideration we can combine subtest numbers starting from the highest level and separate single levels by the slash sign to get the unique number of any subtest we intend to execute. Doing so, if we only want to execute the subtests B (its number is B<1/0/0>) and B (its number is B<2>), this can easily be done with the following command: prove -v -b t/basic.t :: --subtest_number '1/0/0' --subtest_number '2' =back =back B combines all advanced possibilities provided by L with some specific functions only available in the older module L (which allows a smooth migration from L-based tests to L-based ones) and handy functions from some other modules often used in test suites. Furthermore, this module allows to automatically recognize the class / module to be tested (see variable B<$CLASS> below) so that in contrast to L you do not need to specify this explicitly if the path to the test file is in accordance with the name of class / module to be tested i.e. file B corresponds to class / module B. If such automated recognition is not intended, this can be deactivated by explicitly supplied undefined class / module name along with the option C<-target>. A similar recognition is provided in regard to the method / subroutine to be tested (see variables B<$METHOD> and B<$METHOD_REF> below) if the base name (without extension) of test file is identical with the name of this method / subroutine i.e. file B corresponds to method / subroutine B. Finally, a configurable setting of specific environment variables is provided so that there is no need to hard-code this in the test itself. The following options are accepted: =over 2 =item Options specific for this module only are always expected to have values and their meaning is: =over 2 =item B<-bail> - activates immediate stop of test file execution if any test case in this file fails. The expected value is boolean. Defaults to B i.e. the execution continues even if tests fail. Even if activated, this behaviour can be deactivated at any point in the test file using the function B. =item B<-builtins> - overrides builtins in the name space of class / module to be tested. The expected value is a hash reference, where keys are the names of builtins and the values are code references overriding default behavior. =item B<-color> - controls colorization of read-only variables B<$CLASS>, B<$METHOD>, and B<$METHOD_REF> in the test notification header. The expected value is a hash reference, the only supported keys are B and B: =over 2 =item B Contains either a string describing the foreground color, in which these variables are displayed if they are being exported, or B in no colorization is required in such case. Defaults to B<'cyan'>. =item B The same as above, but for the case if these variables remains undefined and unexported. Defaults to B<'magenta'>. =back =item B<-lib> - prepends directory list used by the Perl interpreter for search of modules to be loaded (i.e. the B<@INC> array) with values supplied in form of array reference. Each element of this array is evaluated using L so that any valid expression evaluated to string is supported if it is based on modules used by B or any module loaded before. Among other things this provides a possibility to temporary expand the module search path by directories located in the temporary directory if the latter is defined with the option B<-tempdir> (see below). B<-lib> is interpreted as the very last option, that's why the variables defined by B for export e.g. B<$TEMP_DIR> can be used in the expressions determining such directories (see B above). =item B<-method> - prevents any attempt to automatically determine method / subroutine to be tested. If the value supplied along with this option is defined and found in the class / module to be test (see B<-target> below), this will be considered such method / subroutine so that the variables B<$METHOD> and B<$METHOD_REF> (see description of exported variables below) will be imported and accessible in test. If this value is B, these variables are not imported. =item B<-target> - identical to the same-named option of L and, if contains a defined value, has the same purpose namely the explicit definition of the class / module to be tested as the value. However, if its value is B, this is not passed through to L so that no class / module will be loaded and the variable B<$CLASS> will not be imported at all. =item B<-tempdir> - activates creation of a temporary directory. The value has to be a hash reference with content as explained in L. This means, you can control the creation of temporary directory by passing of necessary parameters in form of a hash reference or, if the default behavior is required, simply pass the empty hash reference as the option value. =item B<-tempfile> - activates creation of a temporary file. The value has to be a hash reference with content as explained in L. This means, you can control the creation of temporary file by passing of necessary parameters in form of a hash reference or, if the default behavior is required, simply pass the empty hash reference as the option value. =back =item All other valid options (i.e. arguments starting with the dash sign B<->) are forwarded to L along with their values. Options without values are not supported; in case of their passing an exception is raised. =item If an argument cannot be recognized as an option, an exception is raised. =back The automated recognition of name of class / module to be tested can only work if the test file is located in the corresponding subdirectory. For instance, if the class / module to be tested is I, then the folder with test files related to this class / module should be BIBIBI or BIBIBI (the name of the top-level directory in this relative name - B, or B, or B is not important) - otherwise the module name cannot be put into the exported variable B<$CLASS> and, if you want to use this variable, should be supplied as the value of B<-target>: use Test::Expander -target => 'Foo::Bar::Baz'; This recognition can explicitly be deactivated if the value of B<-target> is B, so that no class / module will be loaded and, correspondingly, the variables B<$CLASS>, B<$METHOD>, and B<$METHOD_REF> will not be exported. Furthermore, the automated recognition of the name of the method / subroutine to be tested only works if the file containing the class / module mentioned above exists and if this class / module has the method / subroutine with the same name as the test file base name without the extension. If this is the case, the exported variables B<$METHOD> and B<$METHOD_REF> contain the name of method / subroutine to be tested and its reference, correspondingly, otherwise both variables are neither evaluated nor exported. Also in this case evaluation and export of the variables B<$METHOD> and B<$METHOD_REF> can be prevented by passing of B as value of the option B<-method>: use Test::Expander -target => undef; Finally, B supports testing inside of a clean environment containing only some clearly specified environment variables required for the particular test. Names and values of these environment variables should be configured in files, which names are identical with paths to single class / module levels or the method / subroutine to be tested, and the extension is always B<.env>. For instance, if the test file name is B, the following approach is applied: =over 2 =item if the file B exists, its content is used for the initialization of the test environment, =item if the file B exists, its content is used either to extend the test environment initialized in the previous step or for its initialization if B does not exist, =item if the file B exists, its content is used either to extend the test environment initialized in one of the previous steps or for its initialization if neither B nor B exist, =item if the file B exists, its content is used either to extend the test environment initialized in one of the previous steps or for its initialization if none of B<.env> files mentioned above exist. =back If the B<.env> files existing on different levels have identical names of environment variables, the priority is the higher the later they have been detected. I.e. B in B overwrites B in B. If none of these B<.env> files exist, the environment isn't changed by B during the execution of B. An environment configuration file (B<.env> file) is a line-based text file. Its content is interpreted as follows: =over 2 =item if such files don't exist, the B<%ENV> hash remains unchanged; =item otherwise, if at least one of such files exists, those elements of the B<%ENV> hash are kept, which names are equal to names found in lines of B<.env> file without values. All remaining elements of the B<%ENV> hash gets emptied (without localization) and =over 2 =item lines not matching the RegEx B (some alphanumeric characters representing a name of environment variable, optional blanks, optionally followed by the equal sign, again optional blanks, and at least one non-blank character representing the first character of environment variable value) are skipped; =item in all other lines the value of the environment variable is everything from the first non-blank character after the equal sign until end of the line; if this value is omitted, the corresponding environment variable remains unchanged as it originally was in the B<%ENV> hash (if it existed there, of course); =item the cascading definition of environment variables can be used, which means that =over 2 =item during the evaluation of current line environment variables defined in the same file above can be applied. For example if such B<.env> file contains VAR1 = 'ABC' VAR2 = lc( $ENV{ VAR1 } ) and neither B nor B will be overwritten during the evaluation of subsequent lines in the same or other B<.env> files, the B<%ENV> hash will contain at least the following entries: VAR1 => 'ABC' VAR2 => 'abc' =item during the evaluation of current line also environment variables defined in a higher-level B<.env> file can be used. For example if B contains VAR0 = 'XYZ ' and B contains VAR1 = 'ABC' VAR2 = lc( $ENV{ VAR0 } . $ENV{ VAR1 } ) and neither B, nor B, nor B will be overwritten during the evaluation of subsequent lines in the same or other B<.env> files, the B<%ENV> hash will contain at least the following entries: VAR0 => 'XYZ ' VAR1 => 'ABC' VAR2 => 'xyz abc' =back =item the value of the environment variable (if provided) is evaluated by the L so that =over 2 =item constant values must be quoted; =item variables and subroutines must not be quoted: NAME_CONST = 'VALUE' NAME_VAR = $KNIB::App::MyApp::Constants::ABC NAME_FUNC = join(' ', $KNIB::App::MyApp::Constants::DEF) =back =back =back All environment variables set up in this manner are logged to STDOUT using L. Another common feature within test suites is the creation of a temporary directory / file used as an isolated container for some testing actions. The module options B<-tempdir> and B<-tempfile> are fully syntactically compatible with L / L. They make sure that such temporary directory / file are created after B and that their names are stored in the variables B<$TEMP_DIR> / B<$TEMP_FILE>, correspondingly. Both temporary directory and file are removed by default after execution. The following functions provided by this module are exported by default: =over 2 =item all functions exported by default from L, =item all functions exported by default from L, =item some functions exported by default from L and often used in older tests but not supported by L: =over 2 =item BAIL_OUT, =item is_deeply, =item new_ok, =item require_ok, =item use_ok. =back =item some functions exported by default from L and often used in older tests but not supported by L: =over 2 =item dies_ok, =item lives_ok, =item throws_ok. =back some functions exported by default from L and often used in older tests but not supported by L: =over 2 =item explain. =back =item function exported by default from L: =over 2 =item const. =back =item some functions exported by request from L: =over 2 =item tempdir, =item tempfile, =back =item some functions exported by request from L: =over 2 =item cwd, =item path, =back =back The following variables can be set and exported: =over 2 =item variable B<$CLASS> containing the name of the class / module to be tested if the class / module recognition is not disable and possible, =item variable B<$METHOD> containing the name of the method / subroutine to be tested if the method / subroutine recognition is not disable and possible, =item variable B<$METHOD_REF> containing the reference to the subroutine to be tested if the method / subroutine recognition is not disable and possible, =item variable B<$TEMP_DIR> containing the name of a temporary directory created at compile time if the option B<-tempdir> is supplied, =item variable B<$TEMP_FILE> containing the name of a temporary file created at compile time if the option B<-tempfile> is supplied. =item variable B<$TEST_FILE> containing the absolute name of the current test file (if any). In fact its content is identical with the content of special token L<__FILE__|https://perldoc.perl.org/functions/__FILE__>, but only in the test file itself! If, however, you need the test file name in a test submodule or in a B<.env> file belonging to this test, L<__FILE__|https://perldoc.perl.org/functions/__FILE__> can no longer be applied - whereas B<$TEST_FILE> is there. =back All variables mentioned above are read-only after their export. In this case they are logged to STDOUT using L. If any of the variables B<$CLASS>, B<$METHOD>, and B<$METHOD_REF> is undefined and hence not exported, this is reported at the very begin of test execution. =head1 CAVEATS =over 2 =item B is recommended to be the very first module in your test file. The only known exception is when some actions performed on the module level (e.g. determination of constants) rely upon results of other actions (e.g. mocking of built-ins). To explain this let us assume that your test file should globally mock the built-in B (if this is only required in the name space of class / module to be tested, the option B<-builtin> should be used instead!) to verify if the testee properly reacts both on its success and failure. For this purpose a reasonable implementation might look as follows: my $close_success; BEGIN { *CORE::GLOBAL::close = sub (*) { $close_success ? CORE::close( shift ) : 0 } } use Test::Expander; =item Array elements of the value supplied along with the option B<-lib> are evaluated using L so that constant strings would need duplicated quotes e.g. use Test::Expander -lib => [ q('my_test_lib') ]; =item If the value to be assigned to an environment variable after evaluation of an B<.env> file is undefined, such assignment is skipped. =item If B is used in one-line mode (with the B<-e> option), the variable B<$TEST_FILE> is unset and not exported. =back =head1 AUTHOR Jurij Fajnberg, =head1 BUGS Please report any bugs or feature requests through the web interface at L. =head1 COPYRIGHT AND LICENSE Copyright (c) 2021-2024 Jurij Fajnberg This program is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Test-Expander-2.5.1/lib/Test/Expander.pm0000644000175100017540000003560214664643516017055 0ustar jurijjurij## no critic ( ProhibitStringyEval ProhibitSubroutinePrototypes RequireLocalizedPunctuationVars) package Test::Expander; # The versioning is conform with https://semver.org our $VERSION = '2.5.1'; ## no critic (RequireUseStrict, RequireUseWarnings) use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); use Const::Fast; use File::chdir; use File::Temp qw( tempdir tempfile ); use Getopt::Long qw( GetOptions :config posix_default ); use Importer; use Path::Tiny qw( cwd path ); use Scalar::Readonly qw( readonly_on ); use Term::ANSIColor qw( color colored ); use Test::Builder; use Test2::API qw( context ); use Test2::API::Context qw(); use Test2::Tools::Basic; use Test2::Tools::Explain; use Test2::Tools::Subtest; use Test::Expander::Constants qw( $DIE $FALSE $FMT_INVALID_COLOR $FMT_INVALID_DIRECTORY $FMT_INVALID_ENV_ENTRY $FMT_INVALID_VALUE $FMT_INVALID_SUBTEST_NUMBER $FMT_KEEP_ENV_VAR $FMT_NEW_FAILED $FMT_NEW_SUCCEEDED $FMT_REPLACEMENT $FMT_REQUIRE_DESCRIPTION $FMT_REQUIRE_IMPLEMENTATION $FMT_SEARCH_PATTERN $FMT_SET_ENV_VAR $FMT_SET_TO $FMT_SKIP_ENV_VAR $FMT_UNSET_VAR $FMT_UNKNOWN_OPTION $FMT_USE_DESCRIPTION $FMT_USE_IMPLEMENTATION $MSG_BAIL_OUT $MSG_ERROR_WAS $MSG_UNEXPECTED_EXCEPTION $NOTE $REGEX_ANY_EXTENSION $REGEX_CLASS_HIERARCHY_LEVEL $REGEX_TOP_DIR_IN_PATH $REGEX_VERSION_NUMBER $TRUE %COLORS %MOST_CONSTANTS_TO_EXPORT %REST_CONSTANTS_TO_EXPORT ); my $ok_orig = \&Test2::API::Context::ok; my ( @subtest_names, @subtest_numbers ); my %colors = %COLORS; sub _subtest_selection { my $error; GetOptions( 'subtest_name|subtest=s' => sub { ( undef, my $opt_value ) = @_; push( @subtest_names, eval { qr/$opt_value/ } ? $opt_value : "\Q$opt_value\E" ); }, 'subtest_number=s' => sub { ( undef, my $opt_value ) = @_; $error = sprintf( $FMT_INVALID_SUBTEST_NUMBER, $opt_value ) if $opt_value !~ m{^ \d+ (?: / \d+ )* $}x; push( @subtest_numbers, $opt_value ); }, ); die( $error) if $error; my $subtest_buffered_orig = \&Test2::Tools::Subtest::subtest_buffered; my $subtest_streamed_orig = \&Test2::Tools::Subtest::subtest_streamed; no warnings qw( redefine ); *Test2::Tools::Subtest::subtest_buffered = sub { _subtest_conditional( $subtest_buffered_orig, @_ ) }; *Test2::Tools::Subtest::subtest_streamed = sub { _subtest_conditional( $subtest_streamed_orig, @_ ) }; return; } BEGIN { _subtest_selection() } use Test2::V0 qw(); readonly_on( $VERSION ); our ( $CLASS, $METHOD, $METHOD_REF, $TEMP_DIR, $TEMP_FILE, $TEST_FILE ); our @EXPORT = ( @{ Const::Fast::EXPORT }, @{ Test2::Tools::Explain::EXPORT }, @{ Test2::V0::EXPORT }, qw( tempdir tempfile ), qw( cwd path ), qw( BAIL_OUT bail_on_failure dies_ok is_deeply lives_ok new_ok require_ok restore_failure_handler throws_ok use_ok ), ); { no warnings qw( once ); *BAIL_OUT = \&bail_out; # Explicit "sub BAIL_OUT" would be untestable } sub bail_on_failure { _set_failure_handler( sub { # uncoverable subroutine bail_out( $MSG_BAIL_OUT ) # uncoverable statement } ); return; } sub dies_ok ( &;$ ) { my ( $coderef, $description ) = @_; eval { $coderef->() }; return ok( $@, $description ); } sub import { my ( $class, @exports ) = @_; my $frame_index = 0; my $test_file; while( my @current_frame = caller( $frame_index++ ) ) { $test_file = path( $current_frame[ 1 ] ) =~ s{^/}{}r; } my $options = _parse_options( \@exports, $test_file ); _export_most_symbols( $test_file ); _set_env( $options->{ -target }, $test_file ); _mock_builtins( $options ) if defined( $CLASS ) && exists( $options->{ -builtins } ); Test2::V0->import( %$options ); _export_rest_symbols(); Importer->import_into( $class, scalar( caller ), () ); return; } sub is_deeply ( $$;$@ ) { my ( $got, $expected, $title ) = @_; return is( $got, $expected, $title ); } sub lives_ok ( &;$ ) { my ( $coderef, $description ) = @_; eval { $coderef->() }; diag( $MSG_UNEXPECTED_EXCEPTION . $@ ) if $@; return ok( !$@, $description ); } sub new_ok { my ( $class, $args ) = @_; $args ||= []; my $obj = eval { $class->new( @$args ) }; ok( !$@, _new_test_message( $class ) ); return $obj; } sub require_ok { my ( $module ) = @_; my $package = caller; my $require_result = eval( sprintf( $FMT_REQUIRE_IMPLEMENTATION, $package, $module ) ); ok( $require_result, sprintf( $FMT_REQUIRE_DESCRIPTION, $module, _error() ) ); return $require_result; } sub restore_failure_handler { no warnings qw( redefine ); *Test2::API::Context::ok = $ok_orig; return; } sub throws_ok ( &$;$ ) { my ( $coderef, $expecting, $description ) = @_; eval { $coderef->() }; my $exception = $@; my $expected_type = ref( $expecting ); return $expected_type eq 'Regexp' ? like ( $exception, $expecting, $description ) : isa_ok( $exception, [ $expecting ], $description ); } sub use_ok ( $;@ ) { my ( $module, @imports ) = @_; my ( $package, $filename, $line ) = caller( 0 ); $filename =~ y/\n\r/_/; # taken over from Test::More my $require_result = eval( sprintf( $FMT_USE_IMPLEMENTATION, $package, $module, _use_imports( \@imports ) ) ); ok( $require_result, sprintf( $FMT_USE_DESCRIPTION, $module, _error( $FMT_SEARCH_PATTERN, sprintf( $FMT_REPLACEMENT, $filename, $line ) ) ) ); return $require_result; } sub _colorize { my ( $value, $export_type ) = @_; return defined( $colors{ $export_type } ) ? colored( $value, $colors{ $export_type } ) : $value; } sub _determine_testee { my ( $options, $test_file ) = @_; if ( $options->{ -lib } ) { foreach my $directory ( @{ $options->{ -lib } } ) { $DIE->( $FMT_INVALID_DIRECTORY, $directory, 'invalid type' ) if ref( $directory ); my $inc_entry = eval( $directory ); $DIE->( $FMT_INVALID_DIRECTORY, $directory, $@ ) if $@; unshift( @INC, $inc_entry ); } delete( $options->{ -lib } ); } if ( exists( $options->{ -method } ) ) { delete( $options->{ -method } ); } else { $METHOD = path( $test_file )->basename( $REGEX_ANY_EXTENSION ); } unless ( exists( $options->{ -target } ) ) { # Try to determine class / module autmatically my ( $test_root ) = $test_file =~ $REGEX_TOP_DIR_IN_PATH; my $testee = path( $test_file )->relative( $test_root )->parent; $options->{ -target } = "$testee" =~ s{/}{::}gr if grep { path( $_ )->child( $testee . '.pm' )->is_file } @INC; } if ( defined( $options->{ -target } ) ) { $CLASS = $options->{ -target }; } else { delete( $options->{ -target } ); } return $options; } sub _error { my ( $search_string, $replacement_string ) = @_; return '' if $@ eq ''; my $error = $MSG_ERROR_WAS . $@ =~ s/\n$//mr; $error =~ s/$search_string/$replacement_string/m if defined( $search_string ); return $error; } sub _export_most_symbols { my ( $test_file ) = @_; $TEST_FILE = path( $test_file )->absolute->stringify if path( $test_file )->exists; return _export_symbols( %MOST_CONSTANTS_TO_EXPORT ); } sub _export_rest_symbols { # Further export if class and method are known return _export_symbols( %REST_CONSTANTS_TO_EXPORT ) if $CLASS && $METHOD && ( $METHOD_REF = $CLASS->can( $METHOD ) ); $METHOD = undef; return; } sub _export_symbols { my %constants = @_; foreach my $name ( sort keys( %constants ) ) { # Export defined constants no strict qw( refs ); my $value = eval( "${ \$name }" ); if ( defined( $value ) ) { readonly_on( ${ __PACKAGE__ . '::' . $name =~ s/^.//r } ); push( @EXPORT, $name ); $NOTE->( $FMT_SET_TO, _colorize( $name, 'exported' ), $constants{ $name }->( $value, $CLASS ) ); } elsif ( $name =~ /^ \$ (?: CLASS | METHOD | METHOD_REF )$/x ) { $NOTE->( $FMT_UNSET_VAR, _colorize( $name, 'unexported' ) ); } } return; } sub _mock_builtins { my ( $options ) = @_; while ( my ( $sub_name, $sub_ref ) = each( %{ $options->{ -builtins } } ) ) { my $sub_full_name = $CLASS . '::' . $sub_name; no strict qw( refs ); *${ sub_full_name } = $sub_ref; } delete( $options->{ -builtins } ); return; } sub _new_test_message { my ( $class ) = @_; return $@ ? sprintf( $FMT_NEW_FAILED, $class, _error() ) : sprintf( $FMT_NEW_SUCCEEDED, $class, $class ); } sub _parse_options { ## no critic (ProhibitExcessComplexity) my ( $exports, $test_file ) = @_; my $options = {}; while ( my $option_name = shift( @$exports ) ) { $DIE->( $FMT_UNKNOWN_OPTION, $option_name, shift( @$exports ) // '' ) if $option_name !~ /^-\w/; my $option_value = shift( @$exports ); if ( $option_name eq '-bail' ) { ## no critic (ProhibitCascadingIfElse) _set_failure_handler( sub { # uncoverable subroutine bail_out( $MSG_BAIL_OUT ) # uncoverable statement } ); } elsif ( $option_name eq '-builtins' ) { $DIE->( $FMT_INVALID_VALUE, $option_name, $option_value ) if ref( $option_value ) ne 'HASH'; while ( my ( $sub_name, $sub_ref ) = each( %$option_value ) ) { $DIE->( $FMT_INVALID_VALUE, $option_name . "->{ $sub_name }", $sub_ref ) if ref( $sub_ref ) ne 'CODE'; } $options->{ $option_name } = $option_value; } elsif ( $option_name eq '-color' ) { while ( my ( $color_name, $color_value ) = each( %colors ) ) { if ( exists( $option_value->{ $color_name } ) ) { my $requested_color = $option_value->{ $color_name }; $DIE->( $FMT_INVALID_COLOR, $requested_color, $color_name ) if defined( $requested_color ) && !defined( color( $requested_color ) ); $colors{ $color_name } = $requested_color; } } foreach my $color_name ( keys( %$option_value ) ) { $DIE->( $FMT_UNKNOWN_OPTION, $option_name, $color_name ) unless exists( $colors{ $color_name } ); } } elsif ( $option_name eq '-lib' ) { $DIE->( $FMT_INVALID_VALUE, $option_name, $option_value ) if ref( $option_value ) ne 'ARRAY'; $options->{ $option_name } = $option_value; } elsif ( $option_name eq '-method' ) { $DIE->( $FMT_INVALID_VALUE, $option_name, $option_value ) if ref( $option_value ); $METHOD = $options->{ $option_name } = $option_value; } elsif ( $option_name eq '-target' ) { $options->{ $option_name } = $option_value; } elsif ( $option_name eq '-tempdir' ) { $DIE->( $FMT_INVALID_VALUE, $option_name, $option_value ) if ref( $option_value ) ne 'HASH'; $TEMP_DIR = tempdir( CLEANUP => 1, %$option_value ); } elsif ( $option_name eq '-tempfile' ) { $DIE->( $FMT_INVALID_VALUE, $option_name, $option_value ) if ref( $option_value ) ne 'HASH'; my $file_handle; ( $file_handle, $TEMP_FILE ) = tempfile( UNLINK => 1, %$option_value ); } else { $options->{ $option_name } = $option_value; } } return _determine_testee( $options, $test_file ); } sub _read_env_file { my ( $env_file ) = @_; my @lines = path( $env_file )->lines( { chomp => 1 } ); my %env; while ( my ( $index, $line ) = each( @lines ) ) { ## no critic (ProhibitUnusedCapture) next unless $line =~ /^ (? \w+) \s* (?: = \s* (? \S .*) | $ )/x; my ( $name, $value ) = @+{ qw( name value ) }; if ( exists( $+{ value } ) ) { my $stricture = q{ use strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline once portable redefine recursion uninitialized ); }; $value = eval { eval( $stricture . '$value' ); die( $@ ) if $@; # uncoverable branch true $value = eval( $stricture . $value ); die( $@ ) if $@; $value; }; $DIE->( $FMT_INVALID_ENV_ENTRY, $index, $env_file, $line, $@ =~ s/\n//gr =~ s/ at \(eval .+//ir ) if $@; if ( defined( $value ) ) { $NOTE->( $FMT_SET_ENV_VAR, _colorize( $name, 'exported' ), $value, $env_file ); $ENV{ $name } = $env{ $name } = $value; } else { $NOTE->( $FMT_SKIP_ENV_VAR, _colorize( $name, 'unexported' ), $env_file ); } } elsif ( exists( $ENV{ $+{ name } } ) ) { $env{ $name } = $ENV{ $name }; $NOTE->( $FMT_KEEP_ENV_VAR, _colorize( $name, 'exported' ), $ENV{ $name }, $env_file ); } } return \%env; } sub _set_env { my ( $class, $test_file ) = @_; return unless path( $test_file )->exists; my $env_found = $FALSE; my $new_env = {}; { local $CWD = $test_file =~ s{/.*}{}r; ## no critic (ProhibitLocalVars) ( $env_found, $new_env ) = _set_env_hierarchically( $class, $env_found, $new_env ); } my $env_file = $test_file =~ s/$REGEX_ANY_EXTENSION/.env/r; if ( path( $env_file )->is_file ) { $env_found = $TRUE unless $env_found; my $method_env = _read_env_file( $env_file ); @$new_env{ keys( %$method_env ) } = values( %$method_env ); } %ENV = %$new_env if $env_found; return; } sub _set_env_hierarchically { my ( $class, $env_found, $new_env ) = @_; return ( $env_found, $new_env ) unless $class; my $class_top_level; ( $class_top_level, $class ) = $class =~ $REGEX_CLASS_HIERARCHY_LEVEL; return ( $FALSE, {} ) unless path( $class_top_level )->is_dir; my $env_file = $class_top_level . '.env'; if ( path( $env_file )->is_file ) { $env_found = $TRUE unless $env_found; $new_env = { %$new_env, %{ _read_env_file( $env_file ) } }; } local $CWD = $class_top_level; ## no critic (ProhibitLocalVars) return _set_env_hierarchically( $class, $env_found, $new_env ); } sub _set_failure_handler { my $action = shift; no warnings qw( redefine ); *Test2::API::Context::ok = sub { my ( undef, $pass ) = @_; my $result = $ok_orig->( @_ ); $action->() unless $pass; # uncoverable branch true return $result; }; return; } sub _subtest_conditional { my ( $orig_subtest, $name, @rest ) = @_; my $ctx = context(); my $number = join( '/', map { $_->count } @{ $ctx->stack } ); if ( !@subtest_names && !@subtest_numbers || ( grep { $name =~ /$_/ } @subtest_names ) || ( grep { /^$number/ } @subtest_numbers ) ) { $orig_subtest->( $name, @rest ); $ctx->release; } else { $ctx->skip( 'forced by ' . __PACKAGE__ ); $ctx->release; } return; } sub _use_imports { my ( $imports ) = @_; return @$imports == 1 && $imports->[ 0 ] =~ $REGEX_VERSION_NUMBER ? ' ' . $imports->[ 0 ] : ''; } 1; Test-Expander-2.5.1/lib/.perlcriticrc0000644000175100017540000002653514140010270016473 0ustar jurijjurij# 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 "knib". severity = brutal theme = knib verbose = %f: %m at line %l, column %c. (Policy: %p)\n [Perl::Critic::Policy::BuiltinFunctions::ProhibitLvalueSubstr] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitStringyEval] add_themes = knib allow_includes = 1 [Perl::Critic::Policy::BuiltinFunctions::ProhibitStringySplit] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalCan] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitUniversalIsa] add_themes = knib [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 = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidGrep] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::ProhibitVoidMap] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::RequireBlockGrep] add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::RequireBlockMap] add_themes = knib # 14.01.2016 policy disabled after a discussion with the team #[BuiltinFunctions::RequireGlobFunction] #add_themes = knib [Perl::Critic::Policy::BuiltinFunctions::RequireSimpleSortBlock] add_themes = knib [Perl::Critic::Policy::ClassHierarchies::ProhibitExplicitISA] # Note: Some people prefer parent over base. add_themes = knib [Perl::Critic::Policy::CodeLayout::ProhibitHardTabs] add_themes = knib allow_leading_tabs = 0 # 14.01.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::CodeLayout::ProhibitQuotedWordLists] #add_themes = knib #min_elements = 1 #strict = 1 [Perl::Critic::Policy::CodeLayout::ProhibitTrailingWhitespace] add_themes = knib [Perl::Critic::Policy::CodeLayout::RequireConsistentNewlines] add_themes = knib # 14.01.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::CodeLayout::RequireTrailingCommas] #add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitCStyleForLoops] add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitCascadingIfElse] add_themes = knib max_elsif = 1 [Perl::Critic::Policy::ControlStructures::ProhibitDeepNests] # Martin Fowler's book "Refactoring: Improving The Design of Existing Code". add_themes = knib max_nests = 5 [Perl::Critic::Policy::ControlStructures::ProhibitLabelsWithSpecialBlockNames] add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitMutatingListFunctions] # Read the LIMITATIONS that this policy has. add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitNegativeExpressionsInUnlessAndUntilConditions] add_themes = knib [Perl::Critic::Policy::ControlStructures::ProhibitUnreachableCode] add_themes = knib # Available With Perl::Critic v1.126 #[Perl::Critic::Policy::ControlStructures::ProhibitYadaOperator] #add_themes = knib [Perl::Critic::Policy::Documentation::PodSpelling] add_themes = # "spell" is the spell checker avalable on our AIX system. The default spell # checker "aspell" was not available. spell_command = spell #stop_words = ... stop_words_file = PodSpelling_stop_words.txt [Perl::Critic::Policy::Documentation::RequirePackageMatchesPodName] add_themes = knib #[Perl::Critic::Policy::Documentation::RequirePodSections] #add_themes = knib # 14.01.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::ErrorHandling::RequireCheckingReturnValueOfEval] #add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitBacktickOperators] add_themes = knib # 14.01.2016 policy configuration changed after a discussion with the team only_in_void_context = 1 [Perl::Critic::Policy::InputOutput::ProhibitBarewordFileHandles] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitExplicitStdin] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitInteractiveTest] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitJoinedReadline] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitReadlineInForLoop] add_themes = knib [Perl::Critic::Policy::InputOutput::ProhibitTwoArgOpen] add_themes = knib [Perl::Critic::Policy::InputOutput::RequireBriefOpen] # http://www.perlmonks.org/?node_id=1134785 add_themes = knib lines = 9 [Perl::Critic::Policy::InputOutput::RequireCheckedSyscalls] # Covers the policies # Perl::Critic::Policy::InputOutput::RequireCheckedClose and # Perl::Critic::Policy::InputOutput::RequireCheckedOpen add_themes = knib exclude_functions = print say functions = :builtins [Perl::Critic::Policy::InputOutput::RequireEncodingWithUTF8Layer] add_themes = knib [Perl::Critic::Policy::Miscellanea::ProhibitUnrestrictedNoCritic] add_themes = knib [Perl::Critic::Policy::Miscellanea::ProhibitUselessNoCritic] add_themes = knib [Perl::Critic::Policy::Modules::ProhibitAutomaticExportation] add_themes = knib [Perl::Critic::Policy::Modules::ProhibitConditionalUseStatements] add_themes = knib [Perl::Critic::Policy::Modules::ProhibitEvilModules] add_themes = knib modules = Class::ISA Error Pod::Plainer Shell Switch [Perl::Critic::Policy::Modules::ProhibitExcessMainComplexity] # http://en.wikipedia.org/wiki/Cyclomatic_complexity add_themes = knib max_mccabe = 20 [Perl::Critic::Policy::Modules::ProhibitMultiplePackages] add_themes = knib [Perl::Critic::Policy::Modules::RequireBarewordIncludes] add_themes = knib [Perl::Critic::Policy::Modules::RequireEndWithOne] add_themes = knib [Perl::Critic::Policy::Modules::RequireExplicitPackage] add_themes = knib allow_import_of = utf8 exempt_scripts = 0 [Perl::Critic::Policy::Modules::RequireFilenameMatchesPackage] add_themes = knib [Perl::Critic::Policy::Modules::RequireNoMatchVarsWithUseEnglish] add_themes = knib [Perl::Critic::Policy::Modules::RequireVersionVar] # Read the TO DO section of this policy and think about its implication. add_themes = knib # Perl::Critic::Policy::NamingConventions::Capitalization # It takes some time to configure this policy! [Perl::Critic::Policy::Objects::ProhibitIndirectSyntax] add_themes = knib # 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 = knib [Perl::Critic::Policy::RegularExpressions::ProhibitSingleCharAlternation] add_themes = knib [Perl::Critic::Policy::RegularExpressions::ProhibitUnusedCapture] add_themes = knib # 14.01.2016 policy still enabled after a discussion with the team [Perl::Critic::Policy::RegularExpressions::ProhibitUnusualDelimiters] add_themes = knib allow_all_brackets = 0 [Perl::Critic::Policy::RegularExpressions::ProhibitUselessTopic] add_themes = knib [Perl::Critic::Policy::RegularExpressions::RequireBracesForMultiline] add_themes = knib allow_all_brackets = 0 [Perl::Critic::Policy::Subroutines::ProhibitAmpersandSigils] add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitBuiltinHomonyms] # Read the CAVEATS. add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitExcessComplexity] # http://en.wikipedia.org/wiki/Cyclomatic_complexity add_themes = knib max_mccabe = 20 [Perl::Critic::Policy::Subroutines::ProhibitExplicitReturnUndef] # http://perlmonks.org/index.pl?node_id=741847 add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitManyArgs] add_themes = knib max_arguments = 5 [Perl::Critic::Policy::Subroutines::ProhibitNestedSubs] add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitReturnSort] # KNOWN BUGS: This Policy is not sensitive to the wantarray() function. add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitSubroutinePrototypes] add_themes = knib [Perl::Critic::Policy::Subroutines::ProhibitUnusedPrivateSubroutines] add_themes = knib [Perl::Critic::Policy::Subroutines::ProtectPrivateSubs] add_themes = knib #[Perl::Critic::Policy::Subroutines::RequireArgUnpacking] #add_themes = knib #allow_delegation_to = SUPER:: NEXT:: #allow_subscripts = 0 #short_subroutine_statements = 0 [Perl::Critic::Policy::Subroutines::RequireFinalReturn] add_themes = knib terminal_funcs = return carp croak die exec exit goto throw [Perl::Critic::Policy::TestingAndDebugging::ProhibitNoStrict] add_themes = knib allow = refs [Perl::Critic::Policy::TestingAndDebugging::ProhibitNoWarnings] add_themes = knib allow_with_category_restriction = 1 [Perl::Critic::Policy::TestingAndDebugging::ProhibitProlongedStrictureOverride] add_themes = knib statements = 3 # The following policy seems to have a bug for the ok() test. #[Perl::Critic::Policy::TestingAndDebugging::RequireTestLabels] #add_themes = knib #modules = Test::Exception Test::More [Perl::Critic::Policy::TestingAndDebugging::RequireUseStrict] add_themes = knib [Perl::Critic::Policy::TestingAndDebugging::RequireUseWarnings] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitInterpolationOfLiterals] add_themes = knib allow_if_string_contains_single_quote = 1 [Perl::Critic::Policy::ValuesAndExpressions::ProhibitLeadingZeros] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitLongChainsOfMethodCalls] add_themes = knib max_chain_length = 3 [Perl::Critic::Policy::ValuesAndExpressions::ProhibitMagicNumbers] # Not yet configured completely. add_themes = knib # 14.01.2016 2 is considered a magic number as well after a discussion with the team allowed_values = -1 0 1 # 11.02.2016 policy disabled after a discussion with the team #[Perl::Critic::Policy::ValuesAndExpressions::ProhibitMismatchedOperators] #add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitMixedBooleanOperators] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::ProhibitQuotesAsQuotelikeOperatorDelimiters] add_themes = knib back_quote_allowed_operators = double_quote_allowed_operators = single_quote_allowed_operators = [Perl::Critic::Policy::ValuesAndExpressions::ProhibitSpecialLiteralHeredocTerminator] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::RequireConstantVersion] add_themes = allow_version_without_use_on_same_line = 1 [Perl::Critic::Policy::ValuesAndExpressions::RequireNumberSeparators] add_themes = knib min_value = 10000 [Perl::Critic::Policy::ValuesAndExpressions::RequireQuotedHeredocTerminator] add_themes = knib [Perl::Critic::Policy::ValuesAndExpressions::RequireUpperCaseHeredocTerminator] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitConditionalDeclarations] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitLocalVars] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitMatchVars] add_themes = knib [Perl::Critic::Policy::Variables::ProhibitUnusedVariables] add_themes = knib [Perl::Critic::Policy::Variables::RequireInitializationForLocalVars] add_themes = knib [Perl::Critic::Policy::Variables::RequireLexicalLoopIterators] add_themes = knib [Perl::Critic::Policy::Variables::RequireLocalizedPunctuationVars] add_themes = knib allow = [Perl::Critic::Policy::Variables::RequireNegativeIndices] add_themes = knib Test-Expander-2.5.1/LICENSE0000644000175100017540000004367414561714342014271 0ustar jurijjurijThis software is copyright (c) 2021-2024 by Jurij Fajnberg. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2021-2023 by Jurij Fajnberg. This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2021-2024 by Jurij Fajnberg. This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Test-Expander-2.5.1/Readme.md0000644000175100017540000007257214663156177015013 0ustar jurijjurij# NAME **Test::Expander** - Expansion of test functionalities that appear to be frequently used while testing. # SYNOPSIS ```perl # Tries to automatically determine, which class / module and method / subroutine are to be tested, # creates neither a temporary directory, nor a temporary file: use Test::Expander; # Tries to automatically determine, which class / module and method / subroutine are to be tested. # The determined (and hence exported) values are displayed in green, # the undetermined (and hence unexported) ones in red: use Test::Expander -color => { exported => 'green', unexported => 'red' }; # Tries to automatically determine, which class / module and method / subroutine are to be tested. # Both determined and undetermined values are displayed uncolorized: use Test::Expander -color => { exported => undef, unexported => undef }; # Tries to automatically determine, which class / module and method / subroutine are to be tested, # creates both a temporary directory and a temporary file preventing their removal after execution: use Test::Expander -tempdir => { CLEANUP => 0 }, -tempfile => { UNLINK => 0 }; # Tries to automatically determine, which class / module and method / subroutine are to be tested, # creates neither a temporary directory, nor a temporary file, # passes the option '-srand' to Test2::V0 changing the random seed to the current time in seconds: use Test::Expander -srand => time; # Class is supplied explicitly, tries to automatically determine method / subroutine to be tested, # creates a temporary directory with name corresponing to the template supplied, does not create temporary file: use Test::Expander -target => 'My::Class', -tempdir => { TEMPLATE => 'my_dir.XXXXXXXX' }; # Does not try to determine, which class / module and method / subroutine are to be tested, # creates neither a temporary directory, nor a temporary file: use Test::Expander -target => undef; # Tries to automatically determine, which class / module is to be tested, # does not determine method / subroutine to be tested, # creates neither a temporary directory, nor a temporary file: use Test::Expander -method => undef; # Tries to automatically determine, which class / module is to be tested, # does not create temporary file, creates a temporary directory and # adds directories 'dir0' and 'dir1' located therein on top of the directory list used by the Perl interpreter # for search of modules to be loaded. In other words, "unshifts" these directories to the @INC array: # PLEASE CONSIDER THE SINGLE QUOTES APPLIED BELOW! use Test::Expander -lib => [ 'path( $TEMP_DIR )->child( qw( dir0 ) )->stringify', 'path( $TEMP_DIR )->child( qw( dir1 ) )->stringify', ], -tempdir => {}; # Override the builtin 'close' in the name space of explicitly supplied class / module to be tested: my $close_success; use Test::Expander -builtins => { close => sub { $close_success ? CORE::close( shift ) : 0 } }, -target => 'My::Class'; # Activates immediate stop of test execution if any assertion fails: use Test::Expander -bail => 1; ``` # DESCRIPTION The primary objective of **Test::Expander** is to provide additional convenience while testing based on [Test2::V0](https://metacpan.org/pod/Test2::V0) considering boilerplate aspects that seem to be important (to the author) in notable number of cases. These are among other things: - Repeated application of class / module and / or method / function to be tested. This, of course, can be stored in additional variables declared somewhere at the very beginning of test. Doing so, any refactoring including renaming of this class and / or method leads to the necessity to find and then to update all test files containing these names. If, however, both of these values can be determined from the path and base name of the current test file and saved in the exported read-only variables **$CLASS** and **$METHOD**, the only effort necessary in case of such renaming is a single change of path and / or base name of the corresponding test file. An additional benefit of suggested approach is a better readability of tests, where chunks like ```perl Foo::Bar->baz( $arg0, $arg1 ) ``` now look like ```perl $CLASS->$METHOD( $arg0, $arg1 ) ``` and hence clearly manifest that this chunk is about the testee. - The frequent necessity of introduction of temporary directory and / or temporary file usually leads to the usage of modules [File::Temp::tempdir](https://metacpan.org/pod/File::Temp) or [Path::Tiny](https://metacpan.org/pod/Path::Tiny) providing the methods / funtions **tempdir** and **tempfile**. This, however, can significantly be simplified (and the size of test file can be reduced) requesting such introduction via the options supported by **Test::Expander**: ```perl use Test::Expander -tempdir => {}, -tempfile => {}; ``` - Another fuctionality frequently used in tests relates to the work with files and directories: reading, writing, creation, etc. Because almost all features required in such cases are provided by [Path::Tiny](https://metacpan.org/pod/Path::Tiny), some functions of this module are also exported from **Test::Expander**. - To provide a really environment-independent testing, we might need a possibility to run our tests in a clean environment, where only explicitly mentioned environment variables are set and environment variables from the "outside world" cannot affect the execution of tests. This can also be achieved manually by manipulation of **%ENV** hash at the very beginning of tests. However, even ignoring the test code inflation, this might be (in fact - is) necessary in many tests belonging to one and the same module, so that a possibility to outsource the definition of test environment provided by **Test::Expander** makes tests smaller, more maintainable, and much more reliable. - I stole the idea of subtest selection from [Test::Builder::SubtestSelection](https://metacpan.org/pod/Test::Builder::SubtestSelection). That's why the subtest selection supported by **Test::Expander** is partially compatible with the implementation provided by [Test::Builder::SubtestSelection](https://metacpan.org/pod/Test::Builder::SubtestSelection). The term "partially" means that the option `--subtest` can only be applied to selection by name not by number. In general the subtest selection allows the execution of required subtests identified by their names and / or by their numbers before test running. At the command-line [prove](https://metacpan.org/pod/prove) runs your test script and the subtest selection is based on the values given to the options `--subtest_name` (alias `--subtest` - in the [Test::Builder::SubtestSelection](https://metacpan.org/pod/Test::Builder::SubtestSelection) style) and `--subtest_number`. Both options can be applied repeatedly and mixed together so that some tests can be selected by names and other ones by numbers. In both cases the options have to be supplied as arguments to the test script. To do so separate the arguments from prove's own arguments with the arisdottle (`::`). - Another idea inspired by other module namely by [Test::Most](https://metacpan.org/pod/Test::Most) is the idea of immediate stop of test file execution if one of the tests fails. This feature can be applied both for the whole test file using the **-bail** option ```perl use Test::Expander -bail => 1; ``` and for a part of it using the functions **bail\_on\_failure** and **restore\_failure\_handler** to activate and deactivate this reaction, correspondingly. - Selection by name The selection by name means that the value supplied along with `--subtest_name` option is compared with all subtest names in your test and only those, which names match this value in terms of regular expression, will be executed. If this value cannot be treated as a valid regular expression, meta characters therein are properly quoted so that the RegEx match is in any case possible. Assuming the test script **t/my\_test.t** contains ```perl use strict; use warnings; use Test::Expander; plan( 3 ); subtest 'my higher level subtest without RegEx meta characters in name' => sub { # some test function calls }; subtest 'my next higher level subtest' => sub { subtest 'my embedded subtest' => sub { subtest 'my deepest subtest' => sub { # some test function calls }; # some test function calls }; # some test function calls }; # some test function calls subtest 'my subtest with [' => sub { # some test function calls }; ``` Then, if the subtest **my next higher level subtest** with all embedded subtests and the subtest **my subtest with \[** should be executed, the corresponding [prove](https://metacpan.org/pod/prove) call can look like one of the following variants: ```sh prove -v -b t/basic.t :: --subtest_name 'next|embedded|deepest' --subtest_name '[' prove -v -b t/basic.t :: --subtest_name 'next' --subtest_name 'embedded' --subtest_name 'deepest' --subtest_name '[' ``` This kind of subtest selection is pretty convenient but has a significant restriction: you cannot select an embedded subtest without its higher-level subtests. I.e. if you would try to run the following command ```sh prove -v -b t/basic.t :: --subtest_name 'deepest' --subtest_name '[' ``` the subtest **my next higher level subtest** including all embedded subtests will be skipped, so that even the subtest **my deepest subtest** will not be executed although this was your goal. This restriction, however, can be avoided using the subtest selection by number. - Selection by number The selection by number means that the value supplied along with `--subtest_number` option is the sequence of numbers representing required subtest in the test file. Let's add to the source code of **t/my\_test.t** some comments illustrating the numbers of each subtest: ```perl use strict; use warnings; use Test::Expander; plan( 3 ); subtest 'my higher level subtest without RegEx meta characters in name' => sub { # subtest No. 0 # some test function calls }; subtest 'my next higher level subtest' => sub { # subtest No. 1 subtest 'my embedded subtest' => sub { # subtest No. 0 in subtest No. 1 subtest 'my deepest subtest' => sub { # subtest No. 0 in subtest No. 0 in subtest No. 1 # some test function calls }; # some test function calls }; # some test function calls }; # some test function calls subtest 'my subtest with [' => sub { # subtest No. 2 # some test function calls }; ``` Taking this into consideration we can combine subtest numbers starting from the highest level and separate single levels by the slash sign to get the unique number of any subtest we intend to execute. Doing so, if we only want to execute the subtests **my deepest subtest** (its number is **1/0/0**) and **my subtest with \[** (its number is **2**), this can easily be done with the following command: ```sh prove -v -b t/basic.t :: --subtest_number '1/0/0' --subtest_number '2' ``` **Test::Expander** combines all advanced possibilities provided by [Test2::V0](https://metacpan.org/pod/Test2::V0) with some specific functions only available in the older module [Test::More](https://metacpan.org/pod/Test::More) (which allows a smooth migration from [Test::More](https://metacpan.org/pod/Test::More)-based tests to [Test2::V0](https://metacpan.org/pod/Test2::V0)-based ones) and handy functions from some other modules often used in test suites. Furthermore, this module allows to automatically recognize the class / module to be tested (see variable **$CLASS** below) so that in contrast to [Test2::V0](https://metacpan.org/pod/Test2::V0) you do not need to specify this explicitly if the path to the test file is in accordance with the name of class / module to be tested i.e. file **t/Foo/Bar/baz.t** corresponds to class / module **Foo::Bar**. If such automated recognition is not intended, this can be deactivated by explicitly supplied undefined class / module name along with the option `-target`. A similar recognition is provided in regard to the method / subroutine to be tested (see variables **$METHOD** and **$METHOD\_REF** below) if the base name (without extension) of test file is identical with the name of this method / subroutine i.e. file **t/Foo/Bar/baz.t** corresponds to method / subroutine **Foo::Bar::bar**. Finally, a configurable setting of specific environment variables is provided so that there is no need to hard-code this in the test itself. The following options are accepted: - Options specific for this module only are always expected to have values and their meaning is: - **-bail** - activates immediate stop of test file execution if any test case in this file fails. The expected value is boolean. Defaults to **false** i.e. the execution continues even if tests fail. Even if activated, this behaviour can be deactivated at any point in the test file using the function **restore\_failure\_handler**. - **-builtins** - overrides builtins in the name space of class / module to be tested. The expected value is a hash reference, where keys are the names of builtins and the values are code references overriding default behavior. - **-color** - controls colorization of read-only variables **$CLASS**, **$METHOD**, and **$METHOD\_REF** in the test notification header. The expected value is a hash reference, the only supported keys are **exported** and **unexported**: - **exported** Contains either a string describing the foreground color, in which these variables are displayed if they are being exported, or **undef** in no colorization is required in such case. Defaults to **'cyan'**. - **unexported** The same as above, but for the case if these variables remains undefined and unexported. Defaults to **'magenta'**. - **-lib** - prepends directory list used by the Perl interpreter for search of modules to be loaded (i.e. the **@INC** array) with values supplied in form of array reference. Each element of this array is evaluated using [string eval](https://perldoc.perl.org/functions/eval) so that any valid expression evaluated to string is supported if it is based on modules used by **Test::Expander** or any module loaded before. Among other things this provides a possibility to temporary expand the module search path by directories located in the temporary directory if the latter is defined with the option **-tempdir** (see below). **-lib** is interpreted as the very last option, that's why the variables defined by **Test::Expander** for export e.g. **$TEMP\_DIR** can be used in the expressions determining such directories (see **SYNOPSYS** above). - **-method** - prevents any attempt to automatically determine method / subroutine to be tested. If the value supplied along with this option is defined and found in the class / module to be test (see **-target** below), this will be considered such method / subroutine so that the variables **$METHOD** and **$METHOD\_REF** (see description of exported variables below) will be imported and accessible in test. If this value is **undef**, these variables are not imported. - **-target** - identical to the same-named option of [Test2::V0](https://metacpan.org/pod/Test2::V0) and, if contains a defined value, has the same purpose namely the explicit definition of the class / module to be tested as the value. However, if its value is **undef**, this is not passed through to [Test2::V0](https://metacpan.org/pod/Test2::V0) so that no class / module will be loaded and the variable **$CLASS** will not be imported at all. - **-tempdir** - activates creation of a temporary directory. The value has to be a hash reference with content as explained in [File::Temp::tempdir](https://metacpan.org/pod/File::Temp). This means, you can control the creation of temporary directory by passing of necessary parameters in form of a hash reference or, if the default behavior is required, simply pass the empty hash reference as the option value. - **-tempfile** - activates creation of a temporary file. The value has to be a hash reference with content as explained in [File::Temp::tempfile](https://metacpan.org/pod/File::Temp). This means, you can control the creation of temporary file by passing of necessary parameters in form of a hash reference or, if the default behavior is required, simply pass the empty hash reference as the option value. - All other valid options (i.e. arguments starting with the dash sign **-**) are forwarded to [Test2::V0](https://metacpan.org/pod/Test2::V0) along with their values. Options without values are not supported; in case of their passing an exception is raised. - If an argument cannot be recognized as an option, an exception is raised. The automated recognition of name of class / module to be tested can only work if the test file is located in the corresponding subdirectory. For instance, if the class / module to be tested is _Foo::Bar::Baz_, then the folder with test files related to this class / module should be **t/**_Foo_**/**_Bar_**/**_Baz_ or **xt/**_Foo_**/**_Bar_**/**_Baz_ (the name of the top-level directory in this relative name - **t**, or **xt**, or **my\_test** is not important) - otherwise the module name cannot be put into the exported variable **$CLASS** and, if you want to use this variable, should be supplied as the value of **-target**: ```perl use Test::Expander -target => 'Foo::Bar::Baz'; ``` This recognition can explicitly be deactivated if the value of **-target** is **undef**, so that no class / module will be loaded and, correspondingly, the variables **$CLASS**, **$METHOD**, and **$METHOD\_REF** will not be exported. Furthermore, the automated recognition of the name of the method / subroutine to be tested only works if the file containing the class / module mentioned above exists and if this class / module has the method / subroutine with the same name as the test file base name without the extension. If this is the case, the exported variables **$METHOD** and **$METHOD\_REF** contain the name of method / subroutine to be tested and its reference, correspondingly, otherwise both variables are neither evaluated nor exported. Also in this case evaluation and export of the variables **$METHOD** and **$METHOD\_REF** can be prevented by passing of **undef** as value of the option **-method**: ```perl use Test::Expander -target => undef; ``` Finally, **Test::Expander** supports testing inside of a clean environment containing only some clearly specified environment variables required for the particular test. Names and values of these environment variables should be configured in files, which names are identical with paths to single class / module levels or the method / subroutine to be tested, and the extension is always **.env**. For instance, if the test file name is **t/Foo/Bar/Baz/myMethod.t**, the following approach is applied: - if the file **t/Foo.env** exists, its content is used for the initialization of the test environment, - if the file **t/Foo/Bar.env** exists, its content is used either to extend the test environment initialized in the previous step or for its initialization if **t/Foo.env** does not exist, - if the file **t/Foo/Bar/Baz.env** exists, its content is used either to extend the test environment initialized in one of the previous steps or for its initialization if neither **t/Foo.env** nor **t/Foo/Bar.env** exist, - if the file **t/Foo/Bar/Baz/myMethod.env** exists, its content is used either to extend the test environment initialized in one of the previous steps or for its initialization if none of **.env** files mentioned above exist. If the **.env** files existing on different levels have identical names of environment variables, the priority is the higher the later they have been detected. I.e. **VAR = 'VALUE0'** in **t/Foo/Bar/Baz/myMethod.env** overwrites **VAR = 'VALUE1'** in **t/Foo/Bar/Baz.env**. If none of these **.env** files exist, the environment isn't changed by **Test::Expander** during the execution of **t/Foo/Bar/Baz/myMethod.t**. An environment configuration file (**.env** file) is a line-based text file. Its content is interpreted as follows: - if such files don't exist, the **%ENV** hash remains unchanged; - otherwise, if at least one of such files exists, those elements of the **%ENV** hash are kept, which names are equal to names found in lines of **.env** file without values. All remaining elements of the **%ENV** hash gets emptied (without localization) and - lines not matching the RegEx **/^\\w+\\s\*(?:=\\s\*\\S|$)?/** (some alphanumeric characters representing a name of environment variable, optional blanks, optionally followed by the equal sign, again optional blanks, and at least one non-blank character representing the first character of environment variable value) are skipped; - in all other lines the value of the environment variable is everything from the first non-blank character after the equal sign until end of the line; if this value is omitted, the corresponding environment variable remains unchanged as it originally was in the **%ENV** hash (if it existed there, of course); - the cascading definition of environment variables can be used, which means that - during the evaluation of current line environment variables defined in the same file above can be applied. For example if such **.env** file contains ```perl VAR1 = 'ABC' VAR2 = lc( $ENV{ VAR1 } ) ``` and neither **VAR1** nor **VAR2** will be overwritten during the evaluation of subsequent lines in the same or other **.env** files, the **%ENV** hash will contain at least the following entries: ```perl VAR1 => 'ABC' VAR2 => 'abc' ``` - during the evaluation of current line also environment variables defined in a higher-level **.env** file can be used. For example if **t/Foo/Bar/Baz.env** contains ```perl VAR0 = 'XYZ ' ``` and **t/Foo/Bar/Baz/myMethod.env** contains ```perl VAR1 = 'ABC' VAR2 = lc( $ENV{ VAR0 } . $ENV{ VAR1 } ) ``` and neither **VAR0**, nor **VAR1**, nor **VAR2** will be overwritten during the evaluation of subsequent lines in the same or other **.env** files, the **%ENV** hash will contain at least the following entries: ```perl VAR0 => 'XYZ ' VAR1 => 'ABC' VAR2 => 'xyz abc' ``` - the value of the environment variable (if provided) is evaluated by the [string eval](https://perldoc.perl.org/functions/eval) so that - constant values must be quoted; - variables and subroutines must not be quoted: ```perl NAME_CONST = 'VALUE' NAME_VAR = $KNIB::App::MyApp::Constants::ABC NAME_FUNC = join(' ', $KNIB::App::MyApp::Constants::DEF) ``` All environment variables set up in this manner are logged to STDOUT using [note](https://metacpan.org/pod/Test2::Tools::Basic#DIAGNOSTICS). Another common feature within test suites is the creation of a temporary directory / file used as an isolated container for some testing actions. The module options **-tempdir** and **-tempfile** are fully syntactically compatible with [File::Temp::tempdir](https://metacpan.org/pod/File::Temp#FUNCTIONS) / [File::Temp::tempfile](https://metacpan.org/pod/File::Temp#FUNCTIONS). They make sure that such temporary directory / file are created after **use Test::Expander** and that their names are stored in the variables **$TEMP\_DIR** / **$TEMP\_FILE**, correspondingly. Both temporary directory and file are removed by default after execution. The following functions provided by this module are exported by default: - all functions exported by default from [Test2::V0](https://metacpan.org/pod/Test2::V0), - all functions exported by default from [Test2::Tools::Explain](https://metacpan.org/pod/Test2::Tools::Explain), - some functions exported by default from [Test::More](https://metacpan.org/pod/Test::More) and often used in older tests but not supported by [Test2::V0](https://metacpan.org/pod/Test2::V0): - BAIL\_OUT, - is\_deeply, - new\_ok, - require\_ok, - use\_ok. - some functions exported by default from [Test::Exception](https://metacpan.org/pod/Test::Exception) and often used in older tests but not supported by [Test2::V0](https://metacpan.org/pod/Test2::V0): - dies\_ok, - lives\_ok, - throws\_ok. some functions exported by default from [Test2::Tools::Explain](https://metacpan.org/pod/Test2::Tools::Explain) and often used in older tests but not supported by [Test2::Tools::Explain](https://metacpan.org/pod/Test2::Tools::Explain): - explain. - function exported by default from [Const::Fast](https://metacpan.org/pod/Const::Fast): - const. - some functions exported by request from [File::Temp](https://metacpan.org/pod/File::Temp): - tempdir, - tempfile, - some functions exported by request from [Path::Tiny](https://metacpan.org/pod/Path::Tiny): - cwd, - path, The following variables can be set and exported: - variable **$CLASS** containing the name of the class / module to be tested if the class / module recognition is not disable and possible, - variable **$METHOD** containing the name of the method / subroutine to be tested if the method / subroutine recognition is not disable and possible, - variable **$METHOD\_REF** containing the reference to the subroutine to be tested if the method / subroutine recognition is not disable and possible, - variable **$TEMP\_DIR** containing the name of a temporary directory created at compile time if the option **-tempdir** is supplied, - variable **$TEMP\_FILE** containing the name of a temporary file created at compile time if the option **-tempfile** is supplied. - variable **$TEST\_FILE** containing the absolute name of the current test file (if any). In fact its content is identical with the content of special token [\_\_FILE\_\_](https://perldoc.perl.org/functions/__FILE__), but only in the test file itself! If, however, you need the test file name in a test submodule or in a **.env** file belonging to this test, [\_\_FILE\_\_](https://perldoc.perl.org/functions/__FILE__) can no longer be applied - whereas **$TEST\_FILE** is there. All variables mentioned above are read-only after their export. In this case they are logged to STDOUT using [note](https://metacpan.org/pod/Test2::Tools::Basic#DIAGNOSTICS). If any of the variables **$CLASS**, **$METHOD**, and **$METHOD\_REF** is undefined and hence not exported, this is reported at the very begin of test execution. # CAVEATS - **Test::Expander** is recommended to be the very first module in your test file. The only known exception is when some actions performed on the module level (e.g. determination of constants) rely upon results of other actions (e.g. mocking of built-ins). To explain this let us assume that your test file should globally mock the built-in **close** (if this is only required in the name space of class / module to be tested, the option **-builtin** should be used instead!) to verify if the testee properly reacts both on its success and failure. For this purpose a reasonable implementation might look as follows: ```perl my $close_success; BEGIN { *CORE::GLOBAL::close = sub (*) { $close_success ? CORE::close( shift ) : 0 } } use Test::Expander; ``` - Array elements of the value supplied along with the option **-lib** are evaluated using [string eval](https://perldoc.perl.org/functions/eval) so that constant strings would need duplicated quotes e.g. ```perl use Test::Expander -lib => [ q('my_test_lib') ]; ``` - If the value to be assigned to an environment variable after evaluation of an **.env** file is undefined, such assignment is skipped. - If **Test::Expander** is used in one-line mode (with the **-e** option), the variable **$TEST\_FILE** is unset and not exported. # AUTHOR Jurij Fajnberg, <fajnbergj at gmail.com> # BUGS Please report any bugs or feature requests through the web interface at [https://github.com/jsf116/Test-Expander/issues](https://github.com/jsf116/Test-Expander/issues). # COPYRIGHT AND LICENSE Copyright (c) 2021-2024 Jurij Fajnberg This program is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Test-Expander-2.5.1/MANIFEST0000644000175100017540000000212114664645404014401 0ustar jurijjurijChanges lib/.perlcriticrc lib/Test/Expander.pm lib/Test/Expander.pod lib/Test/Expander/Constants.pm LICENSE Makefile.PL MANIFEST This list of files META.json META.yml Readme.md t/.perlcriticrc t/.proverc t/.proverc-cover t/Test t/Test/Expander t/Test/Expander/_colorize.t t/Test/Expander/_determine_testee.env t/Test/Expander/_determine_testee.t t/Test/Expander/_error.t t/Test/Expander/_export_most_symbols.t t/Test/Expander/_new_test_message.t t/Test/Expander/_parse_options.t t/Test/Expander/_set_env.t t/Test/Expander/_subtest_conditional.t t/Test/Expander/_subtest_selection.t t/Test/Expander/_use_imports.t t/Test/Expander/bail_on_failure.t t/Test/Expander/dies_ok.t t/Test/Expander/import.t t/Test/Expander/is_deeply.t t/Test/Expander/lives_ok.t t/Test/Expander/new_ok.t t/Test/Expander/NoCLASS t/Test/Expander/NoCLASS/mock_builtin.t t/Test/Expander/NoCLASS/MyModule.pm t/Test/Expander/NoCLASS/NoMETHOD.t t/Test/Expander/NoCLASS/NoMETHOD_only.t t/Test/Expander/require_ok.t t/Test/Expander/restore_failure_handler.t t/Test/Expander/throws_ok.t t/Test/Expander/use_ok.t Test-Expander-2.1.5.tar.gz Test-Expander-2.5.1/Makefile.PL0000644000175100017540000000340614540041432015211 0ustar jurijjurijuse strict; use warnings FATAL => qw( all ), NONFATAL => qw( deprecated exec internal malloc newline portable recursion ); use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( ABSTRACT => 'Expansion of test functionalities that appear to be frequently used while testing.', AUTHOR => 'Jurij Fajnberg ', DISTNAME => 'Test-Expander', LICENSE => 'perl', MIN_PERL_VERSION => '5.014', NAME => 'Test::Expander', PREREQ_PM => { 'B' => 0, 'Const::Fast' => 0, 'Exporter' => 0, 'File::chdir' => 0, 'File::Temp' => 0, 'Getopt::Long' => 0, 'Importer' => 0, 'PadWalker' => 0, 'Path::Tiny' => '0.144', 'Scalar::Readonly' => 0, 'Test::Builder' => 0, 'Test2::API' => 0, 'Test2::Tools::Basic' => 0, 'Test2::Tools::Explain' => 0, 'Test2::Tools::Subtest' => 0, 'Test2::V0' => 0, }, TEST_REQUIRES => { 'FindBin' => 0, 'Test::Simple' => 0, }, VERSION_FROM => 'lib/Test/Expander.pm', test => { TESTS => 't/*/*/*.t t/*/*/*/*.t', }, META_MERGE => { 'meta-spec' => { version => 2 }, resources => { repository => { type => 'git', url => 'git://github.com/jsf116/Test-Expander.git', web => 'https://github.com/jsf116/Test-Expander', }, bugtracker => { web => 'https://github.com/jsf116/Test-Expander/issues' }, }, }, ); Test-Expander-2.5.1/META.yml0000644000175100017540000000211114664645404014520 0ustar jurijjurij--- abstract: 'Expansion of test functionalities that appear to be frequently used while testing.' author: - 'Jurij Fajnberg ' build_requires: ExtUtils::MakeMaker: '0' FindBin: '0' Test::Simple: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 generated_by: 'ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Test-Expander no_index: directory: - t - inc requires: B: '0' Const::Fast: '0' Exporter: '0' File::Temp: '0' File::chdir: '0' Getopt::Long: '0' Importer: '0' PadWalker: '0' Path::Tiny: '0.144' Scalar::Readonly: '0' Test2::API: '0' Test2::Tools::Basic: '0' Test2::Tools::Explain: '0' Test2::Tools::Subtest: '0' Test2::V0: '0' Test::Builder: '0' perl: '5.014' resources: bugtracker: https://github.com/jsf116/Test-Expander/issues repository: git://github.com/jsf116/Test-Expander.git version: v2.5.1 x_serialization_backend: 'CPAN::Meta::YAML version 0.018' Test-Expander-2.5.1/META.json0000644000175100017540000000364514664645404014705 0ustar jurijjurij{ "abstract" : "Expansion of test functionalities that appear to be frequently used while testing.", "author" : [ "Jurij Fajnberg " ], "dynamic_config" : 1, "generated_by" : "ExtUtils::MakeMaker version 7.70, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Test-Expander", "no_index" : { "directory" : [ "t", "inc" ] }, "prereqs" : { "build" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "B" : "0", "Const::Fast" : "0", "Exporter" : "0", "File::Temp" : "0", "File::chdir" : "0", "Getopt::Long" : "0", "Importer" : "0", "PadWalker" : "0", "Path::Tiny" : "0.144", "Scalar::Readonly" : "0", "Test2::API" : "0", "Test2::Tools::Basic" : "0", "Test2::Tools::Explain" : "0", "Test2::Tools::Subtest" : "0", "Test2::V0" : "0", "Test::Builder" : "0", "perl" : "5.014" } }, "test" : { "requires" : { "FindBin" : "0", "Test::Simple" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/jsf116/Test-Expander/issues" }, "repository" : { "type" : "git", "url" : "git://github.com/jsf116/Test-Expander.git", "web" : "https://github.com/jsf116/Test-Expander" } }, "version" : "v2.5.1", "x_serialization_backend" : "JSON::PP version 4.16" }