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

Migrate tests to null-safety #67692

Merged
merged 2 commits into from Oct 9, 2020
Merged

Conversation

@goderbauer
Copy link
Member

@goderbauer goderbauer commented Oct 8, 2020

No description provided.

fix
Copy link
Contributor

@justinmc justinmc left a comment

LGTM 👍

@@ -55,7 +53,7 @@ class _TimePickerLauncher extends StatelessWidget {
}
}

Future<Offset> startPicker(
Future<Offset?> startPicker(

This comment has been minimized.

@justinmc

justinmc Oct 9, 2020
Contributor

First time I've seen nullable type parameters.

@@ -419,7 +417,7 @@ void _tests() {
);

// Ensure we preserve day period as we roll over.
final dynamic pickerState = tester.state(_timePickerDialog);
final dynamic pickerState = tester.state(_timePickerDialog); // ignore: unnecessary_nullable_for_final_variable_declarations

This comment has been minimized.

@justinmc

justinmc Oct 9, 2020
Contributor

Why was the ignore needed here? For my own curiosity.

This comment has been minimized.

@shihaohong

shihaohong Oct 9, 2020
Contributor

I'm curious too, tried looking in the codebase for some explanation but couldn't find one. It seems like it has something to do with using dynamic as a type?

This comment has been minimized.

@goderbauer

goderbauer Oct 9, 2020
Author Member

NNBD comes with this new lint: https://dart-lang.github.io/linter/lints/unnecessary_nullable_for_final_variable_declarations.html

Basically, if you have a final variable and assign a non-null value to it, the type of that variable should also be non-null. This makes totally sense in normal code. In this case however, we do not have access to the actual type _TimePickerDialogState, which is a private not visible in the test. To still get access to it, the test declares it as dynamic, so we can call any method we want on it and test the internals of the private class. It's a hack, you should never to this in application code.

Unfortunately, dynamic is a nullable type, triggering the warning.

This comment has been minimized.

@goderbauer

goderbauer Oct 9, 2020
Author Member

I've actually filed dart-lang/linter#2282 with the linter team to see if this lint is appropriate for dynamic variables. It does seem a little odd.

@@ -170,50 +168,6 @@ void main() {
},
);

testWidgets('children property cannot be null', (WidgetTester tester) async {

This comment has been minimized.

@justinmc

justinmc Oct 9, 2020
Contributor

Awesome that we can remove whole tests.

Copy link
Contributor

@shihaohong shihaohong left a comment

LGTM

@@ -170,50 +168,6 @@ void main() {
},
);

testWidgets('children property cannot be null', (WidgetTester tester) async {

This comment has been minimized.

@shihaohong

shihaohong Oct 9, 2020
Contributor

Pretty cool side effect of NNBD

@fluttergithubbot fluttergithubbot merged commit 793678d into flutter:master Oct 9, 2020
35 checks passed
35 checks passed
Google testing Google testing passed!
Details
Linux analyze
Details
Linux build_tests
Details
Linux customer_testing
Details
Linux docs
Details
Linux firebase_abstract_method_smoke_test
Details
Linux firebase_android_embedding_v2_smoke_test
Details
Linux firebase_release_smoke_test
Details
Linux framework_tests
Details
Linux fuchsia_precache
Details
Linux gradle_r8_test
Details
Linux web_integration_tests
Details
Linux web_smoke_test
Details
Linux web_tests
Details
Mac build_tests
Details
Mac customer_testing
Details
Mac framework_tests
Details
WIP Ready for review
Details
Windows build_tests
Details
Windows customer_testing
Details
Windows framework_tests
Details
Windows tool_tests
Details
analyze-linux Task Summary
Details
cla/google All necessary CLAs are signed
customer_testing-linux Task Summary
Details
deploy_gallery-linux Task Summary
Details
deploy_gallery-macos Task Summary
Details
docs-linux Task Summary
Details
flutter-build
Details
flutter-gold All golden file tests have passed.
Details
framework_tests-libraries-linux Task Summary
Details
framework_tests-misc-linux Task Summary
Details
framework_tests-widgets-linux Task Summary
Details
web_integration_tests Task Summary
Details
web_smoke_test Task Summary
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.