Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Test::More plan() requires explicit scalar? Behaviour difference wrt Test-Simple-1.302136 #364

@cxw42

Description

@cxw42

First-time cperl user, here courtesy of the cpantesters report on my first CPAN distribution, Text::PerlPP. All tests pass on p5p perl 5.10.1 (cygwin x86) and 5.26.1 (cygwin x64) (both perlbrew; CPAN Test::More 1.302136). However, the plan call fails on cperl 5.26.2c (cygwin x64) (perlbrew; Test::More 1.401015c).

My test code has an array of testcases. I then plan tests => count_tests(\@testcases, 1, 2); (here) using a function to count the tests (some list entries have multiple tests). On cperl, plan gives me the error Got an undefined number of tests.

I have the following MCVE. Save as foo.t and run as perl foo.t for the failure or perl foo.t 1 for success.

use 5.010001; use strict; use warnings; use Test::More;

sub count_tests { return scalar @{+shift}; }

my @testcases=qw(foo);

plan tests => count_tests(\@testcases) unless @ARGV;        # fails
plan tests => scalar count_tests(\@testcases) if @ARGV;     # succeeds

# Workaround:
#my $ntests = count_tests(\@testcases);
#plan tests => $ntests;                          # succeeds
#plan tests => scalar $ntests;                   # succeeds

ok(!!1, 'yep');

Why do I need to specify scalar on the plan line, even though count_tests() is returning a scalar?

I do not know if this is intended behaviour or a bug. Obviously, I have a workaround :) , but I would still like to know. This probably won't be my last CPAN release, and I would like to write cperl-compatible test cases.

I searched the issues and didn't find this one. I did see discussion of strict typing in #153, and I wonder if that might be similar. Also, #255 says TODO Test::Script Have_Plan oddity in Test::Simple, but doesn't explain what oddity that was. Was it indeed this one?

Thanks very much!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions