mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:37:12 +00:00
b25a68ecf5
Change-Id: Icffcc6e64c538de45b055a691a06db5cb6ca3783 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140560 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
76 lines
2.2 KiB
Dart
76 lines
2.2 KiB
Dart
// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:analyzer_cli/src/driver.dart';
|
|
import 'package:analyzer_cli/src/options.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:test/test.dart';
|
|
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
|
|
|
import 'utils.dart';
|
|
|
|
void main() {
|
|
defineReflectiveTests(ErrorsReportedOnceTest);
|
|
}
|
|
|
|
@reflectiveTest
|
|
class ErrorsReportedOnceTest {
|
|
StringSink savedOutSink, savedErrorSink;
|
|
int savedExitCode;
|
|
ExitHandler savedExitHandler;
|
|
|
|
void setUp() {
|
|
savedOutSink = outSink;
|
|
savedErrorSink = errorSink;
|
|
savedExitHandler = exitHandler;
|
|
savedExitCode = exitCode;
|
|
exitHandler = (code) => exitCode = code;
|
|
outSink = StringBuffer();
|
|
errorSink = StringBuffer();
|
|
}
|
|
|
|
void tearDown() {
|
|
outSink = savedOutSink;
|
|
errorSink = savedErrorSink;
|
|
exitCode = savedExitCode;
|
|
exitHandler = savedExitHandler;
|
|
}
|
|
|
|
Future<void> test_once() async {
|
|
var testDir = path.join(testDirectory, 'data', 'errors_reported_once');
|
|
var driver = Driver(isTesting: true);
|
|
await driver.start(
|
|
[path.join(testDir, 'foo.dart'), path.join(testDir, 'bar.dart')]);
|
|
|
|
expect(exitCode, 0);
|
|
|
|
// Ensure that we only have one copy of the error.
|
|
final unusedWarning = 'Unused import';
|
|
var output = outSink.toString();
|
|
expect(output, contains(unusedWarning));
|
|
expect(unusedWarning.allMatches(output).toList(), hasLength(1));
|
|
}
|
|
|
|
Future<void> test_once_machine() async {
|
|
var testDir = path.join(testDirectory, 'data', 'errors_reported_once');
|
|
var driver = Driver(isTesting: true);
|
|
await driver.start([
|
|
'--format',
|
|
'machine',
|
|
path.join(testDir, 'foo.dart'),
|
|
path.join(testDir, 'bar.dart')
|
|
]);
|
|
|
|
expect(exitCode, 0);
|
|
|
|
// Ensure that we only have one copy of the error.
|
|
final unusedWarning = 'Unused import';
|
|
var output = errorSink.toString();
|
|
expect(output, contains(unusedWarning));
|
|
expect(unusedWarning.allMatches(output).toList(), hasLength(1));
|
|
}
|
|
}
|