[flutter_tools] add support for enable null safety asserts (#61114)
Enable null safety asserts for web debug mode. This induces runtime asserts at the boundaries between null safe and non-null safe libraries. Adds integration test that validates assertion error is thrown. #61042
This commit is contained in:
@@ -746,6 +746,7 @@ Future<void> _runWebIntegrationTests() async {
|
||||
await _runWebDebugTest('lib/stack_trace.dart');
|
||||
await _runWebDebugTest('lib/web_directory_loading.dart');
|
||||
await _runWebDebugTest('test/test.dart');
|
||||
await _runWebDebugTest('lib/null_assert_main.dart', enableNullSafety: true);
|
||||
await _runWebDebugTest('lib/null_safe_main.dart', enableNullSafety: true);
|
||||
await _runWebDebugTest('lib/web_define_loading.dart',
|
||||
additionalArguments: <String>[
|
||||
|
||||
22
dev/integration_tests/web/lib/null_assert_main.dart
Normal file
22
dev/integration_tests/web/lib/null_assert_main.dart
Normal file
@@ -0,0 +1,22 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart=2.8
|
||||
|
||||
import 'null_enabled_api.dart';
|
||||
|
||||
void main() {
|
||||
dynamic error;
|
||||
try {
|
||||
// Validate that a generated null assertion is thrown.
|
||||
methodThatAcceptsNonNull(null);
|
||||
} catch (err) {
|
||||
error = err;
|
||||
}
|
||||
if (error is AssertionError) {
|
||||
print('--- TEST SUCCEEDED ---');
|
||||
} else {
|
||||
print('--- TEST FAILED ---');
|
||||
}
|
||||
}
|
||||
9
dev/integration_tests/web/lib/null_enabled_api.dart
Normal file
9
dev/integration_tests/web/lib/null_enabled_api.dart
Normal file
@@ -0,0 +1,9 @@
|
||||
// Copyright 2014 The Flutter Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// @dart=2.9
|
||||
|
||||
void methodThatAcceptsNonNull(int x) {
|
||||
print(x + 2);
|
||||
}
|
||||
Reference in New Issue
Block a user