Conversation
|
I added another commit "Compare partial data structure and use 'bag' check for sets" showing how more sophisticated data structure tests can be made. I removed the usage of
|
|
But https://metacpan.org/pod/Test2::V1 "is out now" :) Should we use that? |
Yes. That actually "fixes" the problem with srand - srand is off by default in V1. We have to submit that version To Leap 16 though |
|
It seems # Test::MockObject
my $obj = Test::MockObject->new->set_always(is_server_error => 1)->set_always(json => {error => 'fake error'});
# Test2::V0
my $obj = mock 'obj', {is_server_error => 1, json => {error => 'fake error'}};
say $obj->is_server_error; # 1
say $obj->something; # undefSo the given hashref provides the return values for the methods, but calling any other method will not die, but simply return undef. Which seems a bit odd to me, but probably not a problem. |
|
my $obj = mock obj => {} => (
add => [
methodname => sub { state @ret = qw(a b c); return shift @ret }
]
); |
| my $check = bag { item $_ for $jobW->id, $jobU->id, $jobR->id, $jobT->id; end() }; | ||
| is $jobQ_deps->{children}->{Chained}, $check, 'jobQ is chained parent to all jobs except jobTA'; | ||
| is $jobQ_deps->{children}->{'Directly chained'}, [$jobTA->id], 'jobQ is directly chained parent to jobTA'; |
There was a problem hiding this comment.
This new test API allows for shorter code but the code is also less intuitive with "magic" functions like bag, item and end() that are not really self-explanatory.
|
Looks generally interesting. |
|
This pull request is now in conflicts. Could you fix it? 🙏 |
This is to show how Test2::V0 can be used.
Some differences:
iscan replaceis_deeplyand it can be more clever - you can leave out parts of the data structure you're not interested inmockandmock_objfunction. Call tracking is possible. It also offersbefore,afterandaround. https://metacpan.org/pod/Test2::Tools::Mockexplainfunction :( (but there is https://metacpan.org/dist/Test2-Tools-Explain )-no_srand => 1because otherwise the test database schema name will not be random and complain that it exists already (from a previous run). Maybe there is a better way to work around thatref_okfor checking a type of a variable