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

Cassandane::Tiny: Import strict/warnings to consumers #5117

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

wolfsage
Copy link
Contributor

@wolfsage wolfsage commented Nov 5, 2024

This way any tiny test gets them by default, avoiding mistakes like forgetting to declare variables, etc...

@wolfsage wolfsage marked this pull request as draft November 5, 2024 13:14
@wolfsage
Copy link
Contributor Author

wolfsage commented Nov 5, 2024

(This identified a bunch of compilation problems that need to be cleaned up; I'll work on that and include them in this MR...)

@wolfsage wolfsage force-pushed the cassandane-tiny-strict-warnings branch from e11c352 to c756170 Compare November 5, 2024 16:35
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!)
@wolfsage wolfsage force-pushed the cassandane-tiny-strict-warnings branch from c756170 to bbc7429 Compare November 6, 2024 14:56
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.
@wolfsage wolfsage marked this pull request as ready for review November 6, 2024 17:20
@wolfsage
Copy link
Contributor Author

wolfsage commented Nov 6, 2024

This should be all set

Copy link
Member

@rsto rsto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Woof - nice!

@rsto
Copy link
Member

rsto commented Nov 6, 2024

Waiting for @elliefm to chime in, too.

@rjbs
Copy link
Collaborator

rjbs commented Nov 7, 2024

Wow, thanks.

Copy link
Contributor

@elliefm elliefm left a 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 {
Copy link
Contributor

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

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.

5 participants