Index: pkg/analyzer_cli/test/package_prefix_test.dart |
diff --git a/pkg/analyzer_cli/test/package_prefix_test.dart b/pkg/analyzer_cli/test/package_prefix_test.dart |
new file mode 100644 |
index 0000000000000000000000000000000000000000..23ff67f2c91b6d7aed6bb8bb86b0cd23433fdd26 |
--- /dev/null |
+++ b/pkg/analyzer_cli/test/package_prefix_test.dart |
@@ -0,0 +1,69 @@ |
+import 'dart:io' show exitCode; |
+ |
+import 'package:analyzer_cli/src/driver.dart' show Driver, outSink, errorSink; |
+import 'package:analyzer_cli/src/options.dart' show ExitHandler, exitHandler; |
+import 'package:unittest/unittest.dart'; |
+ |
+main() { |
+ group('--x-package-warnings-prefix', () { |
+ _Runner runner; |
+ |
+ setUp(() { |
+ runner = new _Runner.setUp(); |
+ }); |
+ |
+ tearDown(() { |
+ runner.tearDown(); |
+ runner = null; |
+ }); |
+ |
+ test('shows only the hint whose package matches the prefix', () { |
+ runner.run([ |
+ "--packages", |
+ "test/data/package_prefix/packagelist", |
+ "--x-package-warnings-prefix=f", |
+ "test/data/package_prefix/main.dart" |
+ ]); |
+ expect(runner.stdout, contains('1 hint found')); |
+ expect(runner.stdout, contains('Unused import')); |
+ expect(runner.stdout, contains('package_prefix/pkg/foo/foo.dart')); |
+ expect(runner.stdout, isNot(contains('bar.dart'))); |
+ }); |
+ }); |
+} |
+ |
+class _Runner { |
+ final _stdout = new StringBuffer(); |
+ final _stderr = new StringBuffer(); |
+ |
+ final StringSink _savedOutSink; |
+ final StringSink _savedErrorSink; |
+ final int _savedExitCode; |
+ final ExitHandler _savedExitHandler; |
+ |
+ _Runner.setUp() |
+ : _savedOutSink = outSink, |
+ _savedErrorSink = errorSink, |
+ _savedExitHandler = exitHandler, |
+ _savedExitCode = exitCode { |
+ outSink = _stdout; |
+ errorSink = _stderr; |
+ } |
+ |
+ void run(List<String> args) { |
+ new Driver().start(args); |
+ if (stderr.isNotEmpty) { |
+ fail("Unexpected output to stderr:\n$stderr"); |
+ } |
+ } |
+ |
+ String get stdout => _stdout.toString(); |
+ String get stderr => _stderr.toString(); |
+ |
+ void tearDown() { |
+ outSink = _savedOutSink; |
+ errorSink = _savedErrorSink; |
+ exitCode = _savedExitCode; |
+ exitHandler = _savedExitHandler; |
+ } |
+} |