Skip to content

Commit 0083128

Browse files
MarkzipanCommit Queue
authored andcommitted
[tests] Using git diff over diff for stability in hot reload tests.
Change-Id: Icdbdf4c569fd8ab5de96560722ac62616185a751 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406224 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Mark Zhou <[email protected]>
1 parent 174ce40 commit 0083128

File tree

116 files changed

+20
-161
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

116 files changed

+20
-161
lines changed

pkg/dev_compiler/test/hot_reload_suite.dart

Lines changed: 7 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -584,9 +584,7 @@ abstract class HotReloadSuiteRunner {
584584
label: test.name);
585585
File.fromUri(previousTempUri).deleteSync();
586586
File.fromUri(currentTempUri).deleteSync();
587-
var (filteredDiffOutput, filteredCurrentDiff) =
588-
_filterLineDeltas(diffOutput, currentDiff);
589-
if (filteredDiffOutput != filteredCurrentDiff) {
587+
if (diffOutput != currentDiff) {
590588
reportDiffOutcome(
591589
test.name,
592590
currentEdit.fileUri,
@@ -906,47 +904,23 @@ abstract class HotReloadSuiteRunner {
906904
{String label = '', bool commented = true, bool trimHeaders = true}) {
907905
final file1Path = file1.toFilePath();
908906
final file2Path = file2.toFilePath();
909-
final diffArgs = [
910-
'-u',
911-
'--width=120',
912-
'--expand-tabs',
913-
file1Path,
914-
file2Path
915-
];
916-
_debugPrint("Running diff with 'diff ${diffArgs.join(' ')}'.",
907+
final diffArgs = ['diff', '-u', file1Path, file2Path];
908+
_debugPrint("Running diff with 'git diff ${diffArgs.join(' ')}'.",
917909
label: label);
918-
final diffProcess = Process.runSync('diff', diffArgs);
910+
final diffProcess = Process.runSync('git', diffArgs);
919911
final errOutput = diffProcess.stderr as String;
920912
if (errOutput.isNotEmpty) {
921-
throw Exception('diff failed with:\n$errOutput');
913+
throw Exception('git diff failed with:\n$errOutput');
922914
}
923915
var output = diffProcess.stdout as String;
924916
if (trimHeaders) {
925-
// Skip the first two lines.
917+
// Skip the diff header. 'git diff' has 5 lines in its header.
926918
// TODO(markzipan): Add support for Windows-style line endings.
927-
output = output.split('\n').skip(2).join('\n');
919+
output = output.split('\n').skip(5).join('\n');
928920
}
929921
return commented ? '$testDiffSeparator\n/*\n$output*/' : output;
930922
}
931923

932-
/// Removes diff lines that show added or removed newlines.
933-
///
934-
/// 'diff' can be unstable across platforms around newline offsets.
935-
(String, String) _filterLineDeltas(String diff1, String diff2) {
936-
bool isBlankLineOrDelta(String s) {
937-
var trimmed = s.trim();
938-
return trimmed.isEmpty ||
939-
(trimmed.startsWith('+') || trimmed.startsWith('-')) &&
940-
trimmed.length == 1;
941-
}
942-
943-
var diff1Lines = LineSplitter().convert(diff1)
944-
..removeWhere(isBlankLineOrDelta);
945-
var diff2Lines = LineSplitter().convert(diff2)
946-
..removeWhere(isBlankLineOrDelta);
947-
return (diff1Lines.join('\n'), diff2Lines.join('\n'));
948-
}
949-
950924
/// Returns the code and diff portions of [file] with all leading and trailing
951925
/// whitespace trimmed.
952926
(String, String) _splitTestByDiff(Uri file) {

tests/hot_reload/add_library_imports/main.1.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ Future<void> main() async {
2121

2222
/** DIFF **/
2323
/*
24-
@@ -2,12 +2,15 @@
2524
import 'package:reload_test/reload_test_utils.dart';
2625
2726
import 'dart:math';

tests/hot_reload/add_new_static_field/main.1.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Future<void> main() async {
2828

2929
/** DIFF **/
3030
/*
31-
@@ -8,10 +8,12 @@
3231
// Adapted from:
3332
// https://github.com/dart-lang/sdk/blob/a70adce28e53ff8bb3445fe96f3f1be951d8a417/runtime/vm/isolate_reload_test.cc#L5423
3433

tests/hot_reload/bad_class/main.1.reject.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ Future<void> main() async {
2424

2525
/** DIFF **/
2626
/*
27-
@@ -9,7 +9,7 @@
2827
// https://github.com/dart-lang/sdk/blob/36c0788137d55c6c77f4b9a8be12e557bc764b1c/runtime/vm/isolate_reload_test.cc#L364
2928
3029
class Foo {

tests/hot_reload/call_deleted_top_level_function/main.1.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Future<void> main() async {
3131

3232
/** DIFF **/
3333
/*
34-
@@ -8,15 +8,14 @@
3534
// Adapted from:
3635
// https://github.com/dart-lang/sdk/blob/bf2fba78e006ce4feac43e514c0b8f3ea9e9fbb8/runtime/vm/isolate_reload_test.cc#L2597
3736

tests/hot_reload/call_deleted_top_level_function_arity_change/main.1.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ Future<void> main() async {
3535

3636
/** DIFF **/
3737
/*
38-
@@ -8,15 +8,18 @@
3938
// Adapted from:
4039
// https://github.com/dart-lang/sdk/blob/bf2fba78e006ce4feac43e514c0b8f3ea9e9fbb8/runtime/vm/isolate_reload_test.cc#L2627
4140

tests/hot_reload/class_added/main.1.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ Future<void> main() async {
2525

2626
/** DIFF **/
2727
/*
28-
@@ -9,7 +9,11 @@
2928
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L561
3029
3130
helper() {

tests/hot_reload/class_field_added/main.1.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Future<void> main() async {
3030

3131
/** DIFF **/
3232
/*
33-
@@ -10,6 +10,7 @@
3433
3534
class Foo {
3635
var x;

tests/hot_reload/class_field_added/main.2.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ Future<void> main() async {
3131

3232
/** DIFF **/
3333
/*
34-
@@ -11,6 +11,7 @@
3534
class Foo {
3635
var x;
3736
var y;

tests/hot_reload/class_field_removed/main.1.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Future<void> main() async {
3030

3131
/** DIFF **/
3232
/*
33-
@@ -11,7 +11,6 @@
3433
class Foo {
3534
var x;
3635
var y;

0 commit comments

Comments
 (0)