Test suite defects: duplicated list, diag prints a variable name, wrong label
- Dominant language
- Perl
- Stars
- 4
- Forks
- 3
- PR merge metrics
- No merged PRs in 30d
Description
Three problems in the tests, one of which removes coverage.
`t/131-utils-mac-properties.t:175` iterates `( @unicasteui48macs, @unicasteui48macs )`. The second list was clearly meant to be `@multicasteui48macs`, which is defined a few lines earlier and is otherwise never checked against `mac_is_vrrp`, `mac_is_hsrp`, `mac_is_hsrp2` or `mac_is_msnlb`. The plan drops from 311 to 307 because the multicast list has three entries where the unicast list has four.
`t/133-random.t:80` has `diag( 'Error: ' . eval { '$NetAddr::MAC::errstr' } )`. A single-quoted string inside `eval` is just a string, so on failure the diagnostic prints the literal text `$NetAddr::MAC::errstr` rather than the error. Referencing the variable directly is fatal in that file because `use warnings FATAL => 'all'` turns the "used only once" warning into an exception, which is presumably how the hack arose. The class method `NetAddr::MAC->errstr` exists for this and avoids both problems.
`t/132-utils-mac-normals.t:43` labels the `mac_as_microsoft` assertion `Check mac_as_cisco output`.
**Verification**
After the diff `prove -l t/` passes with 389 tests (previously 393; the four removed were duplicates). The multicast EUI-48 addresses are now asserted false for all four protocol predicates.
Applies on top of #16, because `t/133` also exercises the `random()` changes there.
**Suggested fix**
```diff
diff --git a/t/131-utils-mac-properties.t b/t/131-utils-mac-properties.t
index cb39b89..b5bb1a2 100755
--- a/t/131-utils-mac-properties.t
+++ b/t/131-utils-mac-properties.t
@@ -1,7 +1,7 @@
use strict;
use warnings;
-use Test::More tests => 311;
+use Test::More tests => 307;
use Test::Trap;
BEGIN {
@@ -172,7 +172,7 @@ BEGIN {
ok( !mac_is_msnlb($mac), 'eui64 is never msnlb from ' . $mac);
}
- for my $mac ( @unicasteui48macs, @unicasteui48macs ) {
+ for my $mac ( @unicasteui48macs, @multicasteui48macs ) {
ok( !mac_is_vrrp($mac), 'vrrp = false from ' . $mac);
ok( !mac_is_hsrp($mac), 'hsrp = false from ' . $mac);
ok( !mac_is_hsrp2($mac), 'hsrp2 = false from ' . $mac);
diff --git a/t/132-utils-mac-normals.t b/t/132-utils-mac-normals.t
index 5eaeaff..4e034cc 100755
--- a/t/132-utils-mac-normals.t
+++ b/t/132-utils-mac-normals.t
@@ -40,7 +40,7 @@ is(mac_as_bpr('10-00-5A-4D-BC-96'), lc('1,6,10:00:5A:4D:BC:96'),'Check mac_as_bp
is(mac_as_cisco('10-00-5A-4D-BC-96'), lc('1000.5A4D.BC96'),'Check mac_as_cisco output');
is(mac_as_ieee('1000.5A4D.BC96'), lc('10:00:5A:4D:BC:96'),'Check mac_as_ieee output');
# ipv6 needed
-is(mac_as_microsoft('10005A4DBC96'), lc('10-00-5A-4D-BC-96'),'Check mac_as_cisco output');
+is(mac_as_microsoft('10005A4DBC96'), lc('10-00-5A-4D-BC-96'),'Check mac_as_microsoft output');
is(mac_as_singledash('1000.5A4D.BC96'), lc('10005A-4DBC96'),'Check mac_as_singledash output');
is(mac_as_pgsql('1000.5A4D.BC96'), lc('10005A:4DBC96'),'Check mac_as_pgsql output');
is(mac_as_sun('1000.5A4D.BC96'), lc('10-0-5A-4D-BC-96'),'Check mac_as_sun output');
diff --git a/t/133-random.t b/t/133-random.t
index 196ed52..3eb4585 100755
--- a/t/133-random.t
+++ b/t/133-random.t
@@ -77,7 +77,7 @@ for my $case (@cases) {
if ($case->{expect_defined}) {
ok(defined $mac, "$case->{desc} (object defined)")
- or diag( 'Error: ' . eval { '$NetAddr::MAC::errstr' } );
+ or diag( 'Error: ' . ( NetAddr::MAC->errstr // 'undef' ) );
if (defined $mac && $case->{match}) {
my $mac_str = $mac->as_ieee;
my %args = (@{$case->{args}} % 2 == 0)
```
Found during a review of master at 4a255fa (v1.01).
Contributor guide
Research direction
Review the three named test files: t/131-utils-mac-properties.t, t/132-utils-mac-normals.t, and t/133-random.t. Compare each reported defect with the surrounding tests and the NetAddr::MAC->errstr entry point, then run prove -l t/; done means the corrected assertions and diagnostic pass with 389 tests and no duplicate coverage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- perl
- Domain
- testing
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 92/100