Skip to content

Commit b6778c9

Browse files
MarkzipanCommit Queue
authored andcommitted
[test] Porting mixin hot reload tests.
Change-Id: Ie9aedb99878cf4adb40949e8127c6e254dba1162 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406061 Reviewed-by: Nate Biggs <[email protected]> Commit-Queue: Mark Zhou <[email protected]>
1 parent 6590bb4 commit b6778c9

File tree

5 files changed

+149
-0
lines changed

5 files changed

+149
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
mixin ImportedMixin {
6+
mixinFunc() => 'mixin';
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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 'lib.dart' show ImportedMixin;
6+
import 'package:expect/expect.dart';
7+
import 'package:reload_test/reload_test_utils.dart';
8+
9+
// Adapted from:
10+
// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L1222
11+
12+
// Verifies that we assign the correct patch classes for imported
13+
// mixins when we reload.
14+
15+
class A extends Object with ImportedMixin {}
16+
17+
var func = new A().mixinFunc;
18+
19+
Future<void> main() async {
20+
Expect.equals('mixin', func());
21+
await hotReload();
22+
Expect.equals('mixin', func());
23+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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 'lib.dart' show ImportedMixin;
6+
import 'package:expect/expect.dart';
7+
import 'package:reload_test/reload_test_utils.dart';
8+
9+
// Adapted from:
10+
// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L1222
11+
12+
// Verifies that we assign the correct patch classes for imported
13+
// mixins when we reload.
14+
15+
class A extends Object with ImportedMixin {}
16+
17+
var func;
18+
19+
Future<void> main() async {
20+
Expect.equals('mixin', func());
21+
await hotReload();
22+
Expect.equals('mixin', func());
23+
}
24+
25+
/** DIFF **/
26+
/*
27+
@@ -14,7 +14,7 @@
28+
29+
class A extends Object with ImportedMixin {}
30+
31+
-var func = new A().mixinFunc;
32+
+var func;
33+
34+
Future<void> main() async {
35+
Expect.equals('mixin', func());
36+
*/
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/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L917
10+
11+
mixin Mixin1 {
12+
var field = 'mixin1';
13+
func() => 'mixin1';
14+
}
15+
16+
class B extends Object with Mixin1 {}
17+
18+
Future<void> main() async {
19+
var saved = B();
20+
Expect.equals('mixin1', saved.field);
21+
Expect.equals('mixin1', saved.func());
22+
await hotReload();
23+
24+
// The saved instance of B retains its old field value from mixin1,
25+
// but it gets the new implementation of func from mixin2.
26+
var newer = B();
27+
Expect.equals('mixin1', saved.field);
28+
Expect.equals('mixin2', saved.func());
29+
Expect.equals('mixin2', newer.field);
30+
Expect.equals('mixin2', newer.func());
31+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L917
10+
11+
mixin Mixin2 {
12+
var field = 'mixin2';
13+
func() => 'mixin2';
14+
}
15+
16+
class B extends Object with Mixin2 {}
17+
18+
Future<void> main() async {
19+
var saved = B();
20+
Expect.equals('mixin1', saved.field);
21+
Expect.equals('mixin1', saved.func());
22+
await hotReload();
23+
24+
// The saved instance of B retains its old field value from mixin1,
25+
// but it gets the new implementation of func from mixin2.
26+
var newer = B();
27+
Expect.equals('mixin1', saved.field);
28+
Expect.equals('mixin2', saved.func());
29+
Expect.equals('mixin2', newer.field);
30+
Expect.equals('mixin2', newer.func());
31+
}
32+
33+
/** DIFF **/
34+
/*
35+
@@ -8,12 +8,12 @@
36+
// Adapted from:
37+
// https://github.com/dart-lang/sdk/blob/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L917
38+
39+
-mixin Mixin1 {
40+
- var field = 'mixin1';
41+
- func() => 'mixin1';
42+
+mixin Mixin2 {
43+
+ var field = 'mixin2';
44+
+ func() => 'mixin2';
45+
}
46+
47+
-class B extends Object with Mixin1 {}
48+
+class B extends Object with Mixin2 {}
49+
50+
Future<void> main() async {
51+
var saved = B();
52+
*/

0 commit comments

Comments
 (0)