flutter/dev/tools/test/engine_hash_test.dart
Michael Goderbauer 5491c8c146
Auto-format Framework (#160545)
This auto-formats all *.dart files in the repository outside of the
`engine` subdirectory and enforces that these files stay formatted with
a presubmit check.

**Reviewers:** Please carefully review all the commits except for the
one titled "formatted". The "formatted" commit was auto-generated by
running `dev/tools/format.sh -a -f`. The other commits were hand-crafted
to prepare the repo for the formatting change. I recommend reviewing the
commits one-by-one via the "Commits" tab and avoiding Github's "Files
changed" tab as it will likely slow down your browser because of the
size of this PR.

---------

Co-authored-by: Kate Lovett <katelovett@google.com>
Co-authored-by: LongCatIsLooong <31859944+LongCatIsLooong@users.noreply.github.com>
2024-12-19 20:06:21 +00:00

100 lines
2.8 KiB
Dart

// Copyright 2014 The Flutter Authors. 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' as io;
import 'package:collection/collection.dart';
import 'package:test/test.dart';
import '../bin/engine_hash.dart' show GitRevisionStrategy, engineHash;
void main() {
test('Produces an engine hash for merge-base', () async {
final Future<io.ProcessResult> Function(List<String>) runProcess = _fakeProcesses(
processes: <FakeProcess>[
(
exe: 'git',
command: 'merge-base',
rest: <String>['upstream/master', 'HEAD'],
exitCode: 0,
stdout: 'abcdef1234',
stderr: null,
),
(
exe: 'git',
command: 'ls-tree',
rest: <String>['-r', 'abcdef1234', 'engine', 'DEPS'],
exitCode: 0,
stdout: 'one\r\ntwo\r\n',
stderr: null,
),
],
);
final Future<String> result = engineHash(runProcess);
expect(result, completion('c708d7ef841f7e1748436b8ef5670d0b2de1a227'));
});
test('Produces an engine hash for HEAD', () async {
final Future<io.ProcessResult> Function(List<String>) runProcess = _fakeProcesses(
processes: <FakeProcess>[
(
exe: 'git',
command: 'ls-tree',
rest: <String>['-r', 'HEAD', 'engine', 'DEPS'],
exitCode: 0,
stdout: 'one\ntwo\n',
stderr: null,
),
],
);
final Future<String> result = engineHash(
runProcess,
revisionStrategy: GitRevisionStrategy.head,
);
expect(result, completion('c708d7ef841f7e1748436b8ef5670d0b2de1a227'));
});
test('Returns error in non-monorepo', () async {
final Future<io.ProcessResult> Function(List<String>) runProcess = _fakeProcesses(
processes: <FakeProcess>[
(
exe: 'git',
command: 'ls-tree',
rest: <String>['-r', 'HEAD', 'engine', 'DEPS'],
exitCode: 0,
stdout: '',
stderr: null,
),
],
);
final Future<String> result = engineHash(
runProcess,
revisionStrategy: GitRevisionStrategy.head,
);
expect(result, throwsA('Not in a monorepo'));
});
}
typedef FakeProcess =
({String exe, String command, List<String> rest, dynamic stdout, dynamic stderr, int exitCode});
Future<io.ProcessResult> Function(List<String>) _fakeProcesses({
required List<FakeProcess> processes,
}) => (List<String> cmd) async {
for (final FakeProcess process in processes) {
if (process.exe.endsWith(cmd[0]) &&
process.command.endsWith(cmd[1]) &&
process.rest.equals(cmd.sublist(2))) {
return io.ProcessResult(1, process.exitCode, process.stdout, process.stderr);
}
}
return io.ProcessResult(1, -42, '', '404 command not found: $cmd');
};