Fix LSP refactor test on Windows

Removes the recently-added base class to tests (which brought more with it than we needed - and caused issues on Windows) and adds in the flutter/meta packages using helpers (inc extracting the meta package to a new helper).

Re-enable skipped LSP refactor test

Change-Id: I62f8b3e300a776cae4fbd6d15deafb5b8970eef0

Change-Id: I165b9acf75a3ec9a91feb1730be2949eb4d5e5cb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/106741
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Danny Tuppeny <dantup@google.com>
This commit is contained in:
Danny Tuppeny 2019-06-19 20:00:15 +00:00 committed by commit-bot@chromium.org
parent 87460ad41a
commit 88408d562b
4 changed files with 149 additions and 110 deletions

View file

@ -21,6 +21,7 @@ import 'package:analyzer/src/test_utilities/mock_sdk.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'src/utilities/flutter_util.dart';
import 'src/utilities/meta_util.dart';
/**
* Finds an [Element] with the given [name].
@ -68,111 +69,8 @@ class AbstractContextTest with ResourceProviderMixin {
}
void addMetaPackage() {
addPackageFile('meta', 'meta.dart', r'''
library meta;
const _AlwaysThrows alwaysThrows = const _AlwaysThrows();
@deprecated
const _Checked checked = const _Checked();
const _Experimental experimental = const _Experimental();
const _Factory factory = const _Factory();
const Immutable immutable = const Immutable();
const _IsTest isTest = const _IsTest();
const _IsTestGroup isTestGroup = const _IsTestGroup();
const _Literal literal = const _Literal();
const _MustCallSuper mustCallSuper = const _MustCallSuper();
const _OptionalTypeArgs optionalTypeArgs = const _OptionalTypeArgs();
const _Protected protected = const _Protected();
const Required required = const Required();
const _Sealed sealed = const _Sealed();
@deprecated
const _Virtual virtual = const _Virtual();
const _VisibleForOverriding visibleForOverriding =
const _VisibleForOverriding();
const _VisibleForTesting visibleForTesting = const _VisibleForTesting();
class Immutable {
final String reason;
const Immutable([this.reason]);
}
class Required {
final String reason;
const Required([this.reason]);
}
class _AlwaysThrows {
const _AlwaysThrows();
}
class _Checked {
const _Checked();
}
class _Experimental {
const _Experimental();
}
class _Factory {
const _Factory();
}
class _IsTest {
const _IsTest();
}
class _IsTestGroup {
const _IsTestGroup();
}
class _Literal {
const _Literal();
}
class _MustCallSuper {
const _MustCallSuper();
}
class _OptionalTypeArgs {
const _OptionalTypeArgs();
}
class _Protected {
const _Protected();
}
class _Sealed {
const _Sealed();
}
@deprecated
class _Virtual {
const _Virtual();
}
class _VisibleForOverriding {
const _VisibleForOverriding();
}
class _VisibleForTesting {
const _VisibleForTesting();
}
''');
Folder libFolder = configureMetaPackage(resourceProvider);
addTestPackageDependency('meta', libFolder.parent.path);
}
/// Add a new file with the given [pathInLib] to the package with the

View file

@ -6,13 +6,14 @@ import 'package:analysis_server/src/lsp/constants.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
import '../src/utilities/flutter_util.dart' as flutter;
import '../src/utilities/meta_util.dart' as meta;
import 'code_actions_abstract.dart';
main() {
defineReflectiveSuite(() {
defineReflectiveTests(ExtractMethodRefactorCodeActionsTest);
// TODO(dantup): Restore this once the tests are fixed for Windows.
//defineReflectiveTests(ExtractWidgetRefactorCodeActionsTest);
defineReflectiveTests(ExtractWidgetRefactorCodeActionsTest);
});
}
@ -68,8 +69,21 @@ main() {}
@reflectiveTest
class ExtractWidgetRefactorCodeActionsTest extends AbstractCodeActionsTest {
final extractWidgetTitle = 'Extract Widget';
@override
void setUp() {
super.setUp();
final flutterLibFolder = flutter.configureFlutterPackage(resourceProvider);
final metaLibFolder = meta.configureMetaPackage(resourceProvider);
// Create .packages in the project.
newFile(join(projectFolderPath, '.packages'), content: '''
flutter:${flutterLibFolder.toUri()}
meta:${metaLibFolder.toUri()}
''');
}
test_appliesCorrectEdits() async {
addFlutterPackage();
const content = '''
import 'package:flutter/material.dart';

View file

@ -21,7 +21,6 @@ import 'package:meta/meta.dart';
import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import '../abstract_context.dart';
import '../mocks.dart';
const dartLanguageId = 'dart';
@ -844,7 +843,7 @@ mixin LspAnalysisServerTestMixin implements ClientCapabilitiesHelperMixin {
contents.replaceAll(rangeMarkerStart, '').replaceAll(rangeMarkerEnd, '');
}
abstract class AbstractLspAnalysisServerTest extends AbstractContextTest
abstract class AbstractLspAnalysisServerTest
with
ResourceProviderMixin,
ClientCapabilitiesHelperMixin,

View file

@ -0,0 +1,128 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// 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/file_system/file_system.dart';
import 'package:analyzer/file_system/memory_file_system.dart';
const String metaPkgLibPath = '/packages/meta/lib';
/**
* Add a meta library and types to the given [provider] and return
* the `lib` folder.
*/
Folder configureMetaPackage(MemoryResourceProvider provider) {
File newFile(String path, String content) =>
provider.newFile(provider.convertPath(path), content ?? '');
Folder newFolder(String path) =>
provider.newFolder(provider.convertPath(path));
newFile('$metaPkgLibPath/meta.dart', r'''
library meta;
const _AlwaysThrows alwaysThrows = const _AlwaysThrows();
@deprecated
const _Checked checked = const _Checked();
const _Experimental experimental = const _Experimental();
const _Factory factory = const _Factory();
const Immutable immutable = const Immutable();
const _IsTest isTest = const _IsTest();
const _IsTestGroup isTestGroup = const _IsTestGroup();
const _Literal literal = const _Literal();
const _MustCallSuper mustCallSuper = const _MustCallSuper();
const _OptionalTypeArgs optionalTypeArgs = const _OptionalTypeArgs();
const _Protected protected = const _Protected();
const Required required = const Required();
const _Sealed sealed = const _Sealed();
@deprecated
const _Virtual virtual = const _Virtual();
const _VisibleForOverriding visibleForOverriding =
const _VisibleForOverriding();
const _VisibleForTesting visibleForTesting = const _VisibleForTesting();
class Immutable {
final String reason;
const Immutable([this.reason]);
}
class Required {
final String reason;
const Required([this.reason]);
}
class _AlwaysThrows {
const _AlwaysThrows();
}
class _Checked {
const _Checked();
}
class _Experimental {
const _Experimental();
}
class _Factory {
const _Factory();
}
class _IsTest {
const _IsTest();
}
class _IsTestGroup {
const _IsTestGroup();
}
class _Literal {
const _Literal();
}
class _MustCallSuper {
const _MustCallSuper();
}
class _OptionalTypeArgs {
const _OptionalTypeArgs();
}
class _Protected {
const _Protected();
}
class _Sealed {
const _Sealed();
}
@deprecated
class _Virtual {
const _Virtual();
}
class _VisibleForOverriding {
const _VisibleForOverriding();
}
class _VisibleForTesting {
const _VisibleForTesting();
}
''');
return newFolder(metaPkgLibPath);
}