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

Test.pm6 make subtest multi to take description first #5237

Closed
p6rt opened this issue Apr 13, 2016 · 7 comments
Closed

Test.pm6 make subtest multi to take description first #5237

p6rt opened this issue Apr 13, 2016 · 7 comments
Labels
RFC Request For Comments

Comments

@p6rt
Copy link

p6rt commented Apr 13, 2016

Migrated from rt.perl.org#127890 (status was 'resolved')

Searchable as RT127890$

@p6rt
Copy link
Author

p6rt commented Apr 13, 2016

From @zoffixznet

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';
  }
  };

It's immediately clear that the subtest is for the .list method, without any need to skim to the end. Also, this mirrors how the most common testing module in Perl 5 offers the `subtest` sub (https://metacpan.org/pod/Test::More#subtest).

If the proposal is approved, I'm happy to write the code and tests. The one issue I'm wondering about is versioning. Were the feature implemented today, modules that use the new `subtest` multi for tests won't work on, say, 2016.01 Perl 6. How would we resolve that?

@p6rt
Copy link
Author

p6rt commented Apr 13, 2016

From @moritz

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-archive.perl.org/perl6/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

@p6rt
Copy link
Author

p6rt commented Apr 13, 2016

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Apr 13, 2016

From @zoffixznet

On Wed Apr 13 06​:36​:41 2016, moritz wrote​:

Why not simply allow two ordinary arguments?

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

Sure, that works too. Maybe it's just my Perl 5 mind, but the version with `=>` kinda says "this description is FOR THIS code." Maybe it's just me.

All in all I approve of this idea though.

Alright. I'll submit code and tests. This will need to be deferred until 6.d, won't it? If we release and document this right now, modules using the new subtest version might not work, depending on which 6.c compiler version the user is using.

@p6rt
Copy link
Author

p6rt commented Apr 13, 2016

From @zoffixznet

PR for this feature​: rakudo/rakudo#743

@p6rt
Copy link
Author

p6rt commented May 18, 2016

From @zoffixznet

The PR implementing this has been merged in rakudo/rakudo@e239f6e

Closing.

@p6rt
Copy link
Author

p6rt commented May 18, 2016

@zoffixznet - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed May 18, 2016
@p6rt p6rt added the RFC Request For Comments label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC Request For Comments
Projects
None yet
Development

No branches or pull requests

1 participant