Skip to content

Commit

Permalink
Migrator: opt all test files _out_ of null safety.
Browse files Browse the repository at this point in the history
Well not quite all; migration_cli_test tests are a bit of a different
beast so I am going to tackle them separately. But this fixes over
1000 test failures, and should clean up test output for further
debugging of the flip CL.

Each test file needs to be in a package with a package config file
which spells out that it is _opted out_ of null safety.

Bug: #43883
Change-Id: I583f66119df57031fd80824111923e15e0f91782
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168900
Reviewed-by: Leaf Petersen <leafp@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
  • Loading branch information
srawlins authored and commit-bot@chromium.org committed Oct 23, 2020
1 parent d751681 commit 360363e
Show file tree
Hide file tree
Showing 11 changed files with 182 additions and 73 deletions.
82 changes: 82 additions & 0 deletions pkg/nnbd_migration/test/abstract_context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,88 @@ export 'package:test_core/test_core.dart';
newFile('$testsPath/.packages', content: '''
tests:file://$testsPath/lib
''');
var pubspecPath = '$testsPath/pubspec.yaml';
// Subclasses may write out a different file first.
if (!getFile(pubspecPath).exists) {
newFile(pubspecPath, content: '''
name: tests
version: 1.0.0
environment:
sdk: '>=2.9.0 <3.0.0'
''');
}
var packageConfigPath = '$testsPath/.dart_tool/package_config.json';
// Subclasses may write out a different file first.
if (!getFile(packageConfigPath).exists) {
// TODO(srawlins): This is a rough hack to allow for the "null safe by
// default" flag flip. We need to _opt out_ all packages at the onset.
// A better solution likely involves the package config-editing code in
// analyzer's [context_collection_resolution.dart].
newFile(packageConfigPath, content: '''
{
"configVersion": 2,
"packages": [
{
"name": "args",
"rootUri": "${toUriStr('/.pub-cache/args')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "collection",
"rootUri": "${toUriStr('/.pub-cache/collection')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "fixnum",
"rootUri": "${toUriStr('/.pub-cache/fixnum')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "foo",
"rootUri": "${toUriStr('/.pub-cache/foo')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "meta",
"rootUri": "${toUriStr('/.pub-cache/meta')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "quiver",
"rootUri": "${toUriStr('/.pub-cache/quiver')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "test",
"rootUri": "${toUriStr('/.pub-cache/test')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "test_core",
"rootUri": "${toUriStr('/.pub-cache/test_core')}",
"packageUri": "lib/",
"languageVersion": "2.9"
},
{
"name": "tests",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.9"
}
],
"generated": "2020-10-21T21:13:05.186004Z",
"generator": "pub",
"generatorVersion": "2.10.0"
}
''');
}

createAnalysisContexts();
}
Expand Down
30 changes: 30 additions & 0 deletions pkg/nnbd_migration/test/abstract_single_unit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,36 @@ class AbstractSingleUnitTest extends AbstractContextTest {
analyzer:
enable-experiment:
- non-nullable
''');
}
if (analyzeWithNnbd) {
newFile('$testRoot/pubspec.yaml', content: '''
name: tests
version: 1.0.0
environment:
sdk: '>=2.12.0 <3.0.0'
''');
newFile('$testRoot/.dart_tool/package_config.json', content: '''
{
"configVersion": 2,
"packages": [
{
"name": "meta",
"rootUri": "file:///.pub-cache/meta",
"packageUri": "lib/",
"languageVersion": "2.12"
},
{
"name": "tests",
"rootUri": "../",
"packageUri": "lib/",
"languageVersion": "2.12"
}
],
"generated": "2020-10-21T21:13:05.186004Z",
"generator": "pub",
"generatorVersion": "2.12.0"
}
''');
}
super.setUp();
Expand Down
26 changes: 17 additions & 9 deletions pkg/nnbd_migration/test/api_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ class _ProvisionalApiTest extends _ProvisionalApiTestBase
abstract class _ProvisionalApiTestBase extends AbstractContextTest {
bool get _usePermissiveMode;

String projectPath;

void setUp() {
projectPath = convertPath(AbstractContextTest.testsPath);
super.setUp();
}

/// Hook invoked between stages of processing inputs.
void _betweenStages() {}

Expand Down Expand Up @@ -102,7 +109,8 @@ abstract class _ProvisionalApiTestBase extends AbstractContextTest {
{Map<String, String> migratedInput = const {},
bool removeViaComments = false,
bool warnOnWeakCode = false}) async {
var sourcePath = convertPath('/home/test/lib/test.dart');
var sourcePath =
convertPath('${AbstractContextTest.testsPath}/lib/test.dart');
await _checkMultipleFileChanges(
{sourcePath: content}, {sourcePath: expected},
migratedInput: migratedInput,
Expand Down Expand Up @@ -398,7 +406,7 @@ void f() {
}
''';
await _checkSingleFileChanges(content, expected, migratedInput: {
'/home/test/lib/already_migrated.dart': alreadyMigrated
'$projectPath/lib/already_migrated.dart': alreadyMigrated
});
}

