-
Notifications
You must be signed in to change notification settings - Fork 33
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
Updates TestUtil.pm for unit tests #1340
Updates TestUtil.pm for unit tests #1340
Conversation
t/TestUtil.pm
Outdated
(in all uppercase), and their corresponding values are an array of: | ||
|
||
=over | ||
|
||
=item * | ||
a boolean (testable) | ||
|
||
=item * | ||
a string (zone name) | ||
|
||
=item * | ||
an array of strings (all test case message tags) | ||
|
||
=item * | ||
an array of strings (mandatory message tags) | ||
|
||
=item * | ||
an array of strings (forbidden message tags) | ||
|
||
=item * | ||
an array of name server expressions for undelegated name servers | ||
|
||
=item * | ||
an array of DS expressions for "undelegated" DS | ||
|
||
=back |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are a lot of positional arguments. I suggest replacing the arrayref of positional arguments with a hashref of named arguments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that I understand what you mean, but that will make it more complex to create e.g. t/Test-nameserver15.t
and harder to read it. Please note that "all test case message tags" will just be a variable, and that the two last arguments will not be used in most cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how you're measuring complexity in the call site. The calling code would be easier to read and less error prone because you wouldn't run the risk of mixing up the arguments. There would be more code inside perform_testcase_testing() but this is a quite good investment.
t/TestUtil.pm
Outdated
if ( ref( $testable ) ne '' ) { | ||
diag("Scenario $scenario: Type of testable must not be a reference"); | ||
fail("Testable is of the correct type"); | ||
next; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is problematic for a couple of reasons, but the biggest one is that the diag() and fail() methods are uses here for complaining about the test script. They should only be used for complaining about the object under test. When complaining about the test script it's better to use croak().
There are more of these below.
I do realize you followed the established pattern, but it would be a really good to break this pattern.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not new code. It is the same code as in the current version, but moved up. Could you suggest the replacement code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just replace the diag
, fail
and next
with a croak
.
t/TestUtil.pm
Outdated
|
||
if ( ref( $zone_name ) ne '' ) { | ||
diag("Scenario $scenario: Type of zone name must not be a reference"); | ||
fail("Zone name is of the correct type"); | ||
next; | ||
} | ||
|
||
if ( ref( $mandatory_message_tags ) ne 'ARRAY' ) { | ||
if ( ref( $all_test_case_tags ) ne 'ARRAY' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we care to verify that it's an array, shouldn't we also check the type of the array elements?
There are more of these below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not new code. It is the same code as in the current version, but maybe moved. What you suggest is that all elements in the array should be matching the tag format? I guess that could be done. Should that also use croak() instead of diag/fail? If so, what is the benefit of croak?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think it’s useful to check the type of the array elements: because the array is usually prepared using qw()
, it is reasonable to assume that each element can be treated as a string. I’m not saying this kind of thorough checking shouldn’t be done; only that I don’t mind if it isn’t done.
However, I do agree that we should use croak
instead of diag
and fail
here. We don’t want to raise an issue with the domain under test here, but with the code that tests the code. In that case, aborting early gives a stronger signal that the problem is with the testing code.
Co-authored-by: Mattias Päivärinta <mattias@paivarinta.se>
* Replaces diag/fail with croak(). * Additional verification of test data from t file. * Moved "all tags" to be a common parameter, not scenario specific.
@mattias-p, please re-review. |
@mattias-p, could your re-review? |
my %subtests = ( | ||
'NO-RESPONSE-MX-QUERY' => [ | ||
q(no-response-mx-query.zone09.xa), | ||
1, | ||
q(no-response-mx-query.zone09.xa),# |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is there a trailing #
here? (many other occurrences below)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tagged scenarios where MANDATORY and FORBIDDEN did not cover all tags. I'll make it explicit.
Co-authored-by: tgreenx <96772376+tgreenx@users.noreply.github.com>
@tgreenx and @mattias-p, please re-review. |
@mattias-p, @tgreenx and @marc-vanderwal, can you approve this? I would like to merge it. It updates TestUtils.pm and the unit tests that use it. They pass as expected. |
I’ve had a look. I see no issues that haven’t already been brought up by @tgreenx. |
Co-authored-by: tgreenx <96772376+tgreenx@users.noreply.github.com>
@marc-vanderwal and @tgreenx, please re-review after my latest updates. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks fine. I do think that croak
is better than diag
/fail
when there is a problem with the data in the test script. It’s better to have a specific failure mode for problems with the testing code, that can’t be confused with the outcome of a failing unit test suite for reasons unrelated to the testing code itself.
t/TestUtil.pm
Outdated
|
||
if ( ref( $zone_name ) ne '' ) { | ||
diag("Scenario $scenario: Type of zone name must not be a reference"); | ||
fail("Zone name is of the correct type"); | ||
next; | ||
} | ||
|
||
if ( ref( $mandatory_message_tags ) ne 'ARRAY' ) { | ||
if ( ref( $all_test_case_tags ) ne 'ARRAY' ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don’t think it’s useful to check the type of the array elements: because the array is usually prepared using qw()
, it is reasonable to assume that each element can be treated as a string. I’m not saying this kind of thorough checking shouldn’t be done; only that I don’t mind if it isn’t done.
However, I do agree that we should use croak
instead of diag
and fail
here. We don’t want to raise an issue with the domain under test here, but with the code that tests the code. In that case, aborting early gives a stronger signal that the problem is with the testing code.
t/TestUtil.pm
Outdated
} | ||
|
||
if ( ! defined( $mandatory_message_tags ) and !defined( $forbidden_message_tags ) ) { | ||
diag("Scenario $scenario: Not both array of mandatory tags and array of forbidden tags can be undefined"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
diag("Scenario $scenario: Not both array of mandatory tags and array of forbidden tags can be undefined"); | |
diag("Scenario $scenario: Arrays of mandatory tags and forbidden tags cannot be both undefined"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your proposal must be based on old code. The current code uses "croak" for such tests.
@marc-vanderwal and @tgreenx, please re-review after my latest updates. All tests pass. TestUtil now treats empty-empty as an error. Can this be merged now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marc-vanderwal and @tgreenx, please re-review after my latest updates. All tests pass. TestUtil now treats empty-empty as an error. Can this be merged now?
Almost! A few nits left:
Co-authored-by: tgreenx <96772376+tgreenx@users.noreply.github.com>
I have commited the proposal from @tgreenx and I have updated the documentation so that it states that empty-empty is not permitted. @marc-vanderwal and @tgreenx, please re-review. |
Co-authored-by: Marc van der Wal <103426270+marc-vanderwal@users.noreply.github.com>
@marc-vanderwal and @tgreenx, please re-review. |
Purpose
This PR introduces two changes to function in TestUtil.pm:
t
file. Use croak() instead.The unit test files using TestUtil.pm have been updated to match the new format.
Five new scenarios have been added to Consistency05 and two to Consistency06. Both updates are to unit tests that uses the new function in TestUtil.pm that supports undelegated data.
The following new scenario fail:
Context
The update is needed for zonemaster/zonemaster#1255.
How to test this PR
Review TestUtil.pm. If the unit test files using TestUtil.pm then they should be fine.