Skip to content

Commit 9f00613

Browse files
MarkzipanCommit Queue
authored andcommitted
[test] Porting more VM hot reload tests.
Change-Id: I196cbd9bee6996c313285cce89f928e22b4804cf Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398929 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Mark Zhou <[email protected]>
1 parent c32c0b8 commit 9f00613

File tree

22 files changed

+659
-0
lines changed

22 files changed

+659
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L561
10+
11+
helper() {
12+
return 'hello';
13+
}
14+
15+
Future<void> main() async {
16+
Expect.equals('hello', helper());
17+
await hotReload();
18+
19+
Expect.equals('hello from A', helper());
20+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L561
10+
11+
helper() {
12+
return A().toString();
13+
}
14+
15+
class A {
16+
toString() => 'hello from A';
17+
}
18+
19+
Future<void> main() async {
20+
Expect.equals('hello', helper());
21+
await hotReload();
22+
23+
Expect.equals('hello from A', helper());
24+
}
25+
/** DIFF **/
26+
/*
27+
@@ -9,7 +9,11 @@
28+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L561
29+
30+
helper() {
31+
- return 'hello';
32+
+ return A().toString();
33+
+}
34+
+
35+
+class A {
36+
+ toString() => 'hello from A';
37+
}
38+
39+
Future<void> main() async {
40+
*/
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L585
10+
11+
class A {
12+
toString() => 'hello from A';
13+
}
14+
var list = <dynamic>[];
15+
helper() {
16+
list.add(A());
17+
return list[0].toString();
18+
}
19+
20+
Future<void> main() async {
21+
Expect.equals('hello from A', helper());
22+
await hotReload();
23+
24+
Expect.equals('hello from A', helper());
25+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L585
10+
11+
var list = <dynamic>[];
12+
helper() {
13+
return list[0].toString();
14+
}
15+
16+
Future<void> main() async {
17+
Expect.equals('hello from A', helper());
18+
await hotReload();
19+
20+
Expect.equals('hello from A', helper());
21+
}
22+
/** DIFF **/
23+
/*
24+
@@ -8,12 +8,8 @@
25+
// Adapted from:
26+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L585
27+
28+
-class A {
29+
- toString() => 'hello from A';
30+
-}
31+
var list = <dynamic>[];
32+
helper() {
33+
- list.add(A());
34+
return list[0].toString();
35+
}
36+
37+
*/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L723
10+
11+
class A {
12+
late int field;
13+
A() {
14+
field = 20;
15+
}
16+
}
17+
18+
var savedA = A();
19+
helper() {
20+
return A();
21+
}
22+
23+
Future<void> main() async {
24+
Expect.equals(20, savedA.field);
25+
Expect.equals(20, helper().field);
26+
await hotReload();
27+
28+
Expect.equals(20, savedA.field);
29+
Expect.equals(10, helper().field);
30+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L723
10+
11+
class A {
12+
late int field;
13+
A() {
14+
field = 10;
15+
}
16+
}
17+
18+
var savedA = A();
19+
helper() {
20+
return A();
21+
}
22+
23+
Future<void> main() async {
24+
Expect.equals(20, savedA.field);
25+
Expect.equals(20, helper().field);
26+
await hotReload();
27+
28+
Expect.equals(20, savedA.field);
29+
Expect.equals(10, helper().field);
30+
}
31+
/** DIFF **/
32+
/*
33+
@@ -11,7 +11,7 @@
34+
class A {
35+
late int field;
36+
A() {
37+
- field = 20;
38+
+ field = 10;
39+
}
40+
}
41+
42+
*/
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L4638
10+
// Regression test for https://github.com/dart-lang/sdk/issues/50148
11+
12+
typedef Create<T, R> = T Function(R ref);
13+
14+
class Base<Input> {
15+
Base(void Function(Create<void, Input> create) factory) : _factory = factory;
16+
17+
final void Function(Create<void, Input> create) _factory;
18+
19+
void fn() => _factory((ref) {});
20+
}
21+
22+
class Check<T> {
23+
Check(Create<Object?, List<T>> create);
24+
}
25+
26+
final f = Base<List<int>>(Check<int>.new);
27+
28+
helper() {
29+
f.fn();
30+
}
31+
32+
Future<void> main() async {
33+
helper();
34+
await hotReload();
35+
helper();
36+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L4638
10+
// Regression test for https://github.com/dart-lang/sdk/issues/50148
11+
12+
typedef Create<T, R> = T Function(R ref);
13+
14+
class Base<Input> {
15+
Base(void Function(Create<void, Input> create) factory) : _factory = factory;
16+
17+
final void Function(Create<void, Input> create) _factory;
18+
19+
void fn() => _factory((ref) {});
20+
}
21+
22+
class Check<T> {
23+
Check(Create<Object?, List<T>> create);
24+
}
25+
26+
final f = Base<List<int>>(Check<int>.new);
27+
28+
helper() {
29+
f.fn();
30+
}
31+
32+
Future<void> main() async {
33+
helper();
34+
await hotReload();
35+
helper();
36+
}
37+
/** DIFF **/
38+
/*
39+
*/
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L690
10+
11+
class A {
12+
int field = 20;
13+
}
14+
15+
var savedA = A();
16+
helper() {
17+
return A();
18+
}
19+
20+
Future<void> main() async {
21+
Expect.equals(20, savedA.field);
22+
Expect.equals(20, helper().field);
23+
await hotReload();
24+
25+
Expect.equals(20, savedA.field);
26+
Expect.equals(10, helper().field);
27+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:expect/expect.dart';
6+
import 'package:reload_test/reload_test_utils.dart';
7+
8+
// Adapted from:
9+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L690
10+
11+
class A {
12+
int field = 10;
13+
}
14+
15+
var savedA = A();
16+
helper() {
17+
return A();
18+
}
19+
20+
Future<void> main() async {
21+
Expect.equals(20, savedA.field);
22+
Expect.equals(20, helper().field);
23+
await hotReload();
24+
25+
Expect.equals(20, savedA.field);
26+
Expect.equals(10, helper().field);
27+
}
28+
/** DIFF **/
29+
/*
30+
@@ -9,7 +9,7 @@
31+
// https://github.com/dart-lang/sdk/blob/f34a2ed99fc1b34cedbd974a5801f8d922121126/runtime/vm/isolate_reload_test.cc#L690
32+
33+
class A {
34+
- int field = 20;
35+
+ int field = 10;
36+
}
37+
38+
var savedA = A();
39+
*/

0 commit comments

Comments
 (0)