Expand Down Expand Up @@ -4312,7 +4320,7 @@ int g() => x;
}

Future<void> test_libraryWithParts() async {
var root = '/home/test/lib';
var root = '$projectPath/lib';
var path1 = convertPath('$root/lib.dart');
var file1 = '''
part 'src/foo/part.dart';
Expand All @@ -4338,7 +4346,7 @@ class C {
}

Future<void> test_libraryWithParts_add_questions() async {
var root = '/home/test/lib';
var root = '$projectPath/lib';
var path1 = convertPath('$root/lib.dart');
var file1 = '''
part 'src/foo/part.dart';
Expand Down Expand Up @@ -5581,7 +5589,7 @@ D<int?> test(C<int?> c) => -c;
}

Future<void> test_prefixes() async {
var root = '/home/test/lib';
var root = '$projectPath/lib';
var path1 = convertPath('$root/file1.dart');
var file1 = '''
import 'file2.dart';
Expand Down Expand Up @@ -6408,7 +6416,7 @@ g(String s) {}
}

Future<void> test_two_files() async {
var root = '/home/test/lib';
var root = '$projectPath/lib';
var path1 = convertPath('$root/file1.dart');
var file1 = '''
import 'file2.dart';
Expand Down Expand Up @@ -6509,7 +6517,7 @@ void main(F<int?> f) {
}
''';
await _checkSingleFileChanges(content, expected, migratedInput: {
'/home/test/lib/migrated_typedef.dart': 'typedef F<R> = Function(R);'
'$projectPath/lib/migrated_typedef.dart': 'typedef F<R> = Function(R);'
});
}

Expand Down Expand Up @@ -6545,7 +6553,7 @@ void f4(F<int> f) {
}
''';
await _checkSingleFileChanges(content, expected, migratedInput: {
'/home/test/lib/migrated_typedef.dart':
'$projectPath/lib/migrated_typedef.dart':
'typedef F<T> = Function<R>(T, R);'
});
}
Expand All @@ -6564,7 +6572,7 @@ void main(F f) {
}
''';
await _checkSingleFileChanges(content, expected, migratedInput: {
'/home/test/lib/migrated_typedef.dart': 'typedef F = Function<R>(R);'
'$projectPath/lib/migrated_typedef.dart': 'typedef F = Function<R>(R);'
});
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/nnbd_migration/test/edge_builder_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5018,13 +5018,13 @@ void g(C c, int j) {
}

Future<void> test_methodInvocation_parameter_named_differentPackage() async {
addPackageFile('pkgC', 'c.dart', '''
addPackageFile('foo', 'c.dart', '''
class C {
void f({int i}) {}
}
''');
await analyze('''
import "package:pkgC/c.dart";
import "package:foo/c.dart";
void g(C c, int j) {
c.f(i: j/*check*/);
}
Expand Down Expand Up @@ -7663,11 +7663,11 @@ double get myPi => pi;
}

Future<void> test_topLevelVar_reference_differentPackage() async {
addPackageFile('pkgPi', 'piConst.dart', '''
addPackageFile('foo', 'piConst.dart', '''
double pi = 3.1415;
''');
await analyze('''
import "package:pkgPi/piConst.dart";
import "package:foo/piConst.dart";
double get myPi => pi;
''');
var myPiType = decoratedTypeAnnotation('double get');
Expand Down
8 changes: 4 additions & 4 deletions pkg/nnbd_migration/test/edit_plan_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,11 @@ class C {
}

Future<void> test_addUnaryPostfix_outer_precedence() async {
await analyze('f(x) => x!;');
await analyze('f(x) => x/*!*/;');
checkPlan(
planner.addUnaryPostfix(
planner.passThrough(findNode.simple('x!')), TokenType.PLUS_PLUS),
'f(x) => x++!;');
planner.addUnaryPostfix(planner.passThrough(findNode.simple('x/*!*/')),
TokenType.PLUS_PLUS),
'f(x) => x++/*!*/;');
}

