From 17116173fba122a9b45bdc5df0bff4c099ed2045 Mon Sep 17 00:00:00 2001 From: "Flavio S. Glock" Date: Wed, 4 Nov 2026 12:07:23 +0100 Subject: [PATCH] fix: preserve scalar MakeMaker test rules Return the generated test rule as a string when MY::test calls SUPER::test in scalar context, while retaining the existing split list return. Add a regression test for scalar-context wrappers that edit the inherited TEST_FILES command, and document the compatibility fix. Generated with [Codex](https://openai.com/codex/) Co-Authored-By: Codex --- docs/about/changelog.md | 2 + src/main/perl/lib/ExtUtils/MakeMaker.pm | 2 +- .../unit/makemaker_scalar_my_test_super.t | 42 +++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/test/resources/unit/makemaker_scalar_my_test_super.t diff --git a/docs/about/changelog.md b/docs/about/changelog.md index f1519945db..30075c831c 100644 --- a/docs/about/changelog.md +++ b/docs/about/changelog.md @@ -6,6 +6,8 @@ priorities and future plans. ## Work in progress +- Preserve MakeMaker test rules when `MY::test` calls `SUPER::test` in scalar context. + - Recognize boolean values as dual-valued in `Scalar::Util::isdual` (#1954). - Recognize a bareword filehandle when `print`'s implicit `$_` list ends at a block close (#1948). diff --git a/src/main/perl/lib/ExtUtils/MakeMaker.pm b/src/main/perl/lib/ExtUtils/MakeMaker.pm index bf27e33f72..1dc1adbda1 100644 --- a/src/main/perl/lib/ExtUtils/MakeMaker.pm +++ b/src/main/perl/lib/ExtUtils/MakeMaker.pm @@ -1921,7 +1921,7 @@ sub clean { '' } sub test { my ($self) = @_; my $rule = $self->{_perlonjava_test_rule} || ''; - return split /(?<=\n)/, $rule; + return wantarray ? split(/(?<=\n)/, $rule) : $rule; } sub top_targets { '' } diff --git a/src/test/resources/unit/makemaker_scalar_my_test_super.t b/src/test/resources/unit/makemaker_scalar_my_test_super.t new file mode 100644 index 0000000000..1202bd4f40 --- /dev/null +++ b/src/test/resources/unit/makemaker_scalar_my_test_super.t @@ -0,0 +1,42 @@ +use strict; +use warnings; +use Test::More; +use Config; +use Cwd qw(getcwd); +use File::Temp qw(tempdir); + +my $orig_dir = getcwd(); +my $tmpdir = tempdir(CLEANUP => 1); +END { chdir $orig_dir if defined $orig_dir } +chdir $tmpdir or die "chdir $tmpdir: $!"; + +open my $marker, '>', 'Makefile.PL' or die "create Makefile.PL: $!"; +close $marker or die "close Makefile.PL: $!"; +mkdir 't' or die "mkdir t: $!"; + +{ + package MY; + sub test { + my $inherited = shift->SUPER::test(@_); + $inherited =~ s/\$\(TEST_FILES\)/-Iscalar-context \$(TEST_FILES)/; + $inherited; + } +} + +use ExtUtils::MakeMaker; +WriteMakefile(NAME => 'Local::ScalarSuperProbe', VERSION => '0.001'); + +open my $makefile_fh, '<', 'Makefile' or die "open Makefile: $!"; +my $makefile = do { local $/; <$makefile_fh> }; +close $makefile_fh or die "close Makefile: $!"; + +like($makefile, qr/-Iscalar-context \$\(TEST_FILES\)/, + 'scalar-context SUPER::test retains and allows edits to the inherited rule'); +unlike($makefile, qr/^\d+\s*$/m, + 'scalar-context SUPER::test does not become a bare list count'); + +my $make = $Config::Config{make} || 'make'; +is(system($make, '-n', 'test'), 0, + 'scalar-context MY::test output parses as a valid make target'); + +done_testing();