Perl-Toolchain-Gang/module-build-tiny

Minilla won't Build test with MBT when no . in @INC

toddr opened this issue · 8 comments

toddr commented

I probably should be reporting this against TH, but trying here first.

I'm using the new Test::Harness:

$>perl -MTest::Harness -E'say $Test::Harness::VERSION'
3.37_01

Minilla has a very basic Build.PL

# =========================================================================
# THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA.
# DO NOT EDIT DIRECTLY.
# =========================================================================

use 5.008_001;
use strict;

use Module::Build::Tiny 0.035;

Build_PL();

But when I do Build test, I get errors complaining about a lack of . in @inc. Is this because Module::Build::Tiny is calling Test::Harness in an inconsistent way from the other builders?

This is just a sampling. There is more output.

t/00_compile.t ............................... ok   
t/01_load_all.t .............................. ok    
t/03_step.t .................................. skipped: Test requires module 'Version::Next' but it's not found
t/05_metadata.t .............................. Can't locate t/Util.pm in @INC (you may need to install the t::Util module) (@INC contains: /root/tmp/Minilla/blib/arch /root/tmp/Minilla/blib/lib /perl/5.25.9/lib/site_perl/5.25.9/x86_64-linux /perl/5.25.9/lib/site_perl/5.25.9 /perl/5.25.9/lib/5.25.9/x86_64-linux /perl/5.25.9/lib/5.25.9) at t/05_metadata.t line 5.
BEGIN failed--compilation aborted at t/05_metadata.t line 5.
t/05_metadata.t .............................. Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
t/bumpversion.t .............................. Can't locate t/Util.pm in @INC (you may need to install the t::Util module) (@INC contains: /root/tmp/Minilla/blib/arch /root/tmp/Minilla/blib/lib /perl/5.25.9/lib/site_perl/5.25.9/x86_64-linux /perl/5.25.9/lib/site_perl/5.25.9 /perl/5.25.9/lib/5.25.9/x86_64-linux /perl/5.25.9/lib/5.25.9) at t/bumpversion.t line 5.
BEGIN failed--compilation aborted at t/bumpversion.t line 5.
t/bumpversion.t .............................. Dubious, test returned 2 (wstat 512, 0x200)
No subtests run 
Leont commented

But when I do Build test, I get errors complaining about a lack of . in @inc. Is this because Module::Build::Tiny is calling Test::Harness in an inconsistent way from the other builders?

That is correct. Much like prove it's calling into TAP::Harness directly. The fix is just a one-liner, though if Minilla is the only affected distribution I'd rather fix it there.

toddr commented

If it's calling into TAP::Harness directly, should we be setting PERL_USE_UNSAFE_INC=1 before we run the tests?

Leont commented

If it's calling into TAP::Harness directly, should we be setting PERL_USE_UNSAFE_INC=1 before we run the tests?

Yes that would be the one-line fix :-)

toddr commented

So you're against this then? #24

toddr commented

Alternatively is there a way MBT could use Test::Harness or are there... Reasons?

https://justincascio.files.wordpress.com/2014/08/ecqkuo.jpg

Leont commented

Alternatively is there a way MBT could use Test::Harness or are there... Reasons?

The main reason was "The Test::Builder API is terrible", but I had been considering doing just that for other reasons. It would look something like this.

diff --git a/lib/Module/Build/Tiny.pm b/lib/Module/Build/Tiny.pm
index 40738ce..04f91f9 100644
--- a/lib/Module/Build/Tiny.pm
+++ b/lib/Module/Build/Tiny.pm
@@ -103,15 +103,15 @@ my %actions = (
    test => sub {
        my %opt = @_;
        die "Must run `./Build build` first\n" if not -d 'blib';
-       require TAP::Harness::Env;
-       my %test_args = (
-           (verbosity => $opt{verbose}) x!! exists $opt{verbose},
-           (jobs => $opt{jobs}) x!! exists $opt{jobs},
-           (color => 1) x !!-t STDOUT,
-           lib => [ map { rel2abs(catdir(qw/blib/, $_)) } qw/arch lib/ ],
-       );
-       my $tester = TAP::Harness::Env->create(\%test_args);
-       $tester->runtests(sort +find(qr/\.t$/, 't'))->has_errors and exit 1;
+       require Test::Harness;
+       no warnings 'once';
+       local $Test::Harness::Switches = '';
+       local $Test::Harness::verbose = $opt{verbose} if exists $opt{verbose};
+       local $Test::Harness::Color = 1 if !!-t STDOUT and not exists $ENV{HARNESS_COLOR};
+       my @blib = map { '-I' . rel2abs(catdir(qw/blib/, $_)) } qw/arch lib/;
+       local @INC = (@blib, @INC);
+       local $ENV{HARNESS_OPTIONS} = join ':', split(':', $ENV{HARNESS_OPTIONS}), "j$opt{jobs}" if $opt{jobs};
+       Test::Harness::runtests(sort +find(qr/\.t$/, 't')) and exit 1;
    },
    install => sub {
        my %opt = @_;
toddr commented

If it fixes the problem, I'm all for it.

Leont commented

Closing as "fixed on the other side"