-
Notifications
You must be signed in to change notification settings - Fork 149
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
Cassandane::Tiny: Import strict/warnings to consumers #5117
base: master
Are you sure you want to change the base?
Cassandane::Tiny: Import strict/warnings to consumers #5117
Conversation
(This identified a bunch of compilation problems that need to be cleaned up; I'll work on that and include them in this MR...) |
e11c352
to
c756170
Compare
This way any tiny test gets them by default, avoiding mistakes like forgetting to declare variables, etc...
- Declare variables where we forgot to - Don't declare the same variable multiple times - Things like {alerts\n} are treated as a function lookup, so wrap the keys in quotes (or reflow them to be on one line) - sort wants $a and $b, not $_ (which was a random string!)
c756170
to
bbc7429
Compare
tiny-tests/Caldav/options was throwing: Variable "$caldav" will not stay shared at ./tiny-tests/Caldav/options line 11. This is because it was defining a subroutine that was closing over variables inside of another subroutine. This generally doesn't do what you expect, so instead lets make the subroutine itself an anonymous subroutine which will be generated at runtime and close over outer scope variables properly. In newer Perl we could use a 'my sub...', but I don't believe we are aiming to require a high enough version of Perl yet.
This test was doing `foo => qw(3,7)`, and then later attempting to assign that to a list of variables. But this doesn't work right for three reasons: 1. foo => qw(3,7) - qw() makes a list of items delimted by spaces, not commas, so this was returning a single item, the string "3,7". 2. If this was `foo => qw(3 7)` as likely intended, it would assign the value `3` to the key `foo`, and then create a key `7` with the value `undef`! 3. The assignment `my ($needMaj, $needMin) = $tc->{skipVersionBefore}` does not dereference the value of skipVersionBefore, so it only ever sets `$needMaj`. So let's switch to using arrayrefs directly and dereference them when needed.
Before we didn't have strict, do dereferencing undef was fine. With strict we have to be more careful/explicit.
And $_ would have contained a non-ref, and so crashed!
Without strict it didn't matter, but with strict it does.
Back in d7c8b4f the uid property was removed from default alerts. This test wasn't updated to account for that, but continued to pass because my $uid = (values %{$defaultAlertsWithTime})->{uid}; $self->assert_matches(qr/UID:$uid/, $res->{content}); would end up with an undef value in $uid and so the assertion would succeed. Now with strict we see that (values %{$defaultAlertsWithTime})->{uid} crashes because values uses in this way returns a count of how many items were in the hash, and so we try to deref that as a hashref and fail. Instead, ensure that depending on which alarms are currently configured, we get the correct alarm id for both the owner and the sharee.
This is something we need to solve more generally, but the main problem is that each tiny test actually exists in the parent package that has loaded it, so any subroutines it defines is visible in the parent. This means if two tests define the same sub, one of those subs will be clobbered. Ugh. For now, let's side step the problem by giving the two (identical) subroutines different names. This is a hack, but puts us in a better place, and we can solve the real problem later.
This should be all set |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Woof - nice!
Waiting for @elliefm to chime in, too. |
Wow, thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice
} | ||
|
||
sub _can_match { | ||
sub _can_match_b { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these two functions identical? In that case I would've just moved it up to the parent. The fact that you gave them distinct names instead makes me think maybe they were distinct functions sharing a name, but the bodies don't show in the diff and I didn't look any deeper to find out
This way any tiny test gets them by default, avoiding mistakes like forgetting to declare variables, etc...