|
| 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