Run dart fix on customer tests as promised (#83944)

This commit is contained in:
Ian Hickson
2021-06-04 01:09:02 -07:00
committed by GitHub
parent ab06d7dddd
commit 0acf53e310
2 changed files with 97 additions and 47 deletions

View File

@@ -31,13 +31,21 @@ Future<bool> runTests({
if (verbose) {
final String s = files.length == 1 ? '' : 's';
final String ss = shardedFiles.length == 1 ? '' : 's';
print('${files.length} file$s specified. ${shardedFiles.length} test$ss in shard #$shardIndex.');
if (numberShards > 1) {
final String ss = shardedFiles.length == 1 ? '' : 's';
print('${files.length} file$s specified. ${shardedFiles.length} test$ss in shard #$shardIndex ($numberShards shards total).');
} else {
print('${files.length} file$s specified.');
}
print('');
}
if (verbose) {
print('Tests in this shard:');
if (numberShards > 1) {
print('Tests in this shard:');
} else {
print('Tests:');
}
for (final File file in shardedFiles)
print(file.path);
}
@@ -46,30 +54,40 @@ Future<bool> runTests({
for (final File file in shardedFiles) {
if (verbose)
print('Processing ${file.path}...');
void printHeader() {
if (!verbose)
print('Processing ${file.path}...');
}
void failure(String message) {
printHeader();
print('ERROR: $message');
failures += 1;
}
CustomerTest instructions;
try {
instructions = CustomerTest(file);
} on FormatException catch (error) {
print('ERROR: ${error.message}');
failure(error.message);
print('');
failures += 1;
continue;
} on FileSystemException catch (error) {
print('ERROR: ${error.message}');
print(' ${file.path}');
failure(error.message);
print('');
failures += 1;
continue;
}
bool success = true;
final Directory checkout = Directory.systemTemp.createTempSync('flutter_customer_testing.${path.basenameWithoutExtension(file.path)}.');
if (verbose)
print('Created temporary directory: ${checkout.path}');
try {
bool? success;
bool showContacts = false;
assert(instructions.fetch.isNotEmpty);
for (final String fetchCommand in instructions.fetch) {
success = await shell(fetchCommand, checkout, verbose: verbose, silentFailure: skipOnFetchFailure);
success = await shell(fetchCommand, checkout, verbose: verbose, silentFailure: skipOnFetchFailure, failedCallback: printHeader);
if (!success) {
if (skipOnFetchFailure) {
if (verbose) {
@@ -78,39 +96,51 @@ Future<bool> runTests({
print('Skipping ${file.path} (fetch failed).');
}
} else {
print('ERROR: Failed to fetch repository.');
failures += 1;
showContacts = true;
failure('Failed to fetch repository.');
}
break;
}
}
assert(success != null);
if (success == true) {
if (verbose)
print('Running tests...');
final Directory tests = Directory(path.join(checkout.path, 'tests'));
// TODO(ianh): Once we have a way to update source code, run that command in each directory of instructions.update
for (int iteration = 0; iteration < repeat; iteration += 1) {
if (verbose && repeat > 1)
print('Round ${iteration + 1} of $repeat.');
for (final String testCommand in instructions.tests) {
testCount += 1;
success = await shell(testCommand, tests, verbose: verbose);
if (!success) {
print('ERROR: One or more tests from ${path.basenameWithoutExtension(file.path)} failed.');
failures += 1;
showContacts = true;
break;
}
if (success) {
final Directory customerRepo = Directory(path.join(checkout.path, 'tests'));
for (final Directory updateDirectory in instructions.update) {
final Directory resolvedUpdateDirectory = Directory(path.join(customerRepo.path, updateDirectory.path));
if (verbose)
print('Updating code in ${resolvedUpdateDirectory.path}...');
if (!File(path.join(resolvedUpdateDirectory.path, 'pubspec.yaml')).existsSync()) {
failure('The directory ${updateDirectory.path}, which was specified as an update directory, does not contain a "pubspec.yaml" file.');
success = false;
break;
}
success = await shell('flutter packages get', resolvedUpdateDirectory, verbose: verbose, failedCallback: printHeader);
if (!success) {
failure('Could not run "flutter pub get" in ${updateDirectory.path}, which was specified as an update directory.');
break;
}
success = await shell('dart fix --apply', resolvedUpdateDirectory, verbose: verbose, failedCallback: printHeader);
if (!success) {
failure('Could not run "dart fix" in ${updateDirectory.path}, which was specified as an update directory.');
break;
}
}
if (verbose && success == true)
print('Tests finished.');
}
if (showContacts) {
final String s = instructions.contacts.length == 1 ? '' : 's';
print('Contact$s: ${instructions.contacts.join(", ")}');
if (success) {
if (verbose)
print('Running tests...');
for (int iteration = 0; iteration < repeat; iteration += 1) {
if (verbose && repeat > 1)
print('Round ${iteration + 1} of $repeat.');
for (final String testCommand in instructions.tests) {
testCount += 1;
success = await shell(testCommand, customerRepo, verbose: verbose, failedCallback: printHeader);
if (!success) {
failure('One or more tests from ${path.basenameWithoutExtension(file.path)} failed.');
break;
}
}
}
if (verbose && success)
print('Tests finished.');
}
}
} finally {
if (verbose)
@@ -121,7 +151,11 @@ Future<bool> runTests({
print('Failed to delete "${checkout.path}".');
}
}
if (verbose)
if (!success) {
final String s = instructions.contacts.length == 1 ? '' : 's';
print('Contact$s: ${instructions.contacts.join(", ")}');
}
if (verbose || !success)
print('');
}
if (failures > 0) {
@@ -135,7 +169,7 @@ Future<bool> runTests({
final RegExp _spaces = RegExp(r' +');
Future<bool> shell(String command, Directory directory, { bool verbose = false, bool silentFailure = false }) async {
Future<bool> shell(String command, Directory directory, { bool verbose = false, bool silentFailure = false, void Function()? failedCallback }) async {
if (verbose)
print('>> $command');
Process process;
@@ -152,6 +186,8 @@ Future<bool> shell(String command, Directory directory, { bool verbose = false,
if (success || silentFailure)
return success;
if (!verbose) {
if (failedCallback != null)
failedCallback();
print('>> $command');
output.forEach(printLog);
}