Skip to content

Commit 0224206

Browse files
nshahanCommit Queue
authored andcommitted
[tests] Port const tests from vm hot reload suite
Change-Id: I8fedb4afe8f117e54aa17ff85e0415e818b2c62f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389583 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]> Reviewed-by: Mark Zhou <[email protected]>
1 parent 7969fc0 commit 0224206

File tree

19 files changed

+635
-0
lines changed

19 files changed

+635
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"expectedErrors": {
3+
"1": "Const class cannot become non-const: Library:'hot-reload-test:///main.dart' Class: A"
4+
}
5+
}
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:reload_test/reload_test_utils.dart';
6+
7+
// Adapted from:
8+
// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4569
9+
10+
void helper() {
11+
a = const A(1);
12+
}
13+
14+
class A {
15+
final dynamic x;
16+
const A(this.x);
17+
}
18+
19+
dynamic a;
20+
21+
Future<void> main() async {
22+
helper();
23+
await hotReload(expectRejection: true);
24+
helper();
25+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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:reload_test/reload_test_utils.dart';
6+
7+
// Adapted from:
8+
// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4569
9+
10+
void helper() {
11+
throw Exception('This should never run.');
12+
}
13+
14+
class A {
15+
dynamic x;
16+
A(this.x);
17+
}
18+
19+
dynamic a;
20+
21+
Future<void> main() async {
22+
helper();
23+
await hotReload(expectRejection: true);
24+
helper();
25+
}
26+
/** DIFF **/
27+
/*
28+
@@ -8,12 +8,12 @@
29+
// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4569
30+
31+
void helper() {
32+
- a = const A(1);
33+
+ throw Exception('This should never run.');
34+
}
35+
36+
class A {
37+
- final dynamic x;
38+
- const A(this.x);
39+
+ dynamic x;
40+
+ A(this.x);
41+
}
42+
43+
dynamic a;
44+
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"expectedErrors": {
3+
"1": "Const class cannot become non-const: Library:'hot-reload-test:///main.dart' Class: A"
4+
}
5+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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:reload_test/reload_test_utils.dart';
6+
7+
// Adapted from:
8+
// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4603
9+
10+
void helper() {
11+
a = const A();
12+
}
13+
14+
class A {
15+
const A();
16+
}
17+
18+
dynamic a;
19+
20+
Future<void> main() async {
21+
helper();
22+
await hotReload(expectRejection: true);
23+
helper();
24+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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:reload_test/reload_test_utils.dart';
6+
7+
// Adapted from:
8+
// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4603
9+
10+
void helper() {
11+
throw Exception('This should never run.');
12+
}
13+
14+
class A {
15+
dynamic x;
16+
A(this.x);
17+
}
18+
19+
dynamic a;
20+
21+
Future<void> main() async {
22+
helper();
23+
await hotReload(expectRejection: true);
24+
helper();
25+
}
26+
/** DIFF **/
27+
/*
28+
@@ -8,11 +8,12 @@
29+
// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4603
30+
31+
void helper() {
32+
- a = const A();
33+
+ throw Exception('This should never run.');
34+
}
35+
36+
class A {
37+
- const A();
38+
+ dynamic x;
39+
+ A(this.x);
40+
}
41+
42+
dynamic a;
43+
*/
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/26f2ff4f11f56841fc5a250231ef7d49f01eb234/runtime/vm/isolate_reload_test.cc#L2604
10+
11+
class Fruit {
12+
final String name;
13+
const Fruit(this.name);
14+
String toString() => name;
15+
}
16+
17+
var x;
18+
19+
Future<void> main() async {
20+
x = const Fruit('Pear');
21+
Expect.equals('Pear', x.toString());
22+
await hotReload();
23+
Expect.equals('Pear', x.toString());
24+
Expect.identical(x, const Fruit('Pear'));
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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/26f2ff4f11f56841fc5a250231ef7d49f01eb234/runtime/vm/isolate_reload_test.cc#L2604
10+
11+
class Fruit {
12+
final String name;
13+
const Fruit(this.name);
14+
String toString() => name;
15+
}
16+
17+
var x;
18+
19+
Future<void> main() async {
20+
x = const Fruit('Pear');
21+
Expect.equals('Pear', x.toString());
22+
await hotReload();
23+
Expect.equals('Pear', x.toString());
24+
Expect.identical(x, const Fruit('Pear'));
25+
}
26+
/** DIFF **/
27+
/*
28+
*/
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/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L5371
10+
11+
void helper() {
12+
throw Exception('This should never run.');
13+
}
14+
15+
class C {
16+
final x;
17+
const C(this.x);
18+
}
19+
20+
var a = const C(const C(1));
21+
var b = const C(const C(2));
22+
var c = const C(const C(3));
23+
var d = const C(const C(4));
24+
25+
class Foo {}
26+
27+
late Foo value;
28+
29+
Future<void> main() async {
30+
value = Foo();
31+
a;
32+
b;
33+
c;
34+
d;
35+
await hotReload();
36+
helper();
37+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L5371
10+
11+
void helper() {
12+
Expect.identical(a, value.a);
13+
Expect.identical(b, value.b);
14+
Expect.identical(c, value.c);
15+
Expect.identical(d, value.d);
16+
}
17+
18+
class C {
19+
final x;
20+
const C(this.x);
21+
}
22+
23+
var a = const C(const C(1));
24+
var b = const C(const C(2));
25+
var c = const C(const C(3));
26+
var d = const C(const C(4));
27+
28+
class Foo {
29+
var d = const C(const C(4));
30+
var c = const C(const C(3));
31+
var b = const C(const C(2));
32+
var a = const C(const C(1));
33+
}
34+
35+
late Foo value;
36+
37+
Future<void> main() async {
38+
value = Foo();
39+
a;
40+
b;
41+
c;
42+
d;
43+
await hotReload();
44+
helper();
45+
}
46+
/** DIFF **/
47+
/*
48+
@@ -9,7 +9,10 @@
49+
// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L5371
50+
51+
void helper() {
52+
- throw Exception('This should never run.');
53+
+ Expect.identical(a, value.a);
54+
+ Expect.identical(b, value.b);
55+
+ Expect.identical(c, value.c);
56+
+ Expect.identical(d, value.d);
57+
}
58+
59+
class C {
60+
@@ -22,7 +25,12 @@
61+
var c = const C(const C(3));
62+
var d = const C(const C(4));
63+
64+
-class Foo {}
65+
+class Foo {
66+
+ var d = const C(const C(4));
67+
+ var c = const C(const C(3));
68+
+ var b = const C(const C(2));
69+
+ var a = const C(const C(1));
70+
+}
71+
72+
late Foo value;
73+
74+
*/

0 commit comments

Comments
 (0)