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

Report line number in active file handle for test failures #901

Open
dboehmer opened this issue Oct 20, 2022 · 2 comments
Open

Report line number in active file handle for test failures #901

dboehmer opened this issue Oct 20, 2022 · 2 comments

Comments

@dboehmer
Copy link
Contributor

I often use the DATA block for storing test data and process that in a loop. I just realized that warn() and die() report the line number of the current file handle but tests don’t. But that would be very handy for test statements repeated in a loop.

I think it should be possible to do so. Do you agree it’s desirable?

use Test2::V0;

is <DATA> => 'foo';
warn 'warns';
die 'dies';

__DATA__
bar
$ perl test.t
# Seeded srand with seed '20221020' from local date.
not ok 1
# Failed test at test.t line 3.
# +-------+----+-------+
# | GOT   | OP | CHECK |
# +-------+----+-------+
# | bar\n | eq | foo   |
# +-------+----+-------+
warns at test.t line 4, <DATA> line 1.
dies at test.t line 5, <DATA> line 1.
# Tests were run but no plan was declared and done_testing() was not seen.
# Looks like your test exited with 255 after test #1.

I suggest the output should look like:

not ok 1
# Failed test at test.t line 3, <DATA> line 1.
@exodist
Copy link
Member

exodist commented Apr 27, 2023

This might be possible via a plugin. But I do not think it makes sense as a default. If the necessary hook does not yet exist I can probably add it. I do think it should be made easy to implement something like this, if I have not already made it easy.

@exodist
Copy link
Member

exodist commented Apr 28, 2023

@dboehmer please see Test-More/Test2-Suite#265 if this is sufficient for your needs we can either merge it here, or put it into its own dist.

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