Allow `linter` unit tests to be run from any directory.
I frequently run unit tests from the root directory of the SDK
package. Previous to this CL, that didn't work for the `linter`
package, because the test `validate_sdk_version_map.dart` contained a
hard-coded path that only worked if the test was invoked from the
`pkg/linter` subdirectory.
With this change, the test uses the `packageRoot` getter from the
`analyzer_utilities` package, which locates the SDK's `pkg` directory
using heuristics that work from a variety of different starting
directories, including the root of the SDK repo, anywhere within
`pkg/linter`, and in a Google3 bazel test.
Change-Id: I525ad21cb5228e670dadc98c05de18bddf3912e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339660
Reviewed-by: Phil Quitslund <pquitslund@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
diff --git a/pkg/linter/pubspec.yaml b/pkg/linter/pubspec.yaml
index 497d7d3..976239b 100644
--- a/pkg/linter/pubspec.yaml
+++ b/pkg/linter/pubspec.yaml
@@ -21,6 +21,7 @@
# Use 'any' constraints here; we get our versions from the DEPS file.
dev_dependencies:
+ analyzer_utilities: any
args: any
cli_util: any
glob: any
diff --git a/pkg/linter/test/validate_sdk_version_map.dart b/pkg/linter/test/validate_sdk_version_map.dart
index 59fdadb..ae4eadb 100644
--- a/pkg/linter/test/validate_sdk_version_map.dart
+++ b/pkg/linter/test/validate_sdk_version_map.dart
@@ -5,14 +5,19 @@
import 'dart:io';
import 'package:analyzer/src/lint/state.dart';
+import 'package:analyzer_utilities/package_root.dart' as pkg_root;
import 'package:linter/src/analyzer.dart';
import 'package:linter/src/rules.dart';
+import 'package:path/path.dart' as path;
import 'package:test/test.dart';
import 'package:yaml/yaml.dart';
void main() {
group('check to ensure all lints have versions in `sdk.yaml`', () {
- var sinceFile = File('tool/since/sdk.yaml').readAsStringSync();
+ var linterPkgPath =
+ path.normalize(path.join(pkg_root.packageRoot, 'linter'));
+ var sinceFile = File(path.join(linterPkgPath, 'tool', 'since', 'sdk.yaml'))
+ .readAsStringSync();
var versionMap = loadYamlNode(sinceFile) as YamlMap;
registerLintRules();
var publicRules =