diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-11 22:32:06 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2015-06-11 22:32:06 +0000 |
commit | 467298a34215401cdcbb1dded51bc2aba5f1f41c (patch) | |
tree | 1923f32fbc9cf8f0b4ab291d1eb9fad5ab872d68 /t/test_types.t | |
download | Module-Build-tarball-master.tar.gz |
Module-Build-0.4214HEADModule-Build-0.4214master
Diffstat (limited to 't/test_types.t')
-rw-r--r-- | t/test_types.t | 174 |
1 files changed, 174 insertions, 0 deletions
diff --git a/t/test_types.t b/t/test_types.t new file mode 100644 index 0000000..bcb58c4 --- /dev/null +++ b/t/test_types.t @@ -0,0 +1,174 @@ +#!/usr/bin/perl -w + +use strict; +use lib 't/lib'; +use MBTest tests => 25; + +blib_load('Module::Build'); + +use DistGen; + +my $dist = DistGen->new()->chdir_in; + +$dist->add_file('t/special_ext.st', <<'---'); +#!perl +use Test::More tests => 2; +ok(1, 'first test in special_ext'); +ok(1, 'second test in special_ext'); +--- + +$dist->add_file('t/another_ext.at', <<'---'); +#!perl +use Test::More tests => 2; +ok(1, 'first test in another_ext'); +ok(1, 'second test in another_ext'); +--- +$dist->add_file('t/foo.txt', <<'---'); +#!perl +use Test::More tests => 1; +ok 0, "don't run this non-test file"; +die "don't run this non-test file"; +--- + +$dist->regen; +######################### + +my $mb = Module::Build->subclass( + code => q# + sub ACTION_testspecial { + shift->generic_test(type => 'special'); + } + + sub ACTION_testanother { + shift->generic_test(type => 'another'); + } + # + )->new( + module_name => $dist->name, + test_types => { + special => '.st', + another => '.at', + }, + ); + + +ok $mb; + +my $special_output = uc(stdout_of( + sub {$mb->dispatch('testspecial', verbose => 1)} +)); + +like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'saw expected output from first test'); +like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'saw expected output from second test'); + +my $another_output = uc(stdout_of( + sub {$mb->dispatch('testanother', verbose => 1)} +)); + +ok($another_output, 'we have some test output'); + +like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m, + 'saw expected output from first test'); +like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m, + 'saw expected output from second test'); + + +my $all_output = uc(stdout_of( + sub {$mb->dispatch('testall', verbose => 1)} +)); + +0 and warn "\ntestall said >>>\n$all_output\n<<<\n"; + +like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); +like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); + +like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m); +like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m); + +# we get a third one from basic.t +is(scalar(@{[$all_output =~ m/OK 1/mg]}), 3 ); +is(scalar(@{[$all_output =~ m/OK/mg]}), 8 ); +is(scalar(@{[$all_output =~ m/ALL TESTS SUCCESSFUL\./mg]}), 1); + +{ # once-again + +$dist->revert; + +$dist->add_file('t/foo/special.st', <<'---'); +#!perl +use Test::More tests => 2; +ok(1, 'first test in special_ext'); +ok(1, 'second test in special_ext'); +--- +$dist->add_file('t/foo/basic_foo.t', <<'---'); +use Test::More tests => 1; +use strict; use Simple; +ok 1; +--- +$dist->regen; + +my $mb = Module::Build->subclass( + code => q# + sub ACTION_testspecial { + shift->generic_test(type => 'special'); + } + + sub ACTION_testanother { + shift->generic_test(type => 'another'); + } + # + )->new( + recursive_test_files => 1, + module_name => $dist->name, + test_types => { + special => '.st', + another => '.at', + }, + ); + +ok $mb; + +my $special_output = uc(stdout_of( + sub {$mb->dispatch('testspecial', verbose => 1)} +)); + +like($special_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'saw expected output from first test'); +like($special_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'saw expected output from second test'); + +my $another_output = uc(stdout_of( + sub {$mb->dispatch('testanother', verbose => 1)} +)); + +ok($another_output, 'we have some test output'); + +like($another_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m, + 'saw expected output from first test'); +like($another_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m, + 'saw expected output from second test'); + + +my $all_output = uc(stdout_of( + sub {$mb->dispatch('testall', verbose => 1)} +)); + +like($all_output, qr/^OK 1 - FIRST TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); +like($all_output, qr/^OK 2 - SECOND TEST IN SPECIAL_EXT/m, + 'expected output from basic.t'); + +like($all_output, qr/^OK 1 - FIRST TEST IN ANOTHER_EXT/m); +like($all_output, qr/^OK 2 - SECOND TEST IN ANOTHER_EXT/m); + +# we get a third one from basic.t +is(scalar(@{[$all_output =~ m/(OK 1)/mg]}), 5 ); +is(scalar(@{[$all_output =~ m/(OK)/mg]}), 13 ); + +} # end once-again + +# vim:ts=4:sw=4:et:sta |