Skip to content

Commit a25eb56

Browse files
stereotype441Commit Queue
authored andcommitted
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>
1 parent 9c3044f commit a25eb56

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pkg/linter/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies:
2121

2222
# Use 'any' constraints here; we get our versions from the DEPS file.
2323
dev_dependencies:
24+
analyzer_utilities: any
2425
args: any
2526
cli_util: any
2627
glob: any

pkg/linter/test/validate_sdk_version_map.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
import 'dart:io';
66

77
import 'package:analyzer/src/lint/state.dart';
8+
import 'package:analyzer_utilities/package_root.dart' as pkg_root;
89
import 'package:linter/src/analyzer.dart';
910
import 'package:linter/src/rules.dart';
11+
import 'package:path/path.dart' as path;
1012
import 'package:test/test.dart';
1113
import 'package:yaml/yaml.dart';
1214

1315
void main() {
1416
group('check to ensure all lints have versions in `sdk.yaml`', () {
15-
var sinceFile = File('tool/since/sdk.yaml').readAsStringSync();
17+
var linterPkgPath =
18+
path.normalize(path.join(pkg_root.packageRoot, 'linter'));
19+
var sinceFile = File(path.join(linterPkgPath, 'tool', 'since', 'sdk.yaml'))
20+
.readAsStringSync();
1621
var versionMap = loadYamlNode(sinceFile) as YamlMap;
1722
registerLintRules();
1823
var publicRules =

0 commit comments

Comments
 (0)