From ed086ad7788ccec6456da06499e999956e4bd61d Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Wed, 1 Dec 2021 20:44:06 +0000 Subject: [PATCH] dart fix: report when --compare-to-golden has unchanged files I was pretty confused about what was being compared until this change was able to highlight that no edits were made. Bug: https://github.com/dart-lang/sdk/issues/47678 Change-Id: I1d37070437658063d4b84f2fb5f4a33923bf5d92 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221840 Reviewed-by: Brian Wilkerson Commit-Queue: Samuel Rawlins --- pkg/dartdev/lib/src/commands/fix.dart | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/dartdev/lib/src/commands/fix.dart b/pkg/dartdev/lib/src/commands/fix.dart index 83c2faa4134..d6c8b5ae449 100644 --- a/pkg/dartdev/lib/src/commands/fix.dart +++ b/pkg/dartdev/lib/src/commands/fix.dart @@ -7,6 +7,7 @@ import 'dart:io' as io; import 'package:analysis_server_client/protocol.dart' hide AnalysisError; import 'package:intl/intl.dart'; +import 'package:meta/meta.dart'; import 'package:path/path.dart' as path; import '../analysis_server.dart'; @@ -220,15 +221,22 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed } try { var expectedCode = expectFile.readAsStringSync(); - var actualCode = - fileContentCache[filePath] ?? originalFile.readAsStringSync(); + var actualIsOriginal = !fileContentCache.containsKey(filePath); + var actualCode = actualIsOriginal + ? originalFile.readAsStringSync() + : fileContentCache[filePath]; // Use a whitespace insensitive comparison. if (_compressWhitespace(actualCode) != _compressWhitespace(expectedCode)) { result.failCount++; // TODO(brianwilkerson) Do a better job of displaying the differences. // It's very hard to see the diff with large files. - _reportFailure(filePath, actualCode, expectedCode); + _reportFailure( + filePath, + actualCode, + expectedCode, + actualIsOriginal: actualIsOriginal, + ); } else { result.passCount++; } @@ -314,12 +322,17 @@ To use the tool, run either ['dart fix --dry-run'] for a preview of the proposed /// Report that the [actualCode] produced by applying fixes to the content of /// [filePath] did not match the [expectedCode]. - void _reportFailure(String filePath, String actualCode, String expectedCode) { + void _reportFailure(String filePath, String actualCode, String expectedCode, + {@required bool actualIsOriginal}) { log.stdout('Failed when applying fixes to $filePath'); log.stdout('Expected:'); log.stdout(expectedCode); log.stdout(''); - log.stdout('Actual:'); + if (actualIsOriginal) { + log.stdout('Actual (original code was unchanged):'); + } else { + log.stdout('Actual:'); + } log.stdout(actualCode); }