Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

explain returns the number of arguments in scalar context #1027

Open
briandfoy opened this issue Jan 28, 2025 · 2 comments
Open

explain returns the number of arguments in scalar context #1027

briandfoy opened this issue Jan 28, 2025 · 2 comments

Comments

@briandfoy
Copy link

This issue is mostly here to check your appetite for change and so people can see that it's a weird behavior.

explain doesn't work in scalar context:

use Test::More;
my $data = [ qw(a b c) ];
diag "From here: " . explain $data;

This outputs:

 # From here: 1

This comes from Test::Builder::explain directly returns the result of a map:

return map { ... } @_;

There's no documentation about this behavior, and there are no tests for explain in scalar context. I don't think the current scalar context behavior is intended, just overlooked.

I think this would be much better in scalar context if it joined each string on a newline (or something) and returned one string. If the user wants one thing, explain should give back the most useful one thing.

@exodist
Copy link
Member

exodist commented Jan 28, 2025

I am reluctant to change this for the following reasons, but I am open to debate over it, I would want other toolchain people to weigh in.

  • Test::More is essentially locked to the current behavior, changes can be made for critical bugs, changes to perl breaking things, etc.
  • The above was decided because of how many tests both on cpan, and in the wider world, depend on test-more working as it does, bad designs included.
  • Any new behaviors or behavior changes are to be implemented in the Test2 tools, like Test2::V0, etc.
  • Test2 was largely implemented to make it possible to continue to improve the Test::* ecosystem without breaking assumptions about Test::More's api.

So, usually for changes like this, where it is possible someone depends on Test::More's existing, (despite being demonstrably bad, as you have pointed out) behavior. The answer is "Implement a fix in Test2, so that no Test::More stuff breaks" and if it breaks existing Test2::V0 functionality implement it for a new Test2::V* bundle to avoid breaking things for Test2 consumers.

The issue with that response here is that the main Test2 distribution does not include an explain(), largely because I refused to take a side in the debate on how explain should work which caused a schism between the previous Test::More maintainer and the Test::Most author. This schism resulted in a major implementation incompatibility that made creating Test2 significantly harder, thus I chose to protest by not implementing explain() at all and telling people who wanted it to write Test2::Explain and put it on cpan so that they could be responsible for the bike-shedding.

@briandfoy
Copy link
Author

I figured as much, but a note in the docs would be fine, and have it acknowledge in the docs as a known issue that will not fixed.

I'm just going to stop using explain. I gave it a try for awhile, but if it's broken and won't be fixed, I don't want other developers to see me using it then run into the same problems.

As I've noted before, Test2 is a non-starter for most of my stuff because it wasn't included with perl until 5.25.1 and my support window is much earlier than that and I'd rather stick to what is in core. As it is now, I'm not migrating anything to Test2, which would effectively be starting over.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants