Skip to content

Migrate flutter_test#66663

Merged
goderbauer merged 13 commits intoflutter:masterfrom
goderbauer:flutter_test_mirgation
Oct 1, 2020
Merged

Migrate flutter_test#66663
goderbauer merged 13 commits intoflutter:masterfrom
goderbauer:flutter_test_mirgation

Conversation

@goderbauer
Copy link
Member

@goderbauer goderbauer commented Sep 25, 2020

Description

Migrates flutter_test to null-safety.

I will migrate the tests of this package in a separate PR.

Related Issues

Fixes #53908.

Tests

I added the following tests:

n/a

Checklist

Before you create this PR, confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

@flutter-dashboard flutter-dashboard bot added a: tests "flutter test", flutter_test, or one of our tests framework flutter/packages/flutter repository. See also f: labels. c: contributor-productivity Team-specific productivity, code health, technical debt. work in progress; do not review labels Sep 25, 2020
@skia-gold

This comment has been minimized.

@goderbauer goderbauer force-pushed the flutter_test_mirgation branch from b8aa3f6 to 839f517 Compare September 25, 2020 19:15
@skia-gold

This comment has been minimized.

@skia-gold

This comment has been minimized.

1 similar comment
@skia-gold

This comment has been minimized.

@skia-gold

This comment has been minimized.

@goderbauer goderbauer force-pushed the flutter_test_mirgation branch from b33ea19 to 2f0c561 Compare September 25, 2020 23:26
@flutter-dashboard flutter-dashboard bot added f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. labels Sep 28, 2020
@goderbauer goderbauer marked this pull request as ready for review September 28, 2020 00:10
@goderbauer goderbauer requested a review from Piinks as a code owner September 28, 2020 00:10
@goderbauer
Copy link
Member Author

Marking this PR as ready for review triggered a whole bunch of new checks. Probably worthwhile to wait and see if all those pass before starting a review.

@gspencergoog
Copy link
Contributor

Looks like they passed. Yay! I'll take a look at this tomorrow.

Comment on lines 243 to 245
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Future<HttpClientResponse> get done {
return Future<HttpClientResponse>.value(_MockHttpResponse());
}
Future<HttpClientResponse> get done async => _MockHttpResponse();

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
final RenderBox renderObject = element.renderObject as RenderBox;
final RenderBox renderObject = element.renderObject! as RenderBox;

Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps throwing something is better here?

Copy link
Contributor

Choose a reason for hiding this comment

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

== true could be removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
final RenderRepaintBoundary boundary = boundaryKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
final RenderRepaintBoundary boundary = boundaryKey.currentContext!.findRenderObject()! as RenderRepaintBoundary;

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
renderObject = renderObject.parent as RenderObject;
renderObject = renderObject.parent! as RenderObject;

Copy link
Contributor

Choose a reason for hiding this comment

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

break?

@goderbauer goderbauer force-pushed the flutter_test_mirgation branch from 2f0c561 to d19b8ec Compare September 28, 2020 16:53
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't casting it to Object (as opposed to Object?) imply the !?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it does. But @a14n is working on a lint that will require you to specifically think about null and add the ! to say that you thought about nullability and this cannot be null here.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK. When that lint is turned on, I'm sure we'll have a bunch of places to fix.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, a14n has already been fixing up our code base in prep for that.

@goderbauer
Copy link
Member Author

@a14n @gspencergoog All comments addressed. Thanks for the review! PTAL.

@goderbauer
Copy link
Member Author

While trying this change out in the google codebase I noticed a minor setback: flutter_test does import the material lib, which is not fully migrated yet. Specifically, flutter_test uses the Tooltip and the Card type to implement the find.byTooltip finder and the isInCard matcher.

Since in google internally, a lib can only have null safety turned on when all its imports are also null safe, we will have to migrate material's Tooltip and Card (plus all their imports) first before we can submit this.

/cc @a14n @gspencergoog

Copy link
Contributor

Choose a reason for hiding this comment

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

that second bug is closed

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed.

Copy link
Contributor

Choose a reason for hiding this comment

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

should we check if renderObject is non-null? Or is it more or less guaranteed to be?

Copy link
Member Author

Choose a reason for hiding this comment

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

Added an assert.

Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor

Choose a reason for hiding this comment

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

similar here; what if someone ends up calling this before layout/paint have run? you can change the phase in a test.

Copy link
Contributor

Choose a reason for hiding this comment

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

yikes, do we document / check that this is only used with RenderBoxes?

Copy link
Member Author

Choose a reason for hiding this comment

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

I added an assert. Currently, it is guaranteed that the renderObject will always be a RenderBox because the element finder above only returns Elements of Text or Editable widgets, which will always have RenderBox elements.

Copy link
Contributor

Choose a reason for hiding this comment

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

docs should mention T

Copy link
Contributor

Choose a reason for hiding this comment

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

nit: switch ((space before(`)

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I saw this when I did my review, and it simplifies other code here, but doesn't change behavior, so a net win.

Copy link
Contributor

Choose a reason for hiding this comment

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

i wonder how many people ever use this and whether we should just remove it. I don't think I've used it once since implementing it.

Copy link
Contributor

Choose a reason for hiding this comment

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

(just an idle thought unrelated to this PR obviously)

Copy link
Contributor

@Hixie Hixie left a comment

Choose a reason for hiding this comment

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

LGTM

@goderbauer goderbauer force-pushed the flutter_test_mirgation branch 3 times, most recently from 4738563 to 71a7d08 Compare September 30, 2020 16:38
@goderbauer goderbauer force-pushed the flutter_test_mirgation branch from 71a7d08 to 6316779 Compare September 30, 2020 23:13
@goderbauer goderbauer merged commit 19e07d2 into flutter:master Oct 1, 2020
@goderbauer goderbauer deleted the flutter_test_mirgation branch October 1, 2020 00:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests c: contributor-productivity Team-specific productivity, code health, technical debt. f: cupertino flutter/packages/flutter/cupertino repository f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enable null safety for flutter_test

6 participants