Skip to content

Commit a647f0e

Browse files
MarkzipanCommit Queue
authored and
Commit Queue
committed
[tests] Porting top level deleted member tests to the hot reload framework
Change-Id: Ic3561614b75b63556ea91b5a4dd75421cc5d3d5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/411084 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Mark Zhou <[email protected]>
1 parent a039f88 commit a647f0e

File tree

23 files changed

+589
-50
lines changed

23 files changed

+589
-50
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2704
10+
11+
var retained;
12+
13+
deleted() {
14+
return 'hello';
15+
}
16+
17+
helper() {
18+
retained = () => deleted();
19+
return retained();
20+
}
21+
22+
Future<void> main() async {
23+
Expect.equals('hello', helper());
24+
await hotReload();
25+
26+
Expect.equals('hello', helper());
27+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2704
10+
11+
var retained;
12+
13+
deleted<A, B, C>() {
14+
return 'hello';
15+
}
16+
17+
helper() {
18+
return retained();
19+
}
20+
21+
Future<void> main() async {
22+
Expect.equals('hello', helper());
23+
await hotReload();
24+
25+
Expect.equals('hello', helper());
26+
}
27+
28+
/** DIFF **/
29+
/*
30+
31+
var retained;
32+
33+
-deleted() {
34+
+deleted<A, B, C>() {
35+
return 'hello';
36+
}
37+
38+
helper() {
39+
- retained = () => deleted();
40+
return retained();
41+
}
42+
43+
*/

tests/hot_reload/call_deleted_top_level_function/config.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/hot_reload/call_deleted_top_level_function/main.0.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ helper() {
2121

2222
Future<void> main() async {
2323
Expect.equals('hello', helper());
24-
Expect.equals(0, hotReloadGeneration);
25-
2624
await hotReload();
2725

28-
Expect.contains('NoSuchMethodError', helper());
29-
Expect.contains('deleted', helper());
30-
Expect.equals(1, hotReloadGeneration);
26+
Expect.throws<NoSuchMethodError>(
27+
helper,
28+
(error) => error.toString().contains('deleted'),
29+
);
3130
}

tests/hot_reload/call_deleted_top_level_function/main.1.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,17 @@ import 'package:reload_test/reload_test_utils.dart';
1111
var retained;
1212

1313
helper() {
14-
try {
15-
return retained();
16-
} catch (e) {
17-
return e.toString();
18-
}
14+
return retained();
1915
}
2016

2117
Future<void> main() async {
2218
Expect.equals('hello', helper());
23-
Expect.equals(0, hotReloadGeneration);
24-
2519
await hotReload();
2620

27-
Expect.contains('NoSuchMethodError', helper());
28-
Expect.contains('deleted', helper());
29-
Expect.equals(1, hotReloadGeneration);
21+
Expect.throws<NoSuchMethodError>(
22+
helper,
23+
(error) => error.toString().contains('deleted'),
24+
);
3025
}
3126

3227
/** DIFF **/
@@ -42,13 +37,7 @@ Future<void> main() async {
4237
4338
helper() {
4439
- retained = () => deleted();
45-
- return retained();
46-
+ try {
47-
+ return retained();
48-
+ } catch (e) {
49-
+ return e.toString();
50-
+ }
40+
return retained();
5141
}
5242
53-
Future<void> main() async {
5443
*/

tests/hot_reload/call_deleted_top_level_function_arity_change/config.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/hot_reload/call_deleted_top_level_function_arity_change/main.0.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ helper() {
2121

2222
Future<void> main() async {
2323
Expect.equals('hello', helper());
24-
Expect.equals(0, hotReloadGeneration);
25-
2624
await hotReload();
2725

28-
Expect.contains('NoSuchMethodError', helper());
29-
Expect.contains('deleted', helper());
30-
Expect.equals(1, hotReloadGeneration);
26+
Expect.throws<NoSuchMethodError>(
27+
helper,
28+
(error) => error.toString().contains('deleted'),
29+
);
3130
}

tests/hot_reload/call_deleted_top_level_function_arity_change/main.1.dart

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,17 @@ deleted(newParameter) {
1515
var retained;
1616

1717
helper() {
18-
try {
19-
return retained();
20-
} catch (e) {
21-
return e.toString();
22-
}
18+
return retained();
2319
}
2420

2521
Future<void> main() async {
2622
Expect.equals('hello', helper());
27-
Expect.equals(0, hotReloadGeneration);
28-
2923
await hotReload();
3024

31-
Expect.contains('NoSuchMethodError', helper());
32-
Expect.contains('deleted', helper());
33-
Expect.equals(1, hotReloadGeneration);
25+
Expect.throws<NoSuchMethodError>(
26+
helper,
27+
(error) => error.toString().contains('deleted'),
28+
);
3429
}
3530

3631
/** DIFF **/
@@ -47,13 +42,7 @@ Future<void> main() async {
4742
4843
helper() {
4944
- retained = () => deleted();
50-
- return retained();
51-
+ try {
52-
+ return retained();
53-
+ } catch (e) {
54-
+ return e.toString();
55-
+ }
45+
return retained();
5646
}
5747
58-
Future<void> main() async {
5948
*/
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2794
10+
11+
var retained;
12+
first(flag) {
13+
if (flag) throw 'first!';
14+
}
15+
16+
deleted(_) {
17+
return 'hello';
18+
}
19+
20+
helper() {
21+
retained = (bool flag) => deleted(first(flag));
22+
return retained(false);
23+
}
24+
25+
Future<void> main() async {
26+
Expect.equals('hello', helper());
27+
await hotReload();
28+
29+
Expect.throws(helper, (error) => error.toString().contains('first!'));
30+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2794
10+
11+
var retained;
12+
first(flag) {
13+
if (flag) throw 'first!';
14+
}
15+
16+
helper() {
17+
return retained(true);
18+
}
19+
20+
Future<void> main() async {
21+
Expect.equals('hello', helper());
22+
await hotReload();
23+
24+
Expect.throws(helper, (error) => error.toString().contains('first!'));
25+
}
26+
27+
/** DIFF **/
28+
/*
29+
if (flag) throw 'first!';
30+
}
31+
32+
-deleted(_) {
33+
- return 'hello';
34+
-}
35+
-
36+
helper() {
37+
- retained = (bool flag) => deleted(first(flag));
38+
- return retained(false);
39+
+ return retained(true);
40+
}
41+
42+
Future<void> main() async {
43+
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2825
10+
11+
import 'test-lib.dart';
12+
13+
var retained;
14+
helper() {
15+
retained = () => deleted();
16+
return retained();
17+
}
18+
19+
Future<void> main() async {
20+
Expect.equals('hello', helper());
21+
await hotReload();
22+
23+
// VM: What actually happens because we don't re-search imported libraries.
24+
Expect.equals('hello', helper());
25+
26+
// VM: What should happen and what did happen with the old VM frontend:
27+
// Expect.throws<NoSuchMethodError>(
28+
// helper,
29+
// (error) => error.toString().contains('deleted'),
30+
// );
31+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2825
10+
11+
var retained;
12+
helper() {
13+
return retained();
14+
}
15+
16+
Future<void> main() async {
17+
Expect.equals('hello', helper());
18+
await hotReload();
19+
20+
// VM: What actually happens because we don't re-search imported libraries.
21+
Expect.equals('hello', helper());
22+
23+
// VM: What should happen and what did happen with the old VM frontend:
24+
// Expect.throws<NoSuchMethodError>(
25+
// helper,
26+
// (error) => error.toString().contains('deleted'),
27+
// );
28+
}
29+
30+
/** DIFF **/
31+
/*
32+
// Adapted from:
33+
// https://github.com/dart-lang/sdk/blob/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2825
34+
35+
-import 'test-lib.dart';
36+
-
37+
var retained;
38+
helper() {
39+
- retained = () => deleted();
40+
return retained();
41+
}
42+
43+
*/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
deleted() {
2+
return 'hello';
3+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L2889
10+
11+
var retained;
12+
get deleted {
13+
return 'hello';
14+
}
15+
16+
helper() {
17+
retained = () => deleted;
18+
return retained();
19+
}
20+
21+
Future<void> main() async {
22+
Expect.equals('hello', helper());
23+
await hotReload();
24+
25+
Expect.throws<NoSuchMethodError>(
26+
helper,
27+
(error) => error.toString().contains('deleted'),
28+
);
29+
}

0 commit comments

Comments
 (0)