Hi,

On 04/13/2016 02:52 PM, Zoffix Znet (via RT) wrote:
# New Ticket Created by  Zoffix Znet
# Please include the string:  [perl #127890]
# in the subject line of all future correspondence about this issue.
# <URL: https://rt.perl.org/Ticket/Display.html?id=127890 >


Hey,

I propose we make Test.pm6's `subtest` a multi sub that can also take a Pair. 
The key of the Pair is to be the description of the test and the value is to be 
the codeblock to run.

Test.pm6 has `subtest` sub that lets you group your tests. It takes a code 
block and description, but that description follows AFTER the codeblock, 
following the same pattern as all the other subs the module provides.

The problem is unlike all the other subs, `subtest` takes a codeblock, which 
can get large quickly.
A programmer reading the code has to skip through all the way to the END of the 
codeblock to find
the description and understand what the subtest is testing.

Here's an example of the current way to use subtest:

     subtest {
         my $res= $glot.list;
         ok $res.keys ⊆ <next content last>, 'return keys match expectations';

         my $expected
         = <created files_hash id language modified owner public title url>;
         for |$res<content> {
             ok .keys ⊆ $expected, 'item keys match expectations';
         }
     }, '.list method';

My proposal, if implemented, would allove the above to be written as:

     subtest '.list method' => {
         my $res= $glot.list;
         ok $res.keys ⊆ <next content last>, 'return keys match expectations';

         my $expected
         = <created files_hash id language modified owner public title url>;
         for |$res<content> {
             ok .keys ⊆ $expected, 'item keys match expectations';
         }
     };

Why not simply allow two ordinary arguments?

Like this:
subtest 'description', { code here };

Since one of the arguments is always a string or String-alike (probably Cool), and the other is always Callable, there shouldn't be any ambiguous cases.

All in all I approve of this idea though.

Cheers,
Moritz

Reply via email to