flutter/dev/bots/test/post_process_docs_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

143 lines
5.1 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';
import 'package:file/memory.dart';
import 'package:platform/platform.dart';
import '../../../packages/flutter_tools/test/src/fake_process_manager.dart';
import '../post_process_docs.dart';
import 'common.dart';
void main() async {
group('getBranch', () {
const String branchName = 'stable';
test('getBranchName does not call git if env LUCI_BRANCH provided', () async {
final Platform platform = FakePlatform(
environment: <String, String>{'LUCI_BRANCH': branchName},
);
final ProcessManager processManager = FakeProcessManager.empty();
final String calculatedBranchName = await getBranchName(
platform: platform,
processManager: processManager,
);
expect(calculatedBranchName, branchName);
});
test('getBranchName calls git if env LUCI_BRANCH not provided', () async {
final Platform platform = FakePlatform(environment: <String, String>{});
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['git', 'status', '-b', '--porcelain'],
stdout: '## $branchName',
),
]);
final String calculatedBranchName = await getBranchName(
platform: platform,
processManager: processManager,
);
expect(calculatedBranchName, branchName);
expect(processManager, hasNoRemainingExpectations);
});
test('getBranchName calls git if env LUCI_BRANCH is empty', () async {
final Platform platform = FakePlatform(environment: <String, String>{'LUCI_BRANCH': ''});
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(
command: <String>['git', 'status', '-b', '--porcelain'],
stdout: '## $branchName',
),
]);
final String calculatedBranchName = await getBranchName(
platform: platform,
processManager: processManager,
);
expect(calculatedBranchName, branchName);
expect(processManager, hasNoRemainingExpectations);
});
});
group('gitRevision', () {
test('Return short format', () async {
const String commitHash = 'e65f01793938e13cac2d321b9fcdc7939f9b2ea6';
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commitHash),
]);
final String revision = await gitRevision(processManager: processManager);
expect(processManager, hasNoRemainingExpectations);
expect(revision, commitHash.substring(0, 10));
});
test('Return full length', () async {
const String commitHash = 'e65f01793938e13cac2d321b9fcdc7939f9b2ea6';
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: <String>['git', 'rev-parse', 'HEAD'], stdout: commitHash),
]);
final String revision = await gitRevision(fullLength: true, processManager: processManager);
expect(processManager, hasNoRemainingExpectations);
expect(revision, commitHash);
});
});
group('runProcessWithValidation', () {
test('With no error', () async {
const List<String> command = <String>['git', 'rev-parse', 'HEAD'];
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: command),
]);
await runProcessWithValidations(command, '', processManager: processManager, verbose: false);
expect(processManager, hasNoRemainingExpectations);
});
test('With error', () async {
const List<String> command = <String>['git', 'rev-parse', 'HEAD'];
final ProcessManager processManager = FakeProcessManager.list(<FakeCommand>[
const FakeCommand(command: command, exitCode: 1),
]);
try {
await runProcessWithValidations(
command,
'',
processManager: processManager,
verbose: false,
);
throw Exception('Exception was not thrown');
} on CommandException catch (e) {
expect(e, isA<Exception>());
}
});
});
group('generateFooter', () {
test('generated correctly', () async {
const String expectedContent = '''
(function() {
var span = document.querySelector('footer>span');
if (span) {
span.innerText = 'Flutter 3.0.0 • 2022-09-22 14:09 • abcdef • stable';
}
var sourceLink = document.querySelector('a.source-link');
if (sourceLink) {
sourceLink.href = sourceLink.href.replace('/master/', '/abcdef/');
}
})();
''';
final MemoryFileSystem fs = MemoryFileSystem();
final File footerFile = fs.file('/a/b/c/footer.js')..createSync(recursive: true);
await createFooter(
footerFile,
'3.0.0',
timestampParam: '2022-09-22 14:09',
branchParam: 'stable',
revisionParam: 'abcdef',
);
final String content = await footerFile.readAsString();
expect(content, expectedContent);
});
});
}