Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 97901da

Browse files
authored
Cleaner test.dart output. (#109206)
1 parent d50c5b1 commit 97901da

File tree

8 files changed

+573
-742
lines changed

8 files changed

+573
-742
lines changed

dev/bots/analyze.dart

Lines changed: 54 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ Future<void> main(List<String> arguments) async {
4444
);
4545
dart = path.join(dartSdk, 'bin', Platform.isWindows ? 'dart.exe' : 'dart');
4646
pub = path.join(dartSdk, 'bin', Platform.isWindows ? 'pub.bat' : 'pub');
47-
print('$clock STARTING ANALYSIS');
47+
printProgress('STARTING ANALYSIS');
4848
await run(arguments);
4949
if (hasError) {
50-
print('$clock ${bold}Test failed.$reset');
50+
printProgress('${bold}Test failed.$reset');
5151
reportErrorsAndExit();
5252
}
53-
print('$clock ${bold}Analysis successful.$reset');
53+
printProgress('${bold}Analysis successful.$reset');
5454
}
5555

5656
/// Scans [arguments] for an argument of the form `--dart-sdk` or
@@ -88,85 +88,85 @@ Future<void> run(List<String> arguments) async {
8888
foundError(<String>['The analyze.dart script must be run with --enable-asserts.']);
8989
}
9090

91-
print('$clock No Double.clamp');
91+
printProgress('No Double.clamp');
9292
await verifyNoDoubleClamp(flutterRoot);
9393

94-
print('$clock All tool test files end in _test.dart...');
94+
printProgress('All tool test files end in _test.dart...');
9595
await verifyToolTestsEndInTestDart(flutterRoot);
9696

97-
print('$clock No sync*/async*');
97+
printProgress('No sync*/async*');
9898
await verifyNoSyncAsyncStar(flutterPackages);
9999
await verifyNoSyncAsyncStar(flutterExamples, minimumMatches: 200);
100100

101-
print('$clock No runtimeType in toString...');
101+
printProgress('No runtimeType in toString...');
102102
await verifyNoRuntimeTypeInToString(flutterRoot);
103103

104-
print('$clock Debug mode instead of checked mode...');
104+
printProgress('Debug mode instead of checked mode...');
105105
await verifyNoCheckedMode(flutterRoot);
106106

107-
print('$clock Links for creating GitHub issues');
107+
printProgress('Links for creating GitHub issues');
108108
await verifyIssueLinks(flutterRoot);
109109

110-
print('$clock Unexpected binaries...');
110+
printProgress('Unexpected binaries...');
111111
await verifyNoBinaries(flutterRoot);
112112

113-
print('$clock Trailing spaces...');
113+
printProgress('Trailing spaces...');
114114
await verifyNoTrailingSpaces(flutterRoot); // assumes no unexpected binaries, so should be after verifyNoBinaries
115115

116-
print('$clock Deprecations...');
116+
printProgress('Deprecations...');
117117
await verifyDeprecations(flutterRoot);
118118

119-
print('$clock Goldens...');
119+
printProgress('Goldens...');
120120
await verifyGoldenTags(flutterPackages);
121121

122-
print('$clock Skip test comments...');
122+
printProgress('Skip test comments...');
123123
await verifySkipTestComments(flutterRoot);
124124

125-
print('$clock Licenses...');
125+
printProgress('Licenses...');
126126
await verifyNoMissingLicense(flutterRoot);
127127

128-
print('$clock Test imports...');
128+
printProgress('Test imports...');
129129
await verifyNoTestImports(flutterRoot);
130130

131-
print('$clock Bad imports (framework)...');
131+
printProgress('Bad imports (framework)...');
132132
await verifyNoBadImportsInFlutter(flutterRoot);
133133

134-
print('$clock Bad imports (tools)...');
134+
printProgress('Bad imports (tools)...');
135135
await verifyNoBadImportsInFlutterTools(flutterRoot);
136136

137-
print('$clock Internationalization...');
137+
printProgress('Internationalization...');
138138
await verifyInternationalizations(flutterRoot, dart);
139139

140-
print('$clock Integration test timeouts...');
140+
printProgress('Integration test timeouts...');
141141
await verifyIntegrationTestTimeouts(flutterRoot);
142142

143-
print('$clock null initialized debug fields...');
143+
printProgress('null initialized debug fields...');
144144
await verifyNullInitializedDebugExpensiveFields(flutterRoot);
145145

146146
// Ensure that all package dependencies are in sync.
147-
print('$clock Package dependencies...');
147+
printProgress('Package dependencies...');
148148
await runCommand(flutter, <String>['update-packages', '--verify-only'],
149149
workingDirectory: flutterRoot,
150150
);
151151

152152
/// Ensure that no new dependencies have been accidentally
153153
/// added to core packages.
154-
print('$clock Package Allowlist...');
154+
printProgress('Package Allowlist...');
155155
await _checkConsumerDependencies();
156156

157157
// Analyze all the Dart code in the repo.
158-
print('$clock Dart analysis...');
158+
printProgress('Dart analysis...');
159159
await _runFlutterAnalyze(flutterRoot, options: <String>[
160160
'--flutter-repo',
161161
...arguments,
162162
]);
163163

164-
print('$clock Executable allowlist...');
164+
printProgress('Executable allowlist...');
165165
await _checkForNewExecutables();
166166

167167
// Try with the --watch analyzer, to make sure it returns success also.
168168
// The --benchmark argument exits after one run.
169-
print('$clock Dart analysis (with --watch)...');
169+
printProgress('Dart analysis (with --watch)...');
170170
await _runFlutterAnalyze(flutterRoot, options: <String>[
171171
'--flutter-repo',
172172
'--watch',
@@ -175,14 +175,14 @@ Future<void> run(List<String> arguments) async {
175175
]);
176176

177177
// Analyze the code in `{@tool snippet}` sections in the repo.
178-
print('$clock Snippet code...');
178+
printProgress('Snippet code...');
179179
await runCommand(dart,
180180
<String>['--enable-asserts', path.join(flutterRoot, 'dev', 'bots', 'analyze_snippet_code.dart'), '--verbose'],
181181
workingDirectory: flutterRoot,
182182
);
183183

184184
// Try analysis against a big version of the gallery; generate into a temporary directory.
185-
print('$clock Dart analysis (mega gallery)...');
185+
printProgress('Dart analysis (mega gallery)...');
186186
final Directory outDir = Directory.systemTemp.createTempSync('flutter_mega_gallery.');
187187
try {
188188
await runCommand(dart,
@@ -548,27 +548,23 @@ String _generateLicense(String prefix) {
548548

549549
Future<void> verifyNoMissingLicense(String workingDirectory, { bool checkMinimums = true }) async {
550550
final int? overrideMinimumMatches = checkMinimums ? null : 0;
551-
int failed = 0;
552-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 2000, _generateLicense('// '));
553-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 39, _generateLicense('// '));
554-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'h', overrideMinimumMatches ?? 30, _generateLicense('// '));
555-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// '));
556-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'cpp', overrideMinimumMatches ?? 0, _generateLicense('// '));
557-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
558-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'gradle', overrideMinimumMatches ?? 80, _generateLicense('// '));
559-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'gn', overrideMinimumMatches ?? 0, _generateLicense('# '));
560-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, _generateLicense('# '), header: r'#!/usr/bin/env bash\n',);
561-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, _generateLicense('REM '), header: r'@ECHO off\n');
562-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'ps1', overrideMinimumMatches ?? 1, _generateLicense('# '));
563-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'html', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', trailingBlank: false, header: r'<!DOCTYPE HTML>\n');
564-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'xml', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', header: r'(<\?xml version="1.0" encoding="utf-8"\?>\n)?');
565-
failed += await _verifyNoMissingLicenseForExtension(workingDirectory, 'frag', overrideMinimumMatches ?? 1, _generateLicense('// '), header: r'#version 320 es(\n)+');
566-
if (failed > 0) {
567-
foundError(<String>['License check failed.']);
568-
}
551+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'dart', overrideMinimumMatches ?? 2000, _generateLicense('// '));
552+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'java', overrideMinimumMatches ?? 39, _generateLicense('// '));
553+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'h', overrideMinimumMatches ?? 30, _generateLicense('// '));
554+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'm', overrideMinimumMatches ?? 30, _generateLicense('// '));
555+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'cpp', overrideMinimumMatches ?? 0, _generateLicense('// '));
556+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'swift', overrideMinimumMatches ?? 10, _generateLicense('// '));
557+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gradle', overrideMinimumMatches ?? 80, _generateLicense('// '));
558+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'gn', overrideMinimumMatches ?? 0, _generateLicense('# '));
559+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'sh', overrideMinimumMatches ?? 1, _generateLicense('# '), header: r'#!/usr/bin/env bash\n',);
560+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'bat', overrideMinimumMatches ?? 1, _generateLicense('REM '), header: r'@ECHO off\n');
561+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'ps1', overrideMinimumMatches ?? 1, _generateLicense('# '));
562+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'html', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', trailingBlank: false, header: r'<!DOCTYPE HTML>\n');
563+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'xml', overrideMinimumMatches ?? 1, '<!-- ${_generateLicense('')} -->', header: r'(<\?xml version="1.0" encoding="utf-8"\?>\n)?');
564+
await _verifyNoMissingLicenseForExtension(workingDirectory, 'frag', overrideMinimumMatches ?? 1, _generateLicense('// '), header: r'#version 320 es(\n)+');
569565
}
570566

571-
Future<int> _verifyNoMissingLicenseForExtension(
567+
Future<void> _verifyNoMissingLicenseForExtension(
572568
String workingDirectory,
573569
String extension,
574570
int minimumMatches,
@@ -592,22 +588,17 @@ Future<int> _verifyNoMissingLicenseForExtension(
592588
}
593589
// Fail if any errors
594590
if (errors.isNotEmpty) {
595-
final String redLine = '$red━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━$reset';
596591
final String fileDoes = errors.length == 1 ? 'file does' : '${errors.length} files do';
597-
print(<String>[
598-
redLine,
592+
foundError(<String>[
599593
'${bold}The following $fileDoes not have the right license header for $extension files:$reset',
600594
...errors.map<String>((String error) => ' $error'),
601595
'The expected license header is:',
602596
if (header.isNotEmpty) 'A header matching the regular expression "$header",',
603597
if (header.isNotEmpty) 'followed by the following license text:',
604598
license,
605599
if (trailingBlank) '...followed by a blank line.',
606-
redLine,
607-
].join('\n'));
608-
return 1;
600+
]);
609601
}
610-
return 0;
611602
}
612603

613604
class _Line {
@@ -1650,7 +1641,7 @@ Future<EvalResult> _evalCommand(String executable, List<String> arguments, {
16501641
final String relativeWorkingDir = path.relative(workingDirectory);
16511642

16521643
if (!runSilently) {
1653-
printProgress('RUNNING', relativeWorkingDir, commandDescription);
1644+
print('RUNNING: cd $cyan$relativeWorkingDir$reset; $green$commandDescription$reset');
16541645
}
16551646

16561647
final Stopwatch time = Stopwatch()..start();
@@ -1669,12 +1660,12 @@ Future<EvalResult> _evalCommand(String executable, List<String> arguments, {
16691660
);
16701661

16711662
if (!runSilently) {
1672-
print('$clock ELAPSED TIME: $bold${prettyPrintDuration(time.elapsed)}$reset for $commandDescription in $relativeWorkingDir');
1663+
print('ELAPSED TIME: $bold${prettyPrintDuration(time.elapsed)}$reset for $commandDescription in $relativeWorkingDir');
16731664
}
16741665

16751666
if (exitCode != 0 && !allowNonZeroExit) {
1676-
stderr.write(result.stderr);
16771667
foundError(<String>[
1668+
result.stderr,
16781669
'${bold}ERROR:$red Last command exited with $exitCode.$reset',
16791670
'${bold}Command:$red $commandDescription$reset',
16801671
'${bold}Relative working directory:$red $relativeWorkingDir$reset',
@@ -1838,9 +1829,8 @@ const Set<String> kExecutableAllowlist = <String>{
18381829
Future<void> _checkForNewExecutables() async {
18391830
// 0b001001001
18401831
const int executableBitMask = 0x49;
1841-
18421832
final List<File> files = await _gitFiles(flutterRoot);
1843-
int unexpectedExecutableCount = 0;
1833+
final List<String> errors = <String>[];
18441834
for (final File file in files) {
18451835
final String relativePath = path.relative(
18461836
file.path,
@@ -1849,14 +1839,14 @@ Future<void> _checkForNewExecutables() async {
18491839
final FileStat stat = file.statSync();
18501840
final bool isExecutable = stat.mode & executableBitMask != 0x0;
18511841
if (isExecutable && !kExecutableAllowlist.contains(relativePath)) {
1852-
unexpectedExecutableCount += 1;
1853-
print('$relativePath is executable: ${(stat.mode & 0x1FF).toRadixString(2)}');
1842+
errors.add('$relativePath is executable: ${(stat.mode & 0x1FF).toRadixString(2)}');
18541843
}
18551844
}
1856-
if (unexpectedExecutableCount > 0) {
1845+
if (errors.isNotEmpty) {
18571846
throw Exception(
1858-
'found $unexpectedExecutableCount unexpected executable file'
1859-
'${unexpectedExecutableCount == 1 ? '' : 's'}! If this was intended, you '
1847+
'${errors.join('\n')}\n'
1848+
'found ${errors.length} unexpected executable file'
1849+
'${errors.length == 1 ? '' : 's'}! If this was intended, you '
18601850
'must add this file to kExecutableAllowlist in dev/bots/analyze.dart',
18611851
);
18621852
}

0 commit comments

Comments
 (0)