Skip to content

Commit 9e0b973

Browse files
authored
add a test that the arg parser library only depends on package:args (#213)
cc @alexmarkov
1 parent 64dfa7f commit 9e0b973

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

pkgs/dart_mcp_server/pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ dependencies:
4040
yaml: ^3.1.3
4141

4242
dev_dependencies:
43+
analyzer: ^7.5.2
4344
dart_flutter_team_lints: ^3.2.1
45+
pub_semver: ^2.2.0
4446
test: ^1.25.15
4547
test_descriptor: ^2.0.2
4648
test_process: ^2.1.1
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
@TestOn('!windows')
6+
library;
7+
8+
import 'dart:isolate';
9+
10+
import 'package:analyzer/dart/analysis/features.dart';
11+
import 'package:analyzer/dart/analysis/utilities.dart';
12+
import 'package:analyzer/dart/ast/ast.dart';
13+
import 'package:pub_semver/pub_semver.dart';
14+
import 'package:test/test.dart';
15+
16+
void main() {
17+
test('public arg parser library only exports lib/src/arg_parser.dart', () {
18+
checkDependencies('package:dart_mcp_server/arg_parser.dart', const [
19+
'src/arg_parser.dart',
20+
]);
21+
});
22+
23+
test('arg parser implementation only depends on package:args', () {
24+
checkDependencies('package:dart_mcp_server/src/arg_parser.dart', const [
25+
'package:args/args.dart',
26+
]);
27+
});
28+
}
29+
30+
/// Checks that [libraryUri] only has directives referencing [allowedUris].
31+
///
32+
/// The [allowedUris] are matched based on the exact string, not a resolved
33+
/// URI.
34+
void checkDependencies(String libraryUri, Iterable<String> allowedUris) {
35+
final parsed = parseFile(
36+
path: Isolate.resolvePackageUriSync(Uri.parse(libraryUri))!.path,
37+
featureSet: FeatureSet.fromEnableFlags2(
38+
sdkLanguageVersion: Version.parse('3.9.0'),
39+
flags: const [],
40+
),
41+
);
42+
final uriDirectives = parsed.unit.directives.whereType<UriBasedDirective>();
43+
44+
expect(
45+
uriDirectives.map((d) => d.uri.stringValue),
46+
unorderedEquals(allowedUris),
47+
);
48+
}

0 commit comments

Comments
 (0)