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

defer wrapping leaves passed to all/any/none #56

Closed
wants to merge 5 commits into from
Closed

Conversation

rjbs
Copy link
Owner

@rjbs rjbs commented Apr 17, 2017

Before this change, leaves (plain strings and numbers) passed to
all/any/none were converted to "real tests" with Test::Deep::wrap
during the all/any/none test's initialization. This meant that
they were subject to the $LeafWrapper in place when any() was called,
rather than when the enclosing cmp_deeply was called. This meant that
leaves inside and outside of all/any/none were treated differently.

Here's a test, not suitable for inclusion, that demonstrated the
problem:

  use strict;
  use warnings;

  use JSON;
  use JSON::Typist;
  use Test::Deep;
  use Test::Deep::JType;
  use Test::More;

  my $json = q<{"foo":1}>;
  my $data = JSON::Typist->new->apply_types(decode_json($json));

  jcmp_deeply($data->{foo}, 1);
  jcmp_deeply($data->{foo}, jnum(1));
  jcmp_deeply($data->{foo}, any(jnum(1)));
  jcmp_deeply($data->{foo}, any(1)); # <-- fails, 1 doesn't right wrapper

  done_testing;

Before this change, leaves (plain strings and numbers) passed to
all/any/none were converted to "real tests" with Test::Deep::wrap
during the all/any/none test's initialization.  This meant that
they were subject to the $LeafWrapper in place when any() was called,
rather than when the enclosing cmp_deeply was called.  This meant that
leaves inside and outside of all/any/none were treated differently.

Here's a test, not suitable for inclusion, that demonstrated the
problem:

  use strict;
  use warnings;

  use JSON;
  use JSON::Typist;
  use Test::Deep;
  use Test::Deep::JType;
  use Test::More;

  my $json = q<{"foo":1}>;
  my $data = JSON::Typist->new->apply_types(decode_json($json));

  jcmp_deeply($data->{foo}, 1);
  jcmp_deeply($data->{foo}, jnum(1));
  jcmp_deeply($data->{foo}, any(jnum(1)));
  jcmp_deeply($data->{foo}, any(1)); # <-- fails, 1 doesn't right wrapper

  done_testing;
@wolfsage
Copy link
Contributor

Seems legit. Are there any tests we can write to show the fix?

@rjbs
Copy link
Owner Author

rjbs commented Apr 17, 2017

I started on some but they didn't demonstrate the problem. I'll get back to them now-ish.

This commit moves tests for $LeafWrapper from shallow.t to a new test
file.

It also adds tests for the bug caused by all/any/none wrapping their
arguments at init time instead of at test time.  Without the fix, the
second set of tests fail because the $LeafWrapper in play for the calls
to any and all is shallow() and not str().
@rjbs
Copy link
Owner Author

rjbs commented Apr 17, 2017

I was close. Now I got it. :)

@rjbs rjbs closed this May 4, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants