Convert more tests to use ResourceProviderMixin
Change-Id: Ia4cce51e33c79c82a989bfda9b8303dfaa72e103
Reviewed-on: https://dart-review.googlesource.com/31880
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analysis_server/test/analysis/get_errors_test.dart b/pkg/analysis_server/test/analysis/get_errors_test.dart
index 431f5ed..af094d1 100644
--- a/pkg/analysis_server/test/analysis/get_errors_test.dart
+++ b/pkg/analysis_server/test/analysis/get_errors_test.dart
@@ -46,12 +46,12 @@
test_errorInPart() async {
String libPath = '$testFolder/main.dart';
String partPath = '$testFolder/main_part.dart';
- addFile(libPath, r'''
+ newFile(libPath, content: r'''
library main;
part 'main_part.dart';
class A {}
''');
- addFile(partPath, r'''
+ newFile(partPath, content: r'''
part of main;
class A {}
''');
@@ -77,7 +77,7 @@
test_fileWithoutContext() {
// Broken under the new driver.
String file = '/outside.dart';
- addFile(file, '''
+ newFile(file, content: '''
main() {
print(42);
}
@@ -124,7 +124,7 @@
Request request = _createGetErrorsRequest(testFile);
server.handleRequest(request);
// remove context, causes sending an "invalid file" error
- resourceProvider.deleteFolder(projectPath);
+ deleteFolder(projectPath);
// wait for an error response
Response response = await serverChannel.waitForResponse(request);
expect(response.error, isNotNull);
diff --git a/pkg/analysis_server/test/analysis/get_navigation_test.dart b/pkg/analysis_server/test/analysis/get_navigation_test.dart
index 6df1179..85945fc 100644
--- a/pkg/analysis_server/test/analysis/get_navigation_test.dart
+++ b/pkg/analysis_server/test/analysis/get_navigation_test.dart
@@ -55,7 +55,7 @@
}
test_fileOutsideOfRoot() async {
- testFile = '/outside.dart';
+ testFile = resourceProvider.convertPath('/outside.dart');
addTestFile('''
main() {
var test = 0;
@@ -198,7 +198,7 @@
server.handleRequest(request);
// remove context, causes sending an "invalid file" error
{
- Folder projectFolder = resourceProvider.getResource(projectPath);
+ Folder projectFolder = getFolder(projectPath);
server.contextManager.callbacks.removeContext(projectFolder, <String>[]);
}
// wait for an error response
diff --git a/pkg/analysis_server/test/analysis/notification_analysis_options_test.dart b/pkg/analysis_server/test/analysis/notification_analysis_options_test.dart
index 4293c6c..4fc4eb1 100644
--- a/pkg/analysis_server/test/analysis/notification_analysis_options_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_analysis_options_test.dart
@@ -43,11 +43,7 @@
List<AnalysisError> get testFileErrors => filesErrors[testFile];
void addOptionsFile(String contents) {
- addFile(optionsFilePath, contents);
- }
-
- void deleteFile(String filePath) {
- resourceProvider.deleteFile(filePath);
+ newFile(optionsFilePath, content: contents);
}
@override
diff --git a/pkg/analysis_server/test/analysis/notification_analyzedFiles_test.dart b/pkg/analysis_server/test/analysis/notification_analyzedFiles_test.dart
index c7a1196..8cfbfad 100644
--- a/pkg/analysis_server/test/analysis/notification_analyzedFiles_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_analyzedFiles_test.dart
@@ -73,9 +73,7 @@
}
test_beforeAnalysis_excludeYamlFiles() async {
- File yamlFile = resourceProvider
- .getFolder(projectPath)
- .getChildAssumingFile('sample.yaml');
+ File yamlFile = getFolder(projectPath).getChildAssumingFile('sample.yaml');
yamlFile.writeAsStringSync('');
addTestFile('''
class A {}
@@ -117,7 +115,7 @@
// Making a change that *does* affect the set of reachable files should
// trigger the notification to be re-sent.
addTestFile('class A {}');
- addFile('/foo.dart', 'library foo;');
+ newFile('/foo.dart', content: 'library foo;');
await prepareAnalyzedFiles();
expect(analyzedFilesReceived, isTrue);
diff --git a/pkg/analysis_server/test/analysis/notification_errors_test.dart b/pkg/analysis_server/test/analysis/notification_errors_test.dart
index d82d58f..161eb85 100644
--- a/pkg/analysis_server/test/analysis/notification_errors_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_errors_test.dart
@@ -47,11 +47,11 @@
test_analysisOptionsFile() async {
String analysisOptionsFile =
- addFile('$projectPath/analysis_options.yaml', '''
+ newFile('$projectPath/analysis_options.yaml', content: '''
linter:
rules:
- invalid_lint_rule_name
-''');
+''').path;
Request request =
new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0');
@@ -90,7 +90,7 @@
test_lintError() async {
var camelCaseTypesLintName = 'camel_case_types';
- addFile('$projectPath/.analysis_options', '''
+ newFile('$projectPath/.analysis_options', content: '''
linter:
rules:
- $camelCaseTypesLintName
@@ -105,7 +105,7 @@
await waitForTasksFinished();
List<Linter> lints;
AnalysisDriver testDriver = (server.contextManager as ContextManagerImpl)
- .getContextInfoFor(resourceProvider.getFolder(projectPath))
+ .getContextInfoFor(getFolder(projectPath))
.analysisDriver;
lints = testDriver.analysisOptions.lintRules;
// Registry should only contain single lint rule.
@@ -124,8 +124,7 @@
test_notInAnalysisRoot() async {
createProject();
- String otherFile = '/other.dart';
- addFile(otherFile, 'UnknownType V;');
+ String otherFile = newFile('/other.dart', content: 'UnknownType V;').path;
addTestFile('''
import '/other.dart';
main() {
@@ -153,9 +152,9 @@
}
test_pubspecFile() async {
- String pubspecFile = addFile('$projectPath/pubspec.yaml', '''
+ String pubspecFile = newFile('$projectPath/pubspec.yaml', content: '''
version: 1.3.2
-''');
+''').path;
Request setRootsRequest =
new AnalysisSetAnalysisRootsParams([projectPath], []).toRequest('0');
@@ -174,7 +173,7 @@
//
// Fix the error and verify the new results.
//
- resourceProvider.updateFile(pubspecFile, '''
+ modifyFile(pubspecFile, '''
name: sample
version: 1.3.2
''');
diff --git a/pkg/analysis_server/test/analysis/notification_highlights_test.dart b/pkg/analysis_server/test/analysis/notification_highlights_test.dart
index ceabbce..16df572 100644
--- a/pkg/analysis_server/test/analysis/notification_highlights_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_highlights_test.dart
@@ -344,7 +344,7 @@
main() {
var part = 42;
}''');
- addFile('/project/bin/my_part.dart', 'part of lib;');
+ newFile('/project/bin/my_part.dart', content: 'part of lib;');
await prepareHighlights();
assertHasRegion(HighlightRegionType.BUILT_IN, 'part "my_');
assertNoRegion(HighlightRegionType.BUILT_IN, 'part = 42');
@@ -934,7 +934,7 @@
}
void _addLibraryForTestPart() {
- addFile('$testFolder/my_lib.dart', '''
+ newFile('$testFolder/my_lib.dart', content: '''
library lib;
part 'test.dart';
''');
diff --git a/pkg/analysis_server/test/analysis/notification_highlights_test2.dart b/pkg/analysis_server/test/analysis/notification_highlights_test2.dart
index df9b59d..56491fe 100644
--- a/pkg/analysis_server/test/analysis/notification_highlights_test2.dart
+++ b/pkg/analysis_server/test/analysis/notification_highlights_test2.dart
@@ -345,7 +345,7 @@
main() {
var part = 42;
}''');
- addFile('/project/bin/my_part.dart', 'part of lib;');
+ newFile('/project/bin/my_part.dart', content: 'part of lib;');
await prepareHighlights();
assertHasRegion(HighlightRegionType.BUILT_IN, 'part "my_');
assertNoRegion(HighlightRegionType.BUILT_IN, 'part = 42');
@@ -1085,7 +1085,7 @@
}
void _addLibraryForTestPart() {
- addFile('$testFolder/my_lib.dart', '''
+ newFile('$testFolder/my_lib.dart', content: '''
library lib;
part 'test.dart';
''');
diff --git a/pkg/analysis_server/test/analysis/notification_implemented_test.dart b/pkg/analysis_server/test/analysis/notification_implemented_test.dart
index cc80eb9..7a6e597 100644
--- a/pkg/analysis_server/test/analysis/notification_implemented_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_implemented_test.dart
@@ -271,7 +271,7 @@
}
test_method_withMethod_private_differentLib() async {
- addFile('$testFolder/lib.dart', r'''
+ newFile('$testFolder/lib.dart', content: r'''
import 'test.dart';
class B extends A {
void _m() {}
diff --git a/pkg/analysis_server/test/analysis/notification_navigation_test.dart b/pkg/analysis_server/test/analysis/notification_navigation_test.dart
index f57c6715..075acf7 100644
--- a/pkg/analysis_server/test/analysis/notification_navigation_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_navigation_test.dart
@@ -229,7 +229,7 @@
}
test_annotationConstructor_importPrefix() async {
- addFile('$testFolder/my_annotation.dart', r'''
+ newFile('$testFolder/my_annotation.dart', content: r'''
library an;
class MyAnnotation {
const MyAnnotation();
@@ -304,7 +304,7 @@
}
test_annotationField_importPrefix() async {
- addFile('$testFolder/mayn.dart', r'''
+ newFile('$testFolder/mayn.dart', content: r'''
library an;
const myan = new Object();
''');
@@ -697,8 +697,8 @@
}
test_multiplyDefinedElement() async {
- addFile('$projectPath/bin/libA.dart', 'library A; int TEST = 1;');
- addFile('$projectPath/bin/libB.dart', 'library B; int TEST = 2;');
+ newFile('$projectPath/bin/libA.dart', content: 'library A; int TEST = 1;');
+ newFile('$projectPath/bin/libB.dart', content: 'library B; int TEST = 2;');
addTestFile('''
import 'libA.dart';
import 'libB.dart';
@@ -776,7 +776,7 @@
test_partOf() async {
var libCode = 'library lib; part "test.dart";';
- var libFile = addFile('$projectPath/bin/lib.dart', libCode);
+ var libFile = newFile('$projectPath/bin/lib.dart', content: libCode).path;
addTestFile('part of lib;');
await prepareNavigation();
assertHasRegionString('lib');
@@ -808,7 +808,7 @@
test_string_export() async {
var libCode = 'library lib;';
- var libFile = addFile('$projectPath/bin/lib.dart', libCode);
+ var libFile = newFile('$projectPath/bin/lib.dart', content: libCode).path;
addTestFile('export "lib.dart";');
await prepareNavigation();
assertHasRegionString('"lib.dart"');
@@ -823,7 +823,7 @@
test_string_import() async {
var libCode = 'library lib;';
- var libFile = addFile('$projectPath/bin/lib.dart', libCode);
+ var libFile = newFile('$projectPath/bin/lib.dart', content: libCode).path;
addTestFile('import "lib.dart";');
await prepareNavigation();
assertHasRegionString('"lib.dart"');
@@ -844,7 +844,8 @@
test_string_part() async {
var unitCode = 'part of lib; f() {}';
- var unitFile = addFile('$projectPath/bin/test_unit.dart', unitCode);
+ var unitFile =
+ newFile('$projectPath/bin/test_unit.dart', content: unitCode).path;
addTestFile('''
library lib;
part "test_unit.dart";
diff --git a/pkg/analysis_server/test/analysis/notification_overrides_test.dart b/pkg/analysis_server/test/analysis/notification_overrides_test.dart
index 10abe23..86cac68 100644
--- a/pkg/analysis_server/test/analysis/notification_overrides_test.dart
+++ b/pkg/analysis_server/test/analysis/notification_overrides_test.dart
@@ -232,7 +232,7 @@
}
test_BAD_privateByPrivate_inDifferentLib() async {
- addFile('$testFolder/lib.dart', r'''
+ newFile('$testFolder/lib.dart', content: r'''
class A {
void _m() {}
}
diff --git a/pkg/analysis_server/test/analysis/reanalyze_test.dart b/pkg/analysis_server/test/analysis/reanalyze_test.dart
index c78dd97..886b200 100644
--- a/pkg/analysis_server/test/analysis/reanalyze_test.dart
+++ b/pkg/analysis_server/test/analysis/reanalyze_test.dart
@@ -46,8 +46,8 @@
test_reanalyze_with_overlay() async {
createProject();
- resourceProvider.newFolder(testFolder);
- resourceProvider.newFile(testFile, 'main() {}');
+ newFolder(testFolder);
+ newFile(testFile, content: 'main() {}');
// Update the content with an overlay that contains a syntax error.
server.updateContent('1', {testFile: new AddContentOverlay('main() {')});
await _resultsAvailable.future;
diff --git a/pkg/analysis_server/test/analysis/set_priority_files_test.dart b/pkg/analysis_server/test/analysis/set_priority_files_test.dart
index 1de25bf..993fb07 100644
--- a/pkg/analysis_server/test/analysis/set_priority_files_test.dart
+++ b/pkg/analysis_server/test/analysis/set_priority_files_test.dart
@@ -57,49 +57,49 @@
test_fileNotInAnalysisRoot() async {
String path = '/other/file.dart';
- addFile(path, '');
+ newFile(path);
await _setPriorityFile(path);
_verifyPriorityFiles(path);
}
test_ignoredInAnalysisOptions() async {
String sampleFile = '$projectPath/samples/sample.dart';
- addFile('$projectPath/.analysis_options', r'''
+ newFile('$projectPath/.analysis_options', content: r'''
analyzer:
exclude:
- 'samples/**'
''');
- addFile(sampleFile, '');
+ newFile(sampleFile);
// attempt to set priority file
await _setPriorityFile(sampleFile);
_verifyPriorityFiles(sampleFile);
}
test_ignoredInAnalysisOptions_inChildContext() async {
- addFile('$projectPath/.packages', '');
- addFile('$projectPath/child/.packages', '');
+ newFile('$projectPath/.packages');
+ newFile('$projectPath/child/.packages');
String sampleFile = '$projectPath/child/samples/sample.dart';
- addFile('$projectPath/child/.analysis_options', r'''
+ newFile('$projectPath/child/.analysis_options', content: r'''
analyzer:
exclude:
- 'samples/**'
''');
- addFile(sampleFile, '');
+ newFile(sampleFile);
// attempt to set priority file
await _setPriorityFile(sampleFile);
_verifyPriorityFiles(sampleFile);
}
test_ignoredInAnalysisOptions_inRootContext() async {
- addFile('$projectPath/.packages', '');
- addFile('$projectPath/child/.packages', '');
+ newFile('$projectPath/.packages');
+ newFile('$projectPath/child/.packages');
String sampleFile = '$projectPath/child/samples/sample.dart';
- addFile('$projectPath/.analysis_options', r'''
+ newFile('$projectPath/.analysis_options', content: r'''
analyzer:
exclude:
- 'child/samples/**'
''');
- addFile(sampleFile, '');
+ newFile(sampleFile);
// attempt to set priority file
await _setPriorityFile(sampleFile);
_verifyPriorityFiles(sampleFile);
diff --git a/pkg/analysis_server/test/analysis/update_content_test.dart b/pkg/analysis_server/test/analysis/update_content_test.dart
index f2733f8..a4fc364 100644
--- a/pkg/analysis_server/test/analysis/update_content_test.dart
+++ b/pkg/analysis_server/test/analysis/update_content_test.dart
@@ -61,21 +61,18 @@
}
test_multiple_contexts() async {
- String fooPath = '/project1/foo.dart';
- resourceProvider.newFile(fooPath, '''
+ String fooPath = newFile('/project1/foo.dart', content: '''
library foo;
import '../project2/baz.dart';
-main() { f(); }''');
- String barPath = '/project2/bar.dart';
- resourceProvider.newFile(barPath, '''
+main() { f(); }''').path;
+ String barPath = newFile('/project2/bar.dart', content: '''
library bar;
import 'baz.dart';
-main() { f(); }''');
- String bazPath = '/project2/baz.dart';
- resourceProvider.newFile(bazPath, '''
+main() { f(); }''').path;
+ String bazPath = newFile('/project2/baz.dart', content: '''
library baz;
f(int i) {}
-''');
+''').path;
Request request =
new AnalysisSetAnalysisRootsParams(['/project1', '/project2'], [])
.toRequest('0');
@@ -106,7 +103,7 @@
@failingTest
test_overlay_addPreviouslyImported() async {
// The list of errors doesn't include errors for '/project/target.dart'.
- Folder project = resourceProvider.newFolder('/project');
+ Folder project = newFolder('/project');
handleSuccessfulRequest(
new AnalysisSetAnalysisRootsParams([project.path], []).toRequest('0'));
@@ -130,8 +127,8 @@
test_overlayOnly() async {
String filePath = '/User/project1/test.dart';
- Folder folder1 = resourceProvider.newFolder('/User/project1');
- Folder folder2 = resourceProvider.newFolder('/User/project2');
+ Folder folder1 = newFolder('/User/project1');
+ Folder folder2 = newFolder('/User/project2');
Request request =
new AnalysisSetAnalysisRootsParams([folder1.path, folder2.path], [])
.toRequest('0');
diff --git a/pkg/analysis_server/test/analysis_abstract.dart b/pkg/analysis_server/test/analysis_abstract.dart
index 2546cd8..1f797a9 100644
--- a/pkg/analysis_server/test/analysis_abstract.dart
+++ b/pkg/analysis_server/test/analysis_abstract.dart
@@ -14,11 +14,11 @@
import 'package:analysis_server/src/plugin/plugin_manager.dart';
import 'package:analyzer/context/context_root.dart' as analyzer;
import 'package:analyzer/file_system/file_system.dart';
-import 'package:analyzer/file_system/memory_file_system.dart';
import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/src/dart/analysis/driver.dart';
import 'package:analyzer/src/generated/engine.dart';
import 'package:analyzer/src/generated/sdk.dart';
+import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:analyzer_plugin/protocol/protocol.dart' as plugin;
import 'package:analyzer_plugin/protocol/protocol_generated.dart' as plugin;
import 'package:analyzer_plugin/src/protocol/protocol_internal.dart' as plugin;
@@ -47,10 +47,9 @@
/**
* An abstract base for all 'analysis' domain tests.
*/
-class AbstractAnalysisTest {
+class AbstractAnalysisTest extends Object with ResourceProviderMixin {
bool generateSummaryFiles = false;
MockServerChannel serverChannel;
- MemoryResourceProvider resourceProvider;
MockPackageMapProvider packageMapProvider;
TestPluginManager pluginManager;
AnalysisServer server;
@@ -89,12 +88,6 @@
handleSuccessfulRequest(request);
}
- String addFile(String path, String content) {
- path = resourceProvider.convertPath(path);
- resourceProvider.newFile(path, content);
- return path;
- }
-
void addGeneralAnalysisSubscription(GeneralAnalysisService service) {
generalServices.add(service);
Request request = new AnalysisSetGeneralSubscriptionsParams(generalServices)
@@ -103,7 +96,7 @@
}
String addTestFile(String content) {
- addFile(testFile, content);
+ newFile(testFile, content: content);
this.testCode = content;
return testFile;
}
@@ -137,7 +130,7 @@
* Creates a project `/project`.
*/
void createProject({Map<String, String> packageRoots}) {
- resourceProvider.newFolder(projectPath);
+ newFolder(projectPath);
Request request = new AnalysisSetAnalysisRootsParams([projectPath], [],
packageRoots: packageRoots)
.toRequest('0');
@@ -149,7 +142,7 @@
* Fails if not found.
*/
int findFileOffset(String path, String search) {
- File file = resourceProvider.getResource(path) as File;
+ File file = getFile(path);
String code = file.createSource().contents.data;
int offset = code.indexOf(search);
expect(offset, isNot(-1), reason: '"$search" in\n$code');
@@ -177,8 +170,7 @@
}
String modifyTestFile(String content) {
- String path = resourceProvider.convertPath(testFile);
- resourceProvider.updateFile(path, content);
+ modifyFile(testFile, content);
this.testCode = content;
return testFile;
}
@@ -204,7 +196,6 @@
void setUp() {
serverChannel = new MockServerChannel();
- resourceProvider = new MemoryResourceProvider();
projectPath = resourceProvider.convertPath('/project');
testFolder = resourceProvider.convertPath('/project/bin');
testFile = resourceProvider.convertPath('/project/bin/test.dart');
@@ -225,7 +216,6 @@
server.done();
handler = null;
server = null;
- resourceProvider = null;
serverChannel = null;
}
diff --git a/pkg/analysis_server/test/completion_test_support.dart b/pkg/analysis_server/test/completion_test_support.dart
index af60220..75833ab 100644
--- a/pkg/analysis_server/test/completion_test_support.dart
+++ b/pkg/analysis_server/test/completion_test_support.dart
@@ -74,12 +74,12 @@
super.setUp();
return new Future(() {
String content = spec.source;
- addFile(testFile, content);
+ newFile(testFile, content: content);
this.testCode = content;
completionOffset = spec.testLocation;
if (extraFiles != null) {
extraFiles.forEach((String fileName, String content) {
- addFile(fileName, content);
+ newFile(fileName, content: content);
});
}
}).then((_) => getSuggestions()).then((_) {
diff --git a/pkg/analysis_server/test/domain_analysis_test.dart b/pkg/analysis_server/test/domain_analysis_test.dart
index 3a6a94c..f79993c 100644
--- a/pkg/analysis_server/test/domain_analysis_test.dart
+++ b/pkg/analysis_server/test/domain_analysis_test.dart
@@ -49,18 +49,15 @@
}
test_setAnalysisRoots_excludedFolder() async {
- String fileA = '/project/aaa/a.dart';
- String fileB = '/project/bbb/b.dart';
- resourceProvider.newFile(fileA, '// a');
- resourceProvider.newFile(fileB, '// b');
+ newFile('/project/aaa/a.dart', content: '// a');
+ newFile('/project/bbb/b.dart', content: '// b');
var response = testSetAnalysisRoots(['/project'], ['/project/bbb']);
expect(response, isResponseSuccess('0'));
}
test_setAnalysisRoots_included_newFolder() async {
- String file = '/project/bin/test.dart';
- resourceProvider.newFile('/project/pubspec.yaml', 'name: project');
- resourceProvider.newFile(file, 'main() {}');
+ newFile('/project/pubspec.yaml', content: 'name: project');
+ String file = newFile('/project/bin/test.dart', content: 'main() {}').path;
var response = testSetAnalysisRoots(['/project'], []);
var serverRef = server;
expect(response, isResponseSuccess('0'));
@@ -71,8 +68,7 @@
}
test_setAnalysisRoots_included_nonexistentFolder() async {
- String fileB = '/project_b/b.dart';
- resourceProvider.newFile(fileB, '// b');
+ String fileB = newFile('/project_b/b.dart', content: '// b').path;
var response = testSetAnalysisRoots(['/project_a', '/project_b'], []);
var serverRef = server;
expect(response, isResponseSuccess('0'));
@@ -115,11 +111,9 @@
}
test_setPriorityFiles_valid() {
- resourceProvider.newFolder('/p1');
- resourceProvider.newFile('/p1/a.dart', 'library a;');
- resourceProvider.newFolder('/p2');
- resourceProvider.newFile('/p2/b.dart', 'library b;');
- resourceProvider.newFile('/p2/c.dart', 'library c;');
+ newFile('/p1/a.dart', content: 'library a;');
+ newFile('/p2/b.dart', content: 'library b;');
+ newFile('/p2/c.dart', content: 'library c;');
var setRootsRequest =
new AnalysisSetAnalysisRootsParams(['/p1', '/p2'], []).toRequest('0');
@@ -263,7 +257,7 @@
xtest_getReachableSources_invalidSource() async {
// TODO(brianwilkerson) Re-enable this test if we re-enable the
// analysis.getReachableSources request.
- resourceProvider.newFile('/project/a.dart', 'import "b.dart";');
+ newFile('/project/a.dart', content: 'import "b.dart";');
server.setAnalysisRoots('0', ['/project/'], [], {});
await server.onAnalysisComplete;
@@ -279,10 +273,8 @@
xtest_getReachableSources_validSources() async {
// TODO(brianwilkerson) Re-enable this test if we re-enable the
// analysis.getReachableSources request.
- String fileA = '/project/a.dart';
- String fileB = '/project/b.dart';
- resourceProvider.newFile(fileA, 'import "b.dart";');
- resourceProvider.newFile(fileB, '');
+ String fileA = newFile('/project/a.dart', content: 'import "b.dart";').path;
+ newFile('/project/b.dart');
server.setAnalysisRoots('0', ['/project/'], [], {});
@@ -314,13 +306,11 @@
test_setRoots_packages() {
// prepare package
- String pkgFile = '/packages/pkgA/libA.dart';
- resourceProvider.newFile(pkgFile, '''
+ String pkgFile = newFile('/packages/pkgA/libA.dart', content: '''
library lib_a;
class A {}
-''');
- resourceProvider.newFile(
- '/project/.packages', 'pkgA:file:///packages/pkgA');
+''').path;
+ newFile('/project/.packages', content: 'pkgA:file:///packages/pkgA');
addTestFile('''
import 'package:pkgA/libA.dart';
main(A a) {
@@ -589,13 +579,11 @@
}
test_afterAnalysis_packageFile_external() async {
- String pkgFile = '/packages/pkgA/lib/libA.dart';
- resourceProvider.newFile(pkgFile, '''
+ String pkgFile = newFile('/packages/pkgA/lib/libA.dart', content: '''
library lib_a;
class A {}
-''');
- resourceProvider.newFile(
- '/project/.packages', 'pkgA:file:///packages/pkgA/lib');
+''').path;
+ newFile('/project/.packages', content: 'pkgA:file:///packages/pkgA/lib');
//
addTestFile('''
import 'package:pkgA/libA.dart';
@@ -617,30 +605,23 @@
test_afterAnalysis_packageFile_inRoot() async {
String pkgA = '/pkgA';
String pkgB = '/pkgA';
- String pkgFileA = '$pkgA/lib/libA.dart';
- String pkgFileB = '$pkgA/lib/libB.dart';
- resourceProvider.newFile(pkgFileA, '''
+ String pkgFileA = newFile('$pkgA/lib/libA.dart', content: '''
library lib_a;
class A {}
-''');
- resourceProvider.newFile(pkgFileB, '''
+''').path;
+ newFile('$pkgA/lib/libB.dart', content: '''
import 'package:pkgA/libA.dart';
main() {
new A();
}
''');
packageMapProvider.packageMap = {
- 'pkgA': [
- resourceProvider.newFolder('$pkgA/lib'),
- resourceProvider.newFolder('$pkgB/lib')
- ]
+ 'pkgA': [newFolder('$pkgA/lib'), newFolder('$pkgB/lib')]
};
// add 'pkgA' and 'pkgB' as projects
- {
- resourceProvider.newFolder(projectPath);
- handleSuccessfulRequest(
- new AnalysisSetAnalysisRootsParams([pkgA, pkgB], []).toRequest('0'));
- }
+ newFolder(projectPath);
+ handleSuccessfulRequest(
+ new AnalysisSetAnalysisRootsParams([pkgA, pkgB], []).toRequest('0'));
// wait for analysis, no results initially
await waitForTasksFinished();
expect(filesHighlights[pkgFileA], isNull);
@@ -652,12 +633,11 @@
}
test_afterAnalysis_packageFile_notUsed() async {
- String pkgFile = '/packages/pkgA/lib/libA.dart';
- resourceProvider.newFile(pkgFile, '''
+ String pkgFile = newFile('/packages/pkgA/lib/libA.dart', content: '''
library lib_a;
class A {}
-''');
- resourceProvider.newFile('/project/.packages', 'pkgA:/packages/pkgA/lib');
+''').path;
+ newFile('/project/.packages', content: 'pkgA:/packages/pkgA/lib');
//
addTestFile('// no "pkgA" reference');
createProject();
diff --git a/pkg/analysis_server/test/domain_completion_test.dart b/pkg/analysis_server/test/domain_completion_test.dart
index 5aad7e4..90b92b4 100644
--- a/pkg/analysis_server/test/domain_completion_test.dart
+++ b/pkg/analysis_server/test/domain_completion_test.dart
@@ -239,7 +239,7 @@
//
// We no longer support the analysis of non-dart files.
//
- testFile = '/project/web/test.html';
+ testFile = resourceProvider.convertPath('/project/web/test.html');
addTestFile('''
<html>^</html>
''');
@@ -251,7 +251,7 @@
}
test_import_uri_with_trailing() {
- addFile('/project/bin/testA.dart', 'library libA;');
+ newFile('/project/bin/testA.dart', content: 'library libA;');
addTestFile('''
import '/project/bin/t^.dart';
main() {}''');
@@ -499,7 +499,7 @@
}
test_inDartDoc_reference1() async {
- addFile('/testA.dart', '''
+ newFile('/testA.dart', content: '''
part of libA;
foo(bar) => 0;''');
addTestFile('''
@@ -528,7 +528,7 @@
}
test_inherited() {
- addFile('/libA.dart', 'class A {m() {}}');
+ newFile('/libA.dart', content: 'class A {m() {}}');
addTestFile('''
import '/libA.dart';
class B extends A {
@@ -606,7 +606,7 @@
}
test_local_override() {
- addFile('/libA.dart', 'class A {m() {}}');
+ newFile('/libA.dart', content: 'class A {m() {}}');
addTestFile('''
import '/libA.dart';
class B extends A {
@@ -649,7 +649,7 @@
}
test_overrides() {
- addFile('/libA.dart', 'class A {m() {}}');
+ newFile('/libA.dart', content: 'class A {m() {}}');
addTestFile('''
import '/libA.dart';
class B extends A {m() {^}}
@@ -663,7 +663,7 @@
}
test_partFile() {
- addFile('/project/bin/testA.dart', '''
+ newFile('/project/bin/testA.dart', content: '''
library libA;
part "$testFile";
import 'dart:html';
@@ -683,7 +683,7 @@
}
test_partFile2() {
- addFile('/testA.dart', '''
+ newFile('/testA.dart', content: '''
part of libA;
class A { }''');
addTestFile('''
diff --git a/pkg/analysis_server/test/domain_diagnostic_test.dart b/pkg/analysis_server/test/domain_diagnostic_test.dart
index 913294f..c3ff619 100644
--- a/pkg/analysis_server/test/domain_diagnostic_test.dart
+++ b/pkg/analysis_server/test/domain_diagnostic_test.dart
@@ -26,9 +26,8 @@
}
test_getDiagnostics() async {
- String file = '/project/bin/test.dart';
- resourceProvider.newFile('/project/pubspec.yaml', 'name: project');
- resourceProvider.newFile(file, 'main() {}');
+ newFile('/project/pubspec.yaml', content: 'name: project');
+ newFile('/project/bin/test.dart', content: 'main() {}');
server.setAnalysisRoots('0', ['/project/'], [], {});
diff --git a/pkg/analysis_server/test/domain_execution_test.dart b/pkg/analysis_server/test/domain_execution_test.dart
index b46daaa..8ccdb16 100644
--- a/pkg/analysis_server/test/domain_execution_test.dart
+++ b/pkg/analysis_server/test/domain_execution_test.dart
@@ -178,8 +178,7 @@
}
void test_mapUri_file() {
- String path = '/a/b.dart';
- resourceProvider.newFile(path, '');
+ String path = newFile('/a/b.dart').path;
// map the file
ExecutionMapUriResult result = _mapUri(file: path);
expect(result.file, isNull);
@@ -189,7 +188,7 @@
void test_mapUri_file_dartUriKind() {
String path = server.findSdk().mapDartUri('dart:async').fullName;
// hack - pretend that the SDK file exists in the project FS
- resourceProvider.newFile(path, '// hack');
+ newFile(path, content: '// hack');
// map file
ExecutionMapUriResult result = _mapUri(file: path);
expect(result.file, isNull);
@@ -198,7 +197,7 @@
void test_mapUri_uri() {
String path = '/a/b.dart';
- resourceProvider.newFile(path, '');
+ newFile(path);
// map the uri
ExecutionMapUriResult result = _mapUri(uri: 'file://$path');
expect(result.file, '/a/b.dart');
diff --git a/pkg/analysis_server/test/edit/fixes_test.dart b/pkg/analysis_server/test/edit/fixes_test.dart
index 90732cd..684506f 100644
--- a/pkg/analysis_server/test/edit/fixes_test.dart
+++ b/pkg/analysis_server/test/edit/fixes_test.dart
@@ -111,20 +111,21 @@
test_suggestImportFromDifferentAnalysisRoot() async {
// Set up two projects.
- resourceProvider..newFolder("/project1")..newFolder("/project2");
+ newFolder("/project1");
+ newFolder("/project2");
handleSuccessfulRequest(
new AnalysisSetAnalysisRootsParams(["/project1", "/project2"], [])
.toRequest('0'),
handler: analysisHandler);
// Set up files.
- testFile = "/project1/main.dart";
- testCode = "main() { print(new Foo()); }";
+ testFile = resourceProvider.convertPath('/project1/main.dart');
+ testCode = 'main() { print(new Foo()); }';
_addOverlay(testFile, testCode);
// Add another file in the same project that imports the target file.
// This ensures it will be analyzed as an implicit Source.
- _addOverlay("/project1/another.dart", 'import "../project2/target.dart";');
- _addOverlay("/project2/target.dart", "class Foo() {}");
+ _addOverlay('/project1/another.dart', 'import "../project2/target.dart";');
+ _addOverlay('/project2/target.dart', 'class Foo() {}');
await waitForTasksFinished();
diff --git a/pkg/analysis_server/test/edit/organize_directives_test.dart b/pkg/analysis_server/test/edit/organize_directives_test.dart
index cf320de..351891f 100644
--- a/pkg/analysis_server/test/edit/organize_directives_test.dart
+++ b/pkg/analysis_server/test/edit/organize_directives_test.dart
@@ -84,8 +84,8 @@
}
Future test_OK_remove_unresolvedDirectives() {
- addFile('$testFolder/existing_part1.dart', 'part of lib;');
- addFile('$testFolder/existing_part2.dart', 'part of lib;');
+ newFile('$testFolder/existing_part1.dart', content: 'part of lib;');
+ newFile('$testFolder/existing_part2.dart', content: 'part of lib;');
addTestFile('''
library lib;
diff --git a/pkg/analysis_server/test/edit/refactoring_test.dart b/pkg/analysis_server/test/edit/refactoring_test.dart
index fd225c6..9fe5e02 100644
--- a/pkg/analysis_server/test/edit/refactoring_test.dart
+++ b/pkg/analysis_server/test/edit/refactoring_test.dart
@@ -271,8 +271,7 @@
test_analysis_onlyOneFile() async {
shouldWaitForFullAnalysis = false;
- String otherFile = '$testFolder/other.dart';
- addFile(otherFile, r'''
+ newFile('$testFolder/other.dart', content: r'''
foo(int myName) {}
''');
addTestFile('''
@@ -445,7 +444,7 @@
test_resetOnAnalysisSetChanged_watch_otherFile() async {
String otherFile = '$testFolder/other.dart';
- addFile(otherFile, '// other 1');
+ newFile(otherFile, content: '// other 1');
addTestFile('''
main() {
foo(1 + 2);
@@ -465,7 +464,7 @@
// The refactoring is reset, even though it's a different file. It is up to
// analyzer to track dependencies and provide resolved units fast when
// possible.
- addFile(otherFile, '// other 2');
+ newFile(otherFile, content: '// other 2');
await pumpEventQueue();
expect(test_resetCount, initialResetCount + 1);
}
@@ -980,7 +979,7 @@
test_analysis_onlyOneFile() async {
shouldWaitForFullAnalysis = false;
String otherFile = '$testFolder/other.dart';
- addFile(otherFile, r'''
+ newFile(otherFile, content: r'''
foo(int p) {}
''');
addTestFile('''
@@ -1048,8 +1047,7 @@
}
test_resetOnAnalysisSetChanged() async {
- String otherFile = '$testFolder/other.dart';
- addFile(otherFile, '// other 1');
+ newFile('$testFolder/other.dart', content: '// other 1');
addTestFile('''
main() {
int res = 1 + 2;
@@ -1217,7 +1215,7 @@
@failingTest
test_OK() {
fail('The move file refactoring is not supported under the new driver');
- resourceProvider.newFile('/project/bin/lib.dart', '');
+ newFile('/project/bin/lib.dart');
addTestFile('''
import 'dart:math';
import 'lib.dart';
@@ -1754,7 +1752,7 @@
}
test_library_partOfDirective() {
- addFile('$testFolder/my_lib.dart', '''
+ newFile('$testFolder/my_lib.dart', content: '''
library aaa.bbb.ccc;
part 'test.dart';
''');
diff --git a/pkg/analysis_server/test/edit/sort_members_test.dart b/pkg/analysis_server/test/edit/sort_members_test.dart
index abce2a0..d6b70c1 100644
--- a/pkg/analysis_server/test/edit/sort_members_test.dart
+++ b/pkg/analysis_server/test/edit/sort_members_test.dart
@@ -178,7 +178,7 @@
}
test_OK_genericFunctionType() async {
- addFile(projectPath + '/analysis_options.yaml', '''
+ newFile('$projectPath/analysis_options.yaml', content: '''
analyzer:
strong-mode: true
''');
diff --git a/pkg/analysis_server/test/search/type_hierarchy_test.dart b/pkg/analysis_server/test/search/type_hierarchy_test.dart
index c2d1547..19e5b52 100644
--- a/pkg/analysis_server/test/search/type_hierarchy_test.dart
+++ b/pkg/analysis_server/test/search/type_hierarchy_test.dart
@@ -164,17 +164,16 @@
test_class_extends_fileAndPackageUris() async {
// prepare packages
- String pkgFile = '/packages/pkgA/lib/libA.dart';
- resourceProvider.newFile(pkgFile, '''
+ newFile('/packages/pkgA/lib/libA.dart', content: '''
library lib_a;
class A {}
class B extends A {}
''');
- resourceProvider.newFile(
- '/packages/pkgA/.packages', 'pkgA:file:///packages/pkgA/lib');
+ newFile('/packages/pkgA/.packages',
+ content: 'pkgA:file:///packages/pkgA/lib');
// reference the package from a project
- resourceProvider.newFile(
- '$projectPath/.packages', 'pkgA:file:///packages/pkgA/lib');
+ newFile('$projectPath/.packages',
+ content: 'pkgA:file:///packages/pkgA/lib');
addTestFile('''
import 'package:pkgA/libA.dart';
class C extends A {}
@@ -696,7 +695,7 @@
}
test_member_method_private_differentLib() async {
- addFile('$testFolder/lib.dart', r'''
+ newFile('$testFolder/lib.dart', content: r'''
import 'test.dart';
class A {
void _m() {}
diff --git a/pkg/analysis_server/test/services/completion/dart/common_usage_sorter_test.dart b/pkg/analysis_server/test/services/completion/dart/common_usage_sorter_test.dart
index b578713..7f455ec 100644
--- a/pkg/analysis_server/test/services/completion/dart/common_usage_sorter_test.dart
+++ b/pkg/analysis_server/test/services/completion/dart/common_usage_sorter_test.dart
@@ -84,8 +84,8 @@
test_PrefixedIdentifier_field_inPart() async {
// SimpleIdentifier PrefixedIdentifier ExpressionStatement
- addFile('/project/bin/myLib.dart',
- 'library L; part "$testFile"; class A {static int s2;}');
+ newFile('/project/bin/myLib.dart',
+ content: 'library L; part "$testFile"; class A {static int s2;}');
addTestFile('part of L; foo() {A.^}');
await getSuggestionsWith({
'L.A': ['s2']
diff --git a/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart b/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart
index 3d15312..a85b628 100644
--- a/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart
+++ b/pkg/analyzer/lib/src/test_utilities/resource_provider_mixin.dart
@@ -18,6 +18,11 @@
resourceProvider.deleteFile(convertedPath);
}
+ void deleteFolder(String path) {
+ String convertedPath = resourceProvider.convertPath(path);
+ resourceProvider.deleteFolder(convertedPath);
+ }
+
File getFile(String path) {
String convertedPath = resourceProvider.convertPath(path);
return resourceProvider.getFile(convertedPath);