Future<void> test_addUnaryPrefix_inner_precedence_add_parens() async {
Expand Down
4 changes: 1 addition & 3 deletions pkg/nnbd_migration/test/front_end/analysis_abstract.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:test/test.dart';

import '../abstract_context.dart';

/// An abstract base for all 'analysis' domain tests.
class AbstractAnalysisTest extends AbstractContextTest
with ResourceProviderMixin {
class AbstractAnalysisTest extends AbstractContextTest {
String projectPath;
String testFolder;
String testFile;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,44 +19,36 @@ void main() {
@reflectiveTest
class InstrumentationRendererTest extends NnbdMigrationTestBase {
/// Render the instrumentation view for [files].
Future<String> renderViewForTestFiles(Map<String, String> files,
Future<String> renderViewForTestFiles(
{bool applied = false, bool needsRerun = false}) async {
var packageRoot = convertPath('/project');
await buildInfoForTestFiles(files, includedRoot: packageRoot);
var files = {convertPath('$projectPath/lib/a.dart'): 'int a = null;'};
await buildInfoForTestFiles(files, includedRoot: projectPath);
var migrationInfo =
MigrationInfo(infos, {}, resourceProvider.pathContext, packageRoot);
MigrationInfo(infos, {}, resourceProvider.pathContext, projectPath);
var instrumentationRenderer = InstrumentationRenderer(
migrationInfo, PathMapper(resourceProvider), applied, needsRerun);
return instrumentationRenderer.render();
}

Future<void> test_appliedStyle() async {
var renderedView = await renderViewForTestFiles(
{convertPath('/project/lib/a.dart'): 'int a = null;'},
applied: true);
var renderedView = await renderViewForTestFiles(applied: true);
// harmless space in class list due to other potential classes here.
expect(renderedView, contains('<body class="applied ">'));
}

Future<void> test_navigation_containsRoot() async {
var renderedView = await renderViewForTestFiles(
{convertPath('/project/lib/a.dart'): 'int a = null;'});
var expectedPath = convertPath('/project');
var renderedView = await renderViewForTestFiles();
// harmless space in class list due to other potential classes here.
expect(renderedView, contains('<p class="root">$expectedPath</p>'));
expect(renderedView, contains('<p class="root">$projectPath</p>'));
}

Future<void> test_needsRerunStyle() async {
var renderedView = await renderViewForTestFiles(
{convertPath('/project/lib/a.dart'): 'int a = null;'},
needsRerun: true);
var renderedView = await renderViewForTestFiles(needsRerun: true);
expect(renderedView, contains('<body class="proposed needs-rerun">'));
}

Future<void> test_notAppliedStyle() async {
var renderedView = await renderViewForTestFiles(
{convertPath('/project/lib/a.dart'): 'int a = null;'},
applied: false);
var renderedView = await renderViewForTestFiles(applied: false);
// harmless space in class list due to other potential classes here.
expect(renderedView, contains('<body class="proposed ">'));
}
Expand Down
Loading

0 comments on commit 360363e

Please sign in to comment.