Test-More / Test-More/test-more

hash comparison from documentation is incorrect: etc was the default

Open
#975 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Perl
Stars
149
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Using perl524 with Test2::Tools::Compare from Test2-Suite-0.000067
the following example is not working

#!/bin/env perl

use strict;
use warnings;

use Test2::Bundle::Extended;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;

my $some_hash = { a => 1, b => 42, c => 12345 };

is(
    $some_hash,
    hash {    # Note: the hash function is not exported by default
        field a => 1;
        field b => match(qr/[0-9]+/);    # Note: The match function is not exported by default
        # Don't care about other fields.
    },
    "The hash comparison is not strict"
);
> prove -v test.pl
test.pl ..
# Seeded srand with seed '20170118' from local date.
ok 1 - The hash comparison is not strict
not ok 2 - Unexpected warning: !!! NOTICE OF BEHAVIOR CHANGE !!!
This test uses at least 1 <HASH> check without using end() or etc().
The old behavior was to default to etc() when inside is().
The old behavior was a bug.
The new behavior is to default to end().
This test will soon start to fail with the following diagnostics:
+------+----------------+---------+------------------+--------+
| PATH | GOT            | OP      | CHECK            | LNs    |
+------+----------------+---------+------------------+--------+
|      | HASH(0xd9d6c8) |         | <HASH>           | 32, 35 |
| {c}  | 12345          | !exists | <DOES NOT EXIST> |        |
+------+----------------+---------+------------------+--------+
 at test.pl line 37.
# Tests were run but no plan was declared and done_testing() was not seen.
Dubious, test returned 1 (wstat 256, 0x100)
Failed 1/2 subtests

Test Summary Report
-------------------
test.pl (Wstat: 256 Tests: 2 Failed: 1)
  Failed test:  2
  Non-zero exit status: 1
  Parse errors: No plan found in TAP output
Files=1, Tests=2,  0 wallclock secs ( 0.03 usr  0.00 sys +  0.10 cusr  0.01 csys =  0.14 CPU)
Result: FAIL

I see two problems there:
1/ the doc is not up to date as etc is not the default behavior now, we should document to use either etc or end
2/ If you run this test inside a subtest... then you have no correct warning message displayed... and the test fails...

my $some_hash = { a => 1, b => 42, c => 12345 };

subtest Foo => sub {
	is(
    $some_hash,
    hash {    # Note: the hash function is not exported by default
        field a => 1;
        field b => match(qr/[0-9]+/);    # Note: The match function is not exported by default
        # Don't care about other fields.
        #etc();
    },
    "The hash comparison is not strict"
);
};
> prove -v test.pl
test.pl ..
# Seeded srand with seed '20170118' from local date.
not ok 1 - Foo {
    ok 1 - The hash comparison is not strict
    1..2
}
# Failed test 'Foo'

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the two examples in test.pl using Test2::Tools::Compare, especially the hash comparison inside the subtest. Read the hash-comparison documentation and the warning behavior around etc() and end(); done means the documentation reflects the current default and the subtest case reports the correct warning and test result.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.