Fix another windows test in analyzer

Change-Id: I675efd198ce7e803e2f9e7bdb62385116da22032
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133438
Reviewed-by: Paul Berry <paulberry@google.com>
Commit-Queue: Samuel Rawlins <srawlins@google.com>
This commit is contained in:
Sam Rawlins 2020-01-31 23:55:22 +00:00 committed by commit-bot@chromium.org
parent c693a9a093
commit 89edf6443b
2 changed files with 47 additions and 28 deletions

View file

@ -12,13 +12,11 @@ import 'package:analysis_server/src/edit/preview/http_preview_server.dart';
import 'package:analyzer/dart/analysis/results.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/file_system/file_system.dart';
import 'package:analyzer/file_system/overlay_file_system.dart';
import 'package:analyzer/src/dart/analysis/experiments.dart';
import 'package:analyzer/src/generated/source.dart';
import 'package:analyzer/src/task/options.dart';
import 'package:analyzer_plugin/protocol/protocol_common.dart';
import 'package:nnbd_migration/nnbd_migration.dart';
import 'package:path/path.dart' as path;
import 'package:source_span/source_span.dart';
import 'package:yaml/yaml.dart';
@ -228,8 +226,8 @@ analyzer:
/// Get the "root" of all [included] paths. See [includedRoot] for its
/// definition.
static String _getIncludedRoot(
List<String> included, OverlayResourceProvider provider) {
path.Context context = provider.pathContext;
List<String> included, ResourceProvider provider) {
var context = provider.pathContext;
// This step looks like it may be expensive (`getResource`, splitting up
// all of the paths, comparing parts, joining one path back together). In
// practice, this should be cheap because typically only one path is given

View file

@ -30,6 +30,13 @@ class NonNullableFixTest extends AbstractAnalysisTest {
String get nextRequestId => (++requestId).toString();
/// On Windows, canonicalization results in changing a drive letter to be
/// lowercase. When a path is canonicalized in [NonNullableFix], and asserted
/// on in a test below, the expected path below also needs to be
/// canonicalized.
String canonicalizeAndConvertPath(String p) =>
convertPath(context.canonicalize(p));
Future<EditDartfixResult> performFix({List<String> included}) async {
final id = nextRequestId;
final params = EditDartfixParams(included);
@ -73,59 +80,73 @@ class NonNullableFixTest extends AbstractAnalysisTest {
Future<void> test_included_multipleRelativeDirectories() async {
NonNullableFix fix = NonNullableFix(listener, included: ['lib', 'test']);
expect(fix.includedRoot, equals(convertPath('/project')));
expect(fix.includedRoot, equals(canonicalizeAndConvertPath('/project')));
}
Future<void> test_included_multipleRelativeDirectories_nonCanonical() async {
NonNullableFix fix = NonNullableFix(listener,
included: ['../project2/lib', '../project2/lib/src']);
expect(fix.includedRoot, equals(convertPath('/project2/lib')));
NonNullableFix fix = NonNullableFix(listener, included: [
convertPath('../project2/lib'),
convertPath('../project2/lib/src')
]);
expect(
fix.includedRoot, equals(canonicalizeAndConvertPath('/project2/lib')));
}
Future<void>
test_included_multipleRelativeDirectories_nonCanonical_atFilesystemRoot() async {
NonNullableFix fix = NonNullableFix(listener,
included: ['../project2/lib', '../project/lib']);
expect(fix.includedRoot, equals(convertPath('/')));
test_included_multipleRelativeDirectories_nonCanonical_atRoot() async {
NonNullableFix fix = NonNullableFix(listener, included: [
convertPath('../project2/lib'),
convertPath('../project/lib')
]);
expect(fix.includedRoot, equals(canonicalizeAndConvertPath('/')));
}
Future<void>
test_included_multipleRelativeDirectories_subAndSuperDirectories() async {
NonNullableFix fix = NonNullableFix(listener, included: ['lib', '.']);
expect(fix.includedRoot, equals(convertPath('/project')));
expect(fix.includedRoot, equals(canonicalizeAndConvertPath('/project')));
}
Future<void> test_included_multipleRelativeFiles() async {
NonNullableFix fix =
NonNullableFix(listener, included: ['lib/lib1.dart', 'test/test.dart']);
expect(fix.includedRoot, equals(convertPath('/project')));
NonNullableFix fix = NonNullableFix(listener, included: [
convertPath('lib/lib1.dart'),
convertPath('test/test.dart')
]);
expect(fix.includedRoot, equals(canonicalizeAndConvertPath('/project')));
}
Future<void> test_included_multipleRelativeFiles_sameDirectory() async {
NonNullableFix fix =
NonNullableFix(listener, included: ['lib/lib1.dart', 'lib/lib2.dart']);
expect(fix.includedRoot, equals(convertPath('/project/lib')));
NonNullableFix fix = NonNullableFix(listener,
included: [convertPath('lib/lib1.dart'), convertPath('lib/lib2.dart')]);
expect(
fix.includedRoot, equals(canonicalizeAndConvertPath('/project/lib')));
}
Future<void> test_included_multipleRelativeFilesAndDirectories() async {
NonNullableFix fix = NonNullableFix(listener,
included: ['lib/lib1.dart', 'lib/src', '../project/lib/src/lib3.dart']);
expect(fix.includedRoot, equals(convertPath('/project/lib')));
NonNullableFix fix = NonNullableFix(listener, included: [
convertPath('lib/lib1.dart'),
convertPath('lib/src'),
convertPath('../project/lib/src/lib3.dart')
]);
expect(
fix.includedRoot, equals(canonicalizeAndConvertPath('/project/lib')));
}
Future<void> test_included_singleAbsoluteDirectory() async {
NonNullableFix fix = NonNullableFix(listener, included: ['/project']);
expect(fix.includedRoot, equals(convertPath('/project')));
NonNullableFix fix =
NonNullableFix(listener, included: [convertPath('/project')]);
expect(fix.includedRoot, equals(canonicalizeAndConvertPath('/project')));
}
Future<void> test_included_singleAbsoluteFile() async {
NonNullableFix fix =
NonNullableFix(listener, included: ['/project/bin/bin.dart']);
expect(fix.includedRoot, equals(convertPath('/project/bin')));
NonNullableFix fix = NonNullableFix(listener,
included: [convertPath('/project/bin/bin.dart')]);
expect(
fix.includedRoot, equals(canonicalizeAndConvertPath('/project/bin')));
}
Future<void> test_included_singleRelativeDirectory() async {
NonNullableFix fix = NonNullableFix(listener, included: ['.']);
expect(fix.includedRoot, equals(convertPath('/project')));
expect(fix.includedRoot, equals(canonicalizeAndConvertPath('/project')));
}
}