Files
sdk/pkg/nnbd_migration/test/front_end/analysis_abstract.dart
T
Paul Berry 68c50f7f92 Migration: re-work test_informationalRegion_containsTraceLinks_separateDrive.
Previously, we were switching test paths to drive `D` at the start of
the test, after the `package_config.json` file had already been
generated to drive `C`; as a result, it didn't apply.  We will need
the `package_config.json` to apply when we flip the null safety flag
(so that the inputs to the migration tool are considered opted out
prior to migration).  This CL reworks the test so that the paths are
modified as part of test set-up, so `package_config.json` gets put in
the right place.

Fixes #43883.

Bug: https://github.com/dart-lang/sdk/issues/43883
Change-Id: I08f79ddb07d7a5ecf640370a32334a7ceb92ceff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169421
Reviewed-by: Samuel Rawlins <srawlins@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
2020-10-28 16:35:30 +00:00

79 lines
2.2 KiB
Dart

// Copyright (c) 2014, 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:test/test.dart';
import '../abstract_context.dart';
/// An abstract base for all 'analysis' domain tests.
class AbstractAnalysisTest extends AbstractContextTest {
String projectPath;
String testFolder;
String testFile;
String testCode;
AbstractAnalysisTest();
void addAnalysisOptionsFile(String content) {
newFile(
resourceProvider.pathContext.join(projectPath, 'analysis_options.yaml'),
content: content);
}
String addTestFile(String content) {
newFile(testFile, content: content);
testCode = content;
return testFile;
}
/// Create an analysis options file based on the given arguments.
void createAnalysisOptionsFile({List<String> experiments}) {
var buffer = StringBuffer();
if (experiments != null) {
buffer.writeln('analyzer:');
buffer.writeln(' enable-experiment:');
for (var experiment in experiments) {
buffer.writeln(' - $experiment');
}
}
addAnalysisOptionsFile(buffer.toString());
}
/// Creates a project [projectPath].
void createProject({Map<String, String> packageRoots}) {
newFolder(projectPath);
}
/// Returns the offset of [search] in the file at the given [path].
/// Fails if not found.
int findFileOffset(String path, String search) {
var file = getFile(path);
var code = file.createSource().contents.data;
var offset = code.indexOf(search);
expect(offset, isNot(-1), reason: '"$search" in\n$code');
return offset;
}
/// Returns the offset of [search] in [testCode].
/// Fails if not found.
int findOffset(String search) {
var offset = testCode.indexOf(search);
expect(offset, isNot(-1));
return offset;
}
String modifyTestFile(String content) {
modifyFile(testFile, content);
testCode = content;
return testFile;
}
void setUp() {
super.setUp();
projectPath = convertPath(testsPath);
testFolder = convertPath('$testsPath/bin');
testFile = convertPath('$testsPath/bin/test.dart');
}
}