Unnecessary new (#20138)
* enable lint unnecessary_new * fix tests * fix tests * fix tests
This commit is contained in:
committed by
GitHub
parent
d7a0dcaa4a
commit
d927c93310
@@ -15,10 +15,10 @@ void main() {
|
||||
);
|
||||
final List<String> stdout = await process.stdout.transform(utf8.decoder).transform(const LineSplitter()).toList();
|
||||
final List<String> stderr = await process.stderr.transform(utf8.decoder).transform(const LineSplitter()).toList();
|
||||
final Match line = new RegExp(r'^(.+)/main\.dart:[0-9]+:[0-9]+: .+$').matchAsPrefix(stdout[1]);
|
||||
final Match line = RegExp(r'^(.+)/main\.dart:[0-9]+:[0-9]+: .+$').matchAsPrefix(stdout[1]);
|
||||
expect(line, isNot(isNull));
|
||||
final String directory = line.group(1);
|
||||
new Directory(directory).deleteSync(recursive: true);
|
||||
Directory(directory).deleteSync(recursive: true);
|
||||
expect(await process.exitCode, 1);
|
||||
expect(stderr, isEmpty);
|
||||
expect(stdout, <String>[
|
||||
|
||||
@@ -13,7 +13,7 @@ export 'package:test/test.dart' hide TypeMatcher, isInstanceOf;
|
||||
// TODO(ianh): Remove this file once https://github.com/dart-lang/matcher/issues/98 is fixed
|
||||
|
||||
/// A matcher that compares the type of the actual value to the type argument T.
|
||||
Matcher isInstanceOf<T>() => new test_package.TypeMatcher<T>(); // ignore: prefer_const_constructors, https://github.com/dart-lang/sdk/issues/32544
|
||||
Matcher isInstanceOf<T>() => test_package.TypeMatcher<T>(); // ignore: prefer_const_constructors, https://github.com/dart-lang/sdk/issues/32544
|
||||
|
||||
void tryToDelete(Directory directory) {
|
||||
// This should not be necessary, but it turns out that
|
||||
|
||||
@@ -36,7 +36,7 @@ class FakeProcessManager extends Mock implements ProcessManager {
|
||||
_fakeResults = <String, List<ProcessResult>>{};
|
||||
for (String key in value.keys) {
|
||||
_fakeResults[key] = <ProcessResult>[]
|
||||
..addAll(value[key] ?? <ProcessResult>[new ProcessResult(0, 0, '', '')]);
|
||||
..addAll(value[key] ?? <ProcessResult>[ProcessResult(0, 0, '', '')]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,11 +63,11 @@ class FakeProcessManager extends Mock implements ProcessManager {
|
||||
}
|
||||
|
||||
FakeProcess _popProcess(List<String> command) =>
|
||||
new FakeProcess(_popResult(command), stdinResults: stdinResults);
|
||||
FakeProcess(_popResult(command), stdinResults: stdinResults);
|
||||
|
||||
Future<Process> _nextProcess(Invocation invocation) async {
|
||||
invocations.add(invocation);
|
||||
return new Future<Process>.value(_popProcess(invocation.positionalArguments[0]));
|
||||
return Future<Process>.value(_popProcess(invocation.positionalArguments[0]));
|
||||
}
|
||||
|
||||
ProcessResult _nextResultSync(Invocation invocation) {
|
||||
@@ -77,7 +77,7 @@ class FakeProcessManager extends Mock implements ProcessManager {
|
||||
|
||||
Future<ProcessResult> _nextResult(Invocation invocation) async {
|
||||
invocations.add(invocation);
|
||||
return new Future<ProcessResult>.value(_popResult(invocation.positionalArguments[0]));
|
||||
return Future<ProcessResult>.value(_popResult(invocation.positionalArguments[0]));
|
||||
}
|
||||
|
||||
void _setupMock() {
|
||||
@@ -118,10 +118,10 @@ class FakeProcessManager extends Mock implements ProcessManager {
|
||||
/// A fake process that can be used to interact with a process "started" by the FakeProcessManager.
|
||||
class FakeProcess extends Mock implements Process {
|
||||
FakeProcess(ProcessResult result, {void stdinResults(String input)})
|
||||
: stdoutStream = new Stream<List<int>>.fromIterable(<List<int>>[result.stdout.codeUnits]),
|
||||
stderrStream = new Stream<List<int>>.fromIterable(<List<int>>[result.stderr.codeUnits]),
|
||||
: stdoutStream = Stream<List<int>>.fromIterable(<List<int>>[result.stdout.codeUnits]),
|
||||
stderrStream = Stream<List<int>>.fromIterable(<List<int>>[result.stderr.codeUnits]),
|
||||
desiredExitCode = result.exitCode,
|
||||
stdinSink = new IOSink(new StringStreamConsumer(stdinResults)) {
|
||||
stdinSink = IOSink(StringStreamConsumer(stdinResults)) {
|
||||
_setupMock();
|
||||
}
|
||||
|
||||
@@ -135,7 +135,7 @@ class FakeProcess extends Mock implements Process {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<int> get exitCode => new Future<int>.value(desiredExitCode);
|
||||
Future<int> get exitCode => Future<int>.value(desiredExitCode);
|
||||
|
||||
@override
|
||||
int get pid => 0;
|
||||
@@ -167,14 +167,14 @@ class StringStreamConsumer implements StreamConsumer<List<int>> {
|
||||
@override
|
||||
Future<dynamic> addStream(Stream<List<int>> value) {
|
||||
streams.add(value);
|
||||
completers.add(new Completer<dynamic>());
|
||||
completers.add(Completer<dynamic>());
|
||||
subscriptions.add(
|
||||
value.listen((List<int> data) {
|
||||
sendString(utf8.decode(data));
|
||||
}),
|
||||
);
|
||||
subscriptions.last.onDone(() => completers.last.complete(null));
|
||||
return new Future<dynamic>.value(null);
|
||||
return Future<dynamic>.value(null);
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -185,6 +185,6 @@ class StringStreamConsumer implements StreamConsumer<List<int>> {
|
||||
completers.clear();
|
||||
streams.clear();
|
||||
subscriptions.clear();
|
||||
return new Future<dynamic>.value(null);
|
||||
return Future<dynamic>.value(null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ void main() {
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
processManager = new FakeProcessManager(stdinResults: _captureStdin);
|
||||
processManager = FakeProcessManager(stdinResults: _captureStdin);
|
||||
});
|
||||
|
||||
tearDown(() async {});
|
||||
@@ -27,10 +27,10 @@ void main() {
|
||||
test('start works', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
@@ -49,10 +49,10 @@ void main() {
|
||||
test('run works', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
@@ -66,10 +66,10 @@ void main() {
|
||||
test('runSync works', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
@@ -83,10 +83,10 @@ void main() {
|
||||
test('captures stdin', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil acl get gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output1', '')
|
||||
ProcessResult(0, 0, 'output1', '')
|
||||
],
|
||||
'gsutil cat gs://flutter_infra/releases/releases.json': <ProcessResult>[
|
||||
new ProcessResult(0, 0, 'output2', '')
|
||||
ProcessResult(0, 0, 'output2', '')
|
||||
],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
|
||||
@@ -20,7 +20,7 @@ void main() {
|
||||
test('Throws on missing executable', () async {
|
||||
// Uses a *real* process manager, since we want to know what happens if
|
||||
// it can't find an executable.
|
||||
final ProcessRunner processRunner = new ProcessRunner(subprocessOutput: false);
|
||||
final ProcessRunner processRunner = ProcessRunner(subprocessOutput: false);
|
||||
expect(
|
||||
expectAsync1((List<String> commandLine) async {
|
||||
return processRunner.runProcess(commandLine);
|
||||
@@ -36,27 +36,27 @@ void main() {
|
||||
}
|
||||
});
|
||||
for (String platformName in <String>['macos', 'linux', 'windows']) {
|
||||
final FakePlatform platform = new FakePlatform(
|
||||
final FakePlatform platform = FakePlatform(
|
||||
operatingSystem: platformName,
|
||||
environment: <String, String>{},
|
||||
);
|
||||
group('ProcessRunner for $platform', () {
|
||||
test('Returns stdout', () async {
|
||||
final FakeProcessManager fakeProcessManager = new FakeProcessManager();
|
||||
final FakeProcessManager fakeProcessManager = FakeProcessManager();
|
||||
fakeProcessManager.fakeResults = <String, List<ProcessResult>>{
|
||||
'echo test': <ProcessResult>[new ProcessResult(0, 0, 'output', 'error')],
|
||||
'echo test': <ProcessResult>[ProcessResult(0, 0, 'output', 'error')],
|
||||
};
|
||||
final ProcessRunner processRunner = new ProcessRunner(
|
||||
final ProcessRunner processRunner = ProcessRunner(
|
||||
subprocessOutput: false, platform: platform, processManager: fakeProcessManager);
|
||||
final String output = await processRunner.runProcess(<String>['echo', 'test']);
|
||||
expect(output, equals('output'));
|
||||
});
|
||||
test('Throws on process failure', () async {
|
||||
final FakeProcessManager fakeProcessManager = new FakeProcessManager();
|
||||
final FakeProcessManager fakeProcessManager = FakeProcessManager();
|
||||
fakeProcessManager.fakeResults = <String, List<ProcessResult>>{
|
||||
'echo test': <ProcessResult>[new ProcessResult(0, -1, 'output', 'error')],
|
||||
'echo test': <ProcessResult>[ProcessResult(0, -1, 'output', 'error')],
|
||||
};
|
||||
final ProcessRunner processRunner = new ProcessRunner(
|
||||
final ProcessRunner processRunner = ProcessRunner(
|
||||
subprocessOutput: false, platform: platform, processManager: fakeProcessManager);
|
||||
expect(
|
||||
expectAsync1((List<String> commandLine) async {
|
||||
@@ -75,17 +75,17 @@ void main() {
|
||||
String flutter;
|
||||
|
||||
Future<Uint8List> fakeHttpReader(Uri url, {Map<String, String> headers}) {
|
||||
return new Future<Uint8List>.value(new Uint8List(0));
|
||||
return Future<Uint8List>.value(Uint8List(0));
|
||||
}
|
||||
|
||||
setUp(() async {
|
||||
processManager = new FakeProcessManager();
|
||||
processManager = FakeProcessManager();
|
||||
args.clear();
|
||||
namedArgs.clear();
|
||||
tempDir = Directory.systemTemp.createTempSync('flutter_prepage_package_test.');
|
||||
flutterDir = new Directory(path.join(tempDir.path, 'flutter'));
|
||||
flutterDir = Directory(path.join(tempDir.path, 'flutter'));
|
||||
flutterDir.createSync(recursive: true);
|
||||
creator = new ArchiveCreator(
|
||||
creator = ArchiveCreator(
|
||||
tempDir,
|
||||
tempDir,
|
||||
testRef,
|
||||
@@ -108,7 +108,7 @@ void main() {
|
||||
'git clone -b dev https://chromium.googlesource.com/external/github.com/flutter/flutter': null,
|
||||
'git reset --hard $testRef': null,
|
||||
'git remote set-url origin https://github.com/flutter/flutter.git': null,
|
||||
'git describe --tags --abbrev=0': <ProcessResult>[new ProcessResult(0, 0, 'v1.2.3', '')],
|
||||
'git describe --tags --abbrev=0': <ProcessResult>[ProcessResult(0, 0, 'v1.2.3', '')],
|
||||
};
|
||||
if (platform.isWindows) {
|
||||
calls['7za x ${path.join(tempDir.path, 'mingit.zip')}'] = null;
|
||||
@@ -151,7 +151,7 @@ void main() {
|
||||
'git clone -b dev https://chromium.googlesource.com/external/github.com/flutter/flutter': null,
|
||||
'git reset --hard $testRef': null,
|
||||
'git remote set-url origin https://github.com/flutter/flutter.git': null,
|
||||
'git describe --tags --abbrev=0': <ProcessResult>[new ProcessResult(0, 0, 'v1.2.3', '')],
|
||||
'git describe --tags --abbrev=0': <ProcessResult>[ProcessResult(0, 0, 'v1.2.3', '')],
|
||||
};
|
||||
if (platform.isWindows) {
|
||||
calls['7za x ${path.join(tempDir.path, 'mingit.zip')}'] = null;
|
||||
@@ -176,7 +176,7 @@ void main() {
|
||||
calls['tar cJf $archiveName flutter'] = null;
|
||||
}
|
||||
processManager.fakeResults = calls;
|
||||
creator = new ArchiveCreator(
|
||||
creator = ArchiveCreator(
|
||||
tempDir,
|
||||
tempDir,
|
||||
testRef,
|
||||
@@ -194,8 +194,8 @@ void main() {
|
||||
test('throws when a command errors out', () async {
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'git clone -b dev https://chromium.googlesource.com/external/github.com/flutter/flutter':
|
||||
<ProcessResult>[new ProcessResult(0, 0, 'output1', '')],
|
||||
'git reset --hard $testRef': <ProcessResult>[new ProcessResult(0, -1, 'output2', '')],
|
||||
<ProcessResult>[ProcessResult(0, 0, 'output1', '')],
|
||||
'git reset --hard $testRef': <ProcessResult>[ProcessResult(0, -1, 'output2', '')],
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
expect(expectAsync0(creator.initializeRepo),
|
||||
@@ -208,7 +208,7 @@ void main() {
|
||||
Directory tempDir;
|
||||
|
||||
setUp(() async {
|
||||
processManager = new FakeProcessManager();
|
||||
processManager = FakeProcessManager();
|
||||
tempDir = Directory.systemTemp.createTempSync('flutter_prepage_package_test.');
|
||||
});
|
||||
|
||||
@@ -255,7 +255,7 @@ void main() {
|
||||
]
|
||||
}
|
||||
''';
|
||||
new File(jsonPath).writeAsStringSync(releasesJson);
|
||||
File(jsonPath).writeAsStringSync(releasesJson);
|
||||
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
|
||||
'gsutil rm $gsArchivePath': null,
|
||||
'gsutil -h Content-Type:$archiveMime cp $archivePath $gsArchivePath': null,
|
||||
@@ -264,9 +264,9 @@ void main() {
|
||||
'gsutil -h Content-Type:application/json cp $jsonPath $gsJsonPath': null,
|
||||
};
|
||||
processManager.fakeResults = calls;
|
||||
final File outputFile = new File(path.join(tempDir.absolute.path, archiveName));
|
||||
final File outputFile = File(path.join(tempDir.absolute.path, archiveName));
|
||||
assert(tempDir.existsSync());
|
||||
final ArchivePublisher publisher = new ArchivePublisher(
|
||||
final ArchivePublisher publisher = ArchivePublisher(
|
||||
tempDir,
|
||||
testRef,
|
||||
Branch.release,
|
||||
@@ -279,7 +279,7 @@ void main() {
|
||||
assert(tempDir.existsSync());
|
||||
await publisher.publishArchive();
|
||||
processManager.verifyCalls(calls.keys.toList());
|
||||
final File releaseFile = new File(jsonPath);
|
||||
final File releaseFile = File(jsonPath);
|
||||
expect(releaseFile.existsSync(), isTrue);
|
||||
final String contents = releaseFile.readAsStringSync();
|
||||
// Make sure new data is added.
|
||||
@@ -299,7 +299,7 @@ void main() {
|
||||
// Make sure the new entry is first (and hopefully it takes less than a
|
||||
// minute to go from publishArchive above to this line!).
|
||||
expect(
|
||||
new DateTime.now().difference(DateTime.parse(releases[0]['release_date'])),
|
||||
DateTime.now().difference(DateTime.parse(releases[0]['release_date'])),
|
||||
lessThan(const Duration(minutes: 1)),
|
||||
);
|
||||
const JsonEncoder encoder = JsonEncoder.withIndent(' ');
|
||||
|
||||
Reference in New Issue
Block a user