mirror of
https://github.com/dart-lang/sdk
synced 2024-09-04 16:03:44 +00:00
[reload_test] Adding diffs to existing tests.
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>
This commit is contained in:
parent
09f523fbb5
commit
6357371c0a
|
@ -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) {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
@ -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) {
|
||||
*/
|
||||
|
|
|
@ -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> {
|
||||
*/
|
||||
|
|
|
@ -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.');
|
||||
});
|
||||
|
||||
*/
|
||||
|
|
|
@ -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.');
|
||||
});
|
||||
|
||||
*/
|
||||
|
|
|
@ -1 +1,7 @@
|
|||
get line => "part3";
|
||||
/** DIFF **/
|
||||
/*
|
||||
@@ -1 +1 @@
|
||||
-get line => "part1";
|
||||
+get line => "part3";
|
||||
*/
|
||||
|
|
|
@ -1 +1,7 @@
|
|||
get line => "part5";
|
||||
/** DIFF **/
|
||||
/*
|
||||
@@ -1 +1 @@
|
||||
-get line => "part3";
|
||||
+get line => "part5";
|
||||
*/
|
||||
|
|
|
@ -1 +1,7 @@
|
|||
get line => "part4";
|
||||
/** DIFF **/
|
||||
/*
|
||||
@@ -1 +1 @@
|
||||
-get line => "part5";
|
||||
+get line => "part4";
|
||||
*/
|
||||
|
|
|
@ -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");
|
||||
*/
|
||||
|
|
|
@ -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});
|
||||
}
|
||||
|
||||
*/
|
||||
|
|
|
@ -53,3 +53,6 @@ Future<void> main() async {
|
|||
Expect.equals('ac', topLevel);
|
||||
Expect.equals(5, hotReloadGeneration);
|
||||
}
|
||||
/** DIFF **/
|
||||
/*
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -53,3 +53,6 @@ Future<void> main() async {
|
|||
Expect.equals('ac', topLevel);
|
||||
Expect.equals(5, hotReloadGeneration);
|
||||
}
|
||||
/** DIFF **/
|
||||
/*
|
||||
*/
|
||||
|
|
|
@ -53,3 +53,6 @@ Future<void> main() async {
|
|||
Expect.equals('ac', topLevel);
|
||||
Expect.equals(5, hotReloadGeneration);
|
||||
}
|
||||
/** DIFF **/
|
||||
/*
|
||||
*/
|
||||
|
|
|
@ -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);
|
||||
*/
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
|
@ -26,3 +26,14 @@ Future<void> main() async {
|
|||
Expect.equals(3, hotReloadGeneration);
|
||||
Expect.equals("before", value);
|
||||
}
|
||||
/** DIFF **/
|
||||
/*
|
||||
@@ -17,6 +17,7 @@
|
||||
await hotReload();
|
||||
|
||||
// The lazy static is now read and contains the updated value.
|
||||
+ print(value);
|
||||
Expect.equals(2, hotReloadGeneration);
|
||||
Expect.equals("before", value);
|
||||
await hotReload();
|
||||
*/
|
||||
|
|
|
@ -25,3 +25,23 @@ 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 = "before";
|
||||
+var value = "after";
|
||||
|
||||
Future<void> main() async {
|
||||
// Declare an unreferenced lazy static field.
|
||||
@@ -17,7 +17,6 @@
|
||||
await hotReload();
|
||||
|
||||
// The lazy static is now read and contains the updated value.
|
||||
- print(value);
|
||||
Expect.equals(2, hotReloadGeneration);
|
||||
Expect.equals("before", value);
|
||||
await hotReload();
|
||||
*/
|
||||
|
|
|
@ -34,3 +34,31 @@ Future<void> main() async {
|
|||
await hotReload();
|
||||
validate();
|
||||
}
|
||||
/** DIFF **/
|
||||
/*
|
||||
@@ -12,18 +12,21 @@
|
||||
|
||||
class Foo {
|
||||
int x = 4;
|
||||
+ int y = myInitialValue++;
|
||||
}
|
||||
|
||||
late Foo value;
|
||||
late Foo value1;
|
||||
|
||||
void validate() {
|
||||
- Expect.equals(0, hotReloadGeneration);
|
||||
- value = Foo();
|
||||
- value1 = Foo();
|
||||
+ // Add field 'y' with side effects and verify that initializers ran lazily.
|
||||
+ Expect.equals(1, hotReloadGeneration);
|
||||
Expect.equals(4, value.x);
|
||||
Expect.equals(4, value1.x);
|
||||
Expect.equals(56, myInitialValue);
|
||||
+ Expect.equals(56, value.y);
|
||||
+ Expect.equals(57, value1.y);
|
||||
+ Expect.equals(58, myInitialValue);
|
||||
}
|
||||
|
||||
Future<void> main() async {
|
||||
*/
|
||||
|
|
|
@ -45,3 +45,6 @@ Future<void> main() async {
|
|||
|
||||
await periodicTimerDone.future;
|
||||
}
|
||||
/** DIFF **/
|
||||
/*
|
||||
*/
|
||||
|
|
|
@ -45,3 +45,6 @@ Future<void> main() async {
|
|||
|
||||
await periodicTimerDone.future;
|
||||
}
|
||||
/** DIFF **/
|
||||
/*
|
||||
*/
|
||||
|
|
Loading…
Reference in a new issue