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

Convert tests to using subtests #1520

Open
kraih opened this issue May 20, 2020 · 6 comments
Open

Convert tests to using subtests #1520

kraih opened this issue May 20, 2020 · 6 comments

Comments

@kraih
Copy link
Member

kraih commented May 20, 2020

Not a particularly hard task, but converting all tests is a lot of work. We want to go from:

# Promisify
is ref Mojo::Promise->resolve('foo'), 'Mojo::Promise', 'right class';
$promise = Mojo::Promise->reject('foo');
is ref $promise, 'Mojo::Promise', 'right class';
@errors = ();
$promise->catch(sub { push @errors, @_ })->wait;
is_deeply \@errors, ['foo'], 'promise rejected';
$promise = Mojo::Promise->resolve('foo');
is refaddr(Mojo::Promise->resolve($promise)), refaddr($promise), 'same object';
$promise = Mojo::Promise->resolve('foo');
isnt refaddr(Mojo::Promise->new->resolve($promise)), refaddr($promise),
  'different object';
$promise = Mojo::Promise->reject('foo');
is refaddr(Mojo::Promise->resolve($promise)), refaddr($promise), 'same object';
@errors = ();
$promise->catch(sub { push @errors, @_ })->wait;
is_deeply \@errors, ['foo'], 'promise rejected';
$promise  = Mojo::Promise->reject('foo');
$promise2 = Mojo::Promise->reject($promise);
isnt refaddr($promise2), refaddr($promise), 'different object';
@errors = ();
$promise2->catch(sub { push @errors, @_ })->wait;
is_deeply \@errors, ['foo'], 'promise rejected';

to:

subtest 'Promisify' => sub {
  is ref Mojo::Promise->resolve('foo'), 'Mojo::Promise', 'right class';

  $promise = Mojo::Promise->reject('foo');
  is ref $promise, 'Mojo::Promise', 'right class';
  @errors = ();
  $promise->catch(sub { push @errors, @_ })->wait;
  is_deeply \@errors, ['foo'], 'promise rejected';

  $promise = Mojo::Promise->resolve('foo');
  is refaddr(Mojo::Promise->resolve($promise)), refaddr($promise),
    'same object';

  $promise = Mojo::Promise->resolve('foo');
  isnt refaddr(Mojo::Promise->new->resolve($promise)), refaddr($promise),
    'different object';

  $promise = Mojo::Promise->reject('foo');
  is refaddr(Mojo::Promise->resolve($promise)), refaddr($promise),
    'same object';
  @errors = ();
  $promise->catch(sub { push @errors, @_ })->wait;
  is_deeply \@errors, ['foo'], 'promise rejected';

  $promise  = Mojo::Promise->reject('foo');
  $promise2 = Mojo::Promise->reject($promise);
  isnt refaddr($promise2), refaddr($promise), 'different object';
  @errors = ();
  $promise2->catch(sub { push @errors, @_ })->wait;
  is_deeply \@errors, ['foo'], 'promise rejected';
};

Block comments become the subtest description, and then we add a blank line in between unrelated test cases within the subtest. Here is another example.

@kraih
Copy link
Member Author

kraih commented May 20, 2020

And you don't have to convert all tests at once, one PR per test file should be fine.

@kraih
Copy link
Member Author

kraih commented May 20, 2020

We've converted promise.t in its entirety first, so there is an example for what's expected.

@kraih
Copy link
Member Author

kraih commented May 22, 2020

And cgi.t has been converted so there's an example for a test with lite app.

@kraih kraih pinned this issue May 22, 2020
This was referenced Oct 23, 2020
@kraih
Copy link
Member Author

kraih commented Apr 6, 2021

Since we keep linking to the issue, it is probably worth mentioning that all new code should always use subtests. Even if the test file it is added to has not been converted yet.

mergify bot added a commit that referenced this issue Aug 9, 2021
Convert to using subtests per issue #1520
mergify bot added a commit that referenced this issue Aug 13, 2021
Convert to using subtests per issue #1520
tschaefer added a commit to tschaefer/mojo that referenced this issue Feb 11, 2022
tschaefer added a commit to tschaefer/mojo that referenced this issue Feb 13, 2022
tschaefer added a commit to tschaefer/mojo that referenced this issue Feb 25, 2022
tschaefer added a commit to tschaefer/mojo that referenced this issue Mar 9, 2022
tschaefer added a commit to tschaefer/mojo that referenced this issue Apr 2, 2022
karenetheridge pushed a commit to karenetheridge/Mojolicious that referenced this issue Sep 20, 2023
karenetheridge pushed a commit to karenetheridge/Mojolicious that referenced this issue Sep 20, 2023
karenetheridge pushed a commit to karenetheridge/Mojolicious that referenced this issue Sep 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant