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

expected_tests doesn't strictly correspond to runtests #40

Open
szabgab opened this issue Feb 23, 2021 · 0 comments
Open

expected_tests doesn't strictly correspond to runtests #40

szabgab opened this issue Feb 23, 2021 · 0 comments

Comments

@szabgab
Copy link
Collaborator

szabgab commented Feb 23, 2021

expected_tests is documented to correspond to the behaviour of runtests:

> Returns the total number of tests that runtests() will run on the specified class/object.

Which makes sense, but isn't the case currently because of different implementation. While calling PACKAGE->runtests() executes 31 tests in my case currently, the same call with expected_tests always return 0.

The reason is that I have one base class for all my tests currently which doesn't contain any tests itself, but only provides infrastructure, e.g. to read some files and such. As per documentation I can execute runtests on that base class and all tests of all derived subclasses are executed. But if expected_tests of that class is called, the return value wrongly is 0, because derived classes are not taken into account automatically.

One possible workaround is to call _test_classes, which is used by runtests, and forward that result to expected_tests manually.

package Backend::Tests::Base;

use strict;
use warnings;

use base 'Test::Class';

INIT
{
my @testClasses = __PACKAGE__->_test_classes();
#pop(@testClasses);

use Data::Dumper;
warn(Dumper(\@testClasses));
warn(__PACKAGE__->expected_tests(@testClasses));
#  die('No tests to execute found.') unless (__PACKAGE__->expected_tests() > 0);
  Test::Class->runtests();
#warn(__PACKAGE__->expected_tests());
}

Original: https://rt.cpan.org/Ticket/Display.html?id=123142

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

1 participant