Skip to content

Commit

Permalink
[reload_test] Adding diffs to existing tests.
Browse files Browse the repository at this point in the history
Change-Id: Icf7135ae46159ca834a54849c72405eec83f9b4f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364384
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
  • Loading branch information
Markzipan authored and Commit Queue committed Apr 26, 2024
1 parent 09f523f commit 6357371
Show file tree
Hide file tree
Showing 25 changed files with 338 additions and 12 deletions.
39 changes: 27 additions & 12 deletions pkg/dev_compiler/test/hot_reload_suite.dart
Expand Up @@ -268,7 +268,14 @@ Future<void> main(List<String> args) async {
throw Exception('Too many generations specified in test '
'(requested: $maxGenerations, max: $globalMaxGenerations).');
}
switch (argResults['diff']) {

var diffMode = argResults['diff']!;
if (fe_shared.isWindows && diffMode != 'ignore') {
_print("Diffing isn't supported on Windows. Defaulting to 'ignore'.",
label: testName);
diffMode = 'ignore';
}
switch (diffMode) {
case 'check':
_print('Checking source file diffs.', label: testName);
filesByGeneration.forEach((basename, filesQueue) {
Expand Down Expand Up @@ -701,26 +708,32 @@ void _debugPrint(String message, {String? label}) {
///
/// If [commented] is set, the output will be wrapped in multiline comments
/// and the diff separator.
///
/// If [trimHeaders] is set, the leading '+++' and '---' file headers will be
/// removed.
String _diffWithFileUris(Uri file1, Uri file2,
{String label = '', bool commented = true}) {
{String label = '', bool commented = true, bool trimHeaders = true}) {
final file1Path = file1.toFilePath();
final file2Path = file2.toFilePath();
_debugPrint(
"Running diff with 'diff -dy --suppress-common-lines"
" --expand-tabs $file1Path $file2Path'.",
label: label);
final diffProcess = Process.runSync('diff', [
'-dy',
'--suppress-common-lines',
final diffArgs = [
'-du',
'--width=120',
'--expand-tabs',
file1Path,
file2Path
]);
];
_debugPrint("Running diff with 'diff ${diffArgs.join(' ')}'.", label: label);
final diffProcess = Process.runSync('diff', diffArgs);
final errOutput = diffProcess.stderr as String;
if (errOutput.isNotEmpty) {
throw Exception('diff failed with:\n$errOutput');
}
final output = diffProcess.stdout as String;
var output = diffProcess.stdout as String;
if (trimHeaders) {
// Skip the first two lines.
// TODO(markzipan): Add support for Windows-style line endings.
output = output.split('\n').skip(2).join('\n');
}
return commented ? '$testDiffSeparator\n/*\n$output*/' : output;
}

Expand All @@ -731,7 +744,9 @@ String _diffWithFileUris(Uri file1, Uri file2,
final diffSplitIndex = diffIndex == -1 ? text.length - 1 : diffIndex;
final codeText = text.substring(0, diffSplitIndex);
final diffText = text.substring(diffSplitIndex, text.length - 1);
return (codeText, diffText);
// Avoid 'No newline at end of file' messages in the output by appending a
// newline if one is not already trailing.
return ('$codeText${codeText.endsWith('\n') ? '' : '\n'}', diffText);
}

abstract class HotReloadSuiteRunner {
Expand Down
21 changes: 21 additions & 0 deletions tests/hot_reload/add_library_imports/main.1.dart
Expand Up @@ -18,3 +18,24 @@ Future<void> main() async {
await hotReload();
validate();
}
/** DIFF **/
/*
@@ -2,12 +2,15 @@
import 'package:reload_test/reload_test_utils.dart';
import 'dart:math';
+import 'dart:convert';
void validate() {
- // Initial program is valid. Symbols in 'dart:math' are visible.
- Expect.equals(0, hotReloadGeneration);
+ // Symbols in 'dart:convert' are visible after hot reload.
+ Expect.equals(1, hotReloadGeneration);
Expect.equals(e, 2.718281828459045);
Expect.type<double>(e);
+ Expect.type<Codec>(utf8);
+ Expect.type<Function>(jsonEncode);
}
Future<void> main() async {
*/
12 changes: 12 additions & 0 deletions tests/hot_reload/bad_class/main.1.dart
Expand Up @@ -19,3 +19,15 @@ Future<void> main() async {
await hotReload();
throw Exception('This should never run.');
}
/** DIFF **/
/*
@@ -9,7 +9,7 @@
// https://github.com/dart-lang/sdk/blob/36c0788137d55c6c77f4b9a8be12e557bc764b1c/runtime/vm/isolate_reload_test.cc#L364
class Foo {
- final a;
+ final a kjsdf ksjdf;
Foo(this.a);
}
*/
12 changes: 12 additions & 0 deletions tests/hot_reload/compile_base_class/lib.1.dart
Expand Up @@ -10,3 +10,15 @@ class State<U, T> {
u = l[1] is U ? l[1] : null;
}
}
/** DIFF **/
/*
@@ -2,7 +2,7 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
-class State<T, U> {
+class State<U, T> {
T? t;
U? u;
State(List l) {
*/
12 changes: 12 additions & 0 deletions tests/hot_reload/compile_generics/main.1.dart
Expand Up @@ -26,3 +26,15 @@ Future<void> main() async {
balance = (MyAccountState(Account())).howAreTheThings().balance();
Expect.equals(24, balance);
}
/** DIFF **/
/*
@@ -11,7 +11,7 @@
// https://github.com/dart-lang/sdk/blob/36c0788137d55c6c77f4b9a8be12e557bc764b1c/runtime/vm/isolate_reload_test.cc#L204
class Account {
- int balance() => 42;
+ int balance() => 24;
}
class MyAccountState extends State<Account> {
*/
37 changes: 37 additions & 0 deletions tests/hot_reload/framework_timing_test/main.1.dart
Expand Up @@ -31,3 +31,40 @@ void main() {

hotRestart();
}
/** DIFF **/
/*
@@ -7,25 +7,25 @@
import 'package:expect/expect.dart';
import 'package:reload_test/reload_test_utils.dart';
-var x = 'Hello World';
+var x = 'Hello Foo';
void main() {
- Expect.equals('Hello World', x);
- Expect.equals(0, hotRestartGeneration);
+ Expect.equals('Hello Foo', x);
+ Expect.equals(1, hotRestartGeneration);
scheduleMicrotask(() {
- Expect.equals(0, hotRestartGeneration);
+ Expect.equals(1, hotRestartGeneration);
});
Future<Null>.microtask(() {
throw x;
}).catchError((e, stackTrace) {
- Expect.equals("Hello World", e);
- Expect.equals(0, hotRestartGeneration);
+ Expect.equals("Hello Foo", e);
+ Expect.equals(1, hotRestartGeneration);
}).then((_) {
- Expect.equals(0, hotRestartGeneration);
+ Expect.equals(1, hotRestartGeneration);
});
Future.delayed(Duration(seconds: 5), () {
- throw Exception('Future from main.0.dart before hot restart. '
+ throw Exception('Future from main.1.dart before hot restart. '
'This should never run.');
});
*/
37 changes: 37 additions & 0 deletions tests/hot_reload/framework_timing_test/main.2.dart
Expand Up @@ -31,3 +31,40 @@ void main() {

hotRestart();
}
/** DIFF **/
/*
@@ -7,25 +7,25 @@
import 'package:expect/expect.dart';
import 'package:reload_test/reload_test_utils.dart';
-var x = 'Hello Foo';
+var x = 'Hello Bar';
void main() {
- Expect.equals('Hello Foo', x);
- Expect.equals(1, hotRestartGeneration);
+ Expect.equals('Hello Bar', x);
+ Expect.equals(2, hotRestartGeneration);
scheduleMicrotask(() {
- Expect.equals(1, hotRestartGeneration);
+ Expect.equals(2, hotRestartGeneration);
});
Future<Null>.microtask(() {
throw x;
}).catchError((e, stackTrace) {
- Expect.equals("Hello Foo", e);
- Expect.equals(1, hotRestartGeneration);
+ Expect.equals("Hello Bar", e);
+ Expect.equals(2, hotRestartGeneration);
}).then((_) {
- Expect.equals(1, hotRestartGeneration);
+ Expect.equals(2, hotRestartGeneration);
});
Future.delayed(Duration(seconds: 5), () {
- throw Exception('Future from main.1.dart before hot restart. '
+ throw Exception('Future from main.2.dart before hot restart. '
'This should never run.');
});
*/
6 changes: 6 additions & 0 deletions tests/hot_reload/general_test/b.1.dart
@@ -1 +1,7 @@
get line => "part3";
/** DIFF **/
/*
@@ -1 +1 @@
-get line => "part1";
+get line => "part3";
*/
6 changes: 6 additions & 0 deletions tests/hot_reload/general_test/b.3.dart
@@ -1 +1,7 @@
get line => "part5";
/** DIFF **/
/*
@@ -1 +1 @@
-get line => "part3";
+get line => "part5";
*/
6 changes: 6 additions & 0 deletions tests/hot_reload/general_test/b.4.dart
@@ -1 +1,7 @@
get line => "part4";
/** DIFF **/
/*
@@ -1 +1 @@
-get line => "part5";
+get line => "part4";
*/
15 changes: 15 additions & 0 deletions tests/hot_reload/general_test/c.4.dart
Expand Up @@ -8,3 +8,18 @@ class B {
}

var bField = B(a: (String s) => "$s");
/** DIFF **/
/*
@@ -1 +1,10 @@
-String g() => "";
+String g() {
+ return bField.a("a");
+}
+
+class B {
+ dynamic a;
+ B({this.a});
+}
+
+var bField = B(a: (String s) => "$s");
*/
15 changes: 15 additions & 0 deletions tests/hot_reload/general_test/c.5.dart
Expand Up @@ -9,3 +9,18 @@ class B {
}

var bField = B(a: (String s) => "$s");
/** DIFF **/
/*
@@ -1,9 +1,10 @@
String g() {
- return bField.a("a");
+ return bField.a("a") + (bField.b ?? "c");
}
class B {
dynamic a;
+ dynamic b;
B({this.a});
}
*/
3 changes: 3 additions & 0 deletions tests/hot_reload/general_test/main.1.dart
Expand Up @@ -53,3 +53,6 @@ Future<void> main() async {
Expect.equals('ac', topLevel);
Expect.equals(5, hotReloadGeneration);
}
/** DIFF **/
/*
*/
12 changes: 12 additions & 0 deletions tests/hot_reload/general_test/main.2.dart
Expand Up @@ -53,3 +53,15 @@ Future<void> main() async {
Expect.equals('ac', topLevel);
Expect.equals(5, hotReloadGeneration);
}
/** DIFF **/
/*
@@ -11,7 +11,7 @@
import 'b.dart';
import 'c.dart';
-f() => "$line part2";
+f() => "$line part4";
Future<void> main() async {
// Initial program is valid.
*/
12 changes: 12 additions & 0 deletions tests/hot_reload/general_test/main.3.dart
Expand Up @@ -53,3 +53,15 @@ Future<void> main() async {
Expect.equals('ac', topLevel);
Expect.equals(5, hotReloadGeneration);
}
/** DIFF **/
/*
@@ -11,7 +11,7 @@
import 'b.dart';
import 'c.dart';
-f() => "$line part4";
+f() => "$line part6";
Future<void> main() async {
// Initial program is valid.
*/
3 changes: 3 additions & 0 deletions tests/hot_reload/general_test/main.4.dart
Expand Up @@ -53,3 +53,6 @@ Future<void> main() async {
Expect.equals('ac', topLevel);
Expect.equals(5, hotReloadGeneration);
}
/** DIFF **/
/*
*/
3 changes: 3 additions & 0 deletions tests/hot_reload/general_test/main.5.dart
Expand Up @@ -53,3 +53,6 @@ Future<void> main() async {
Expect.equals('ac', topLevel);
Expect.equals(5, hotReloadGeneration);
}
/** DIFF **/
/*
*/
10 changes: 10 additions & 0 deletions tests/hot_reload/hot_restart_constant_equality/library_b.1.dart
Expand Up @@ -6,3 +6,13 @@ import 'library_a.dart';

int variableToModifyToForceRecompile = 45;
B get value2 => const B(2);
/** DIFF **/
/*
@@ -4,5 +4,5 @@
import 'library_a.dart';
-int variableToModifyToForceRecompile = 23;
+int variableToModifyToForceRecompile = 45;
B get value2 => const B(2);
*/
12 changes: 12 additions & 0 deletions tests/hot_reload/hot_restart_constant_equality/main.1.dart
Expand Up @@ -31,3 +31,15 @@ void main() {
Expect.equals('ConstObject(reloadVariable: 45, ConstantEqualitySuccess)',
'${const ConstObject().text}');
}
/** DIFF **/
/*
@@ -28,7 +28,6 @@
}
void main() {
- Expect.equals('ConstObject(reloadVariable: 23, ConstantEqualitySuccess)',
+ Expect.equals('ConstObject(reloadVariable: 45, ConstantEqualitySuccess)',
'${const ConstObject().text}');
- hotRestart();
}
*/
12 changes: 12 additions & 0 deletions tests/hot_reload/lazy_static_initializers/main.1.dart
Expand Up @@ -25,3 +25,15 @@ Future<void> main() async {
Expect.equals(3, hotReloadGeneration);
Expect.equals("before", value);
}
/** DIFF **/
/*
@@ -5,7 +5,7 @@
import 'package:expect/expect.dart';
import 'package:reload_test/reload_test_utils.dart';
-var value = "unused";
+var value = "before";
Future<void> main() async {
// Declare an unreferenced lazy static field.
*/

0 comments on commit 6357371

Please sign in to comment.