diff --git a/tests/hot_reload/const_to_non_const_class/config.json b/tests/hot_reload/const_to_non_const_class/config.json new file mode 100644 index 00000000000..599a967f6ac --- /dev/null +++ b/tests/hot_reload/const_to_non_const_class/config.json @@ -0,0 +1,5 @@ +{ + "expectedErrors": { + "1": "Const class cannot become non-const: Library:'hot-reload-test:///main.dart' Class: A" + } +} \ No newline at end of file diff --git a/tests/hot_reload/const_to_non_const_class/main.0.dart b/tests/hot_reload/const_to_non_const_class/main.0.dart new file mode 100644 index 00000000000..1444aec95ff --- /dev/null +++ b/tests/hot_reload/const_to_non_const_class/main.0.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4569 + +void helper() { + a = const A(1); +} + +class A { + final dynamic x; + const A(this.x); +} + +dynamic a; + +Future main() async { + helper(); + await hotReload(expectRejection: true); + helper(); +} diff --git a/tests/hot_reload/const_to_non_const_class/main.1.reject.dart b/tests/hot_reload/const_to_non_const_class/main.1.reject.dart new file mode 100644 index 00000000000..24ef1d8d2a7 --- /dev/null +++ b/tests/hot_reload/const_to_non_const_class/main.1.reject.dart @@ -0,0 +1,44 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4569 + +void helper() { + throw Exception('This should never run.'); +} + +class A { + dynamic x; + A(this.x); +} + +dynamic a; + +Future main() async { + helper(); + await hotReload(expectRejection: true); + helper(); +} +/** DIFF **/ +/* +@@ -8,12 +8,12 @@ + // https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4569 + + void helper() { +- a = const A(1); ++ throw Exception('This should never run.'); + } + + class A { +- final dynamic x; +- const A(this.x); ++ dynamic x; ++ A(this.x); + } + + dynamic a; +*/ diff --git a/tests/hot_reload/const_to_non_const_class_empty/config.json b/tests/hot_reload/const_to_non_const_class_empty/config.json new file mode 100644 index 00000000000..599a967f6ac --- /dev/null +++ b/tests/hot_reload/const_to_non_const_class_empty/config.json @@ -0,0 +1,5 @@ +{ + "expectedErrors": { + "1": "Const class cannot become non-const: Library:'hot-reload-test:///main.dart' Class: A" + } +} \ No newline at end of file diff --git a/tests/hot_reload/const_to_non_const_class_empty/main.0.dart b/tests/hot_reload/const_to_non_const_class_empty/main.0.dart new file mode 100644 index 00000000000..379b8cc6028 --- /dev/null +++ b/tests/hot_reload/const_to_non_const_class_empty/main.0.dart @@ -0,0 +1,24 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4603 + +void helper() { + a = const A(); +} + +class A { + const A(); +} + +dynamic a; + +Future main() async { + helper(); + await hotReload(expectRejection: true); + helper(); +} diff --git a/tests/hot_reload/const_to_non_const_class_empty/main.1.reject.dart b/tests/hot_reload/const_to_non_const_class_empty/main.1.reject.dart new file mode 100644 index 00000000000..57b44a15fc5 --- /dev/null +++ b/tests/hot_reload/const_to_non_const_class_empty/main.1.reject.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4603 + +void helper() { + throw Exception('This should never run.'); +} + +class A { + dynamic x; + A(this.x); +} + +dynamic a; + +Future main() async { + helper(); + await hotReload(expectRejection: true); + helper(); +} +/** DIFF **/ +/* +@@ -8,11 +8,12 @@ + // https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4603 + + void helper() { +- a = const A(); ++ throw Exception('This should never run.'); + } + + class A { +- const A(); ++ dynamic x; ++ A(this.x); + } + + dynamic a; +*/ diff --git a/tests/hot_reload/constant_identical/main.0.dart b/tests/hot_reload/constant_identical/main.0.dart new file mode 100644 index 00000000000..4c16fe190a9 --- /dev/null +++ b/tests/hot_reload/constant_identical/main.0.dart @@ -0,0 +1,25 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/26f2ff4f11f56841fc5a250231ef7d49f01eb234/runtime/vm/isolate_reload_test.cc#L2604 + +class Fruit { + final String name; + const Fruit(this.name); + String toString() => name; +} + +var x; + +Future main() async { + x = const Fruit('Pear'); + Expect.equals('Pear', x.toString()); + await hotReload(); + Expect.equals('Pear', x.toString()); + Expect.identical(x, const Fruit('Pear')); +} diff --git a/tests/hot_reload/constant_identical/main.1.dart b/tests/hot_reload/constant_identical/main.1.dart new file mode 100644 index 00000000000..f2fbeb57c20 --- /dev/null +++ b/tests/hot_reload/constant_identical/main.1.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/26f2ff4f11f56841fc5a250231ef7d49f01eb234/runtime/vm/isolate_reload_test.cc#L2604 + +class Fruit { + final String name; + const Fruit(this.name); + String toString() => name; +} + +var x; + +Future main() async { + x = const Fruit('Pear'); + Expect.equals('Pear', x.toString()); + await hotReload(); + Expect.equals('Pear', x.toString()); + Expect.identical(x, const Fruit('Pear')); +} +/** DIFF **/ +/* +*/ diff --git a/tests/hot_reload/run_new_field_initializers_with_consts/main.0.dart b/tests/hot_reload/run_new_field_initializers_with_consts/main.0.dart new file mode 100644 index 00000000000..34c19b554d4 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_with_consts/main.0.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L5371 + +void helper() { + throw Exception('This should never run.'); +} + +class C { + final x; + const C(this.x); +} + +var a = const C(const C(1)); +var b = const C(const C(2)); +var c = const C(const C(3)); +var d = const C(const C(4)); + +class Foo {} + +late Foo value; + +Future main() async { + value = Foo(); + a; + b; + c; + d; + await hotReload(); + helper(); +} diff --git a/tests/hot_reload/run_new_field_initializers_with_consts/main.1.dart b/tests/hot_reload/run_new_field_initializers_with_consts/main.1.dart new file mode 100644 index 00000000000..dd393413904 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_with_consts/main.1.dart @@ -0,0 +1,74 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L5371 + +void helper() { + Expect.identical(a, value.a); + Expect.identical(b, value.b); + Expect.identical(c, value.c); + Expect.identical(d, value.d); +} + +class C { + final x; + const C(this.x); +} + +var a = const C(const C(1)); +var b = const C(const C(2)); +var c = const C(const C(3)); +var d = const C(const C(4)); + +class Foo { + var d = const C(const C(4)); + var c = const C(const C(3)); + var b = const C(const C(2)); + var a = const C(const C(1)); +} + +late Foo value; + +Future main() async { + value = Foo(); + a; + b; + c; + d; + await hotReload(); + helper(); +} +/** DIFF **/ +/* +@@ -9,7 +9,10 @@ + // https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L5371 + + void helper() { +- throw Exception('This should never run.'); ++ Expect.identical(a, value.a); ++ Expect.identical(b, value.b); ++ Expect.identical(c, value.c); ++ Expect.identical(d, value.d); + } + + class C { +@@ -22,7 +25,12 @@ + var c = const C(const C(3)); + var d = const C(const C(4)); + +-class Foo {} ++class Foo { ++ var d = const C(const C(4)); ++ var c = const C(const C(3)); ++ var b = const C(const C(2)); ++ var a = const C(const C(1)); ++} + + late Foo value; + +*/ diff --git a/tests/hot_reload/shape_change_const_add_slot/main.0.dart b/tests/hot_reload/shape_change_const_add_slot/main.0.dart new file mode 100644 index 00000000000..91bdbb0e857 --- /dev/null +++ b/tests/hot_reload/shape_change_const_add_slot/main.0.dart @@ -0,0 +1,27 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4243 + +void helper() { + a = const A(1); +} + +class A { + final x; + const A(this.x); +} + +var a; + +Future main() async { + helper(); + await hotReload(); + helper(); + await hotReload(); + helper(); +} diff --git a/tests/hot_reload/shape_change_const_add_slot/main.1.dart b/tests/hot_reload/shape_change_const_add_slot/main.1.dart new file mode 100644 index 00000000000..e79dae4119e --- /dev/null +++ b/tests/hot_reload/shape_change_const_add_slot/main.1.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4243 + +void helper() { + a = const A(1, null, null); +} + +class A { + final x, y, z; + const A(this.x, this.y, this.z); +} + +var a; + +Future main() async { + helper(); + await hotReload(); + helper(); + await hotReload(); + helper(); +} +/** DIFF **/ +/* +@@ -8,12 +8,12 @@ + // https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4243 + + void helper() { +- a = const A(1); ++ a = const A(1, null, null); + } + + class A { +- final x; +- const A(this.x); ++ final x, y, z; ++ const A(this.x, this.y, this.z); + } + + var a; +*/ diff --git a/tests/hot_reload/shape_change_const_add_slot/main.2.dart b/tests/hot_reload/shape_change_const_add_slot/main.2.dart new file mode 100644 index 00000000000..8b405f7e2ce --- /dev/null +++ b/tests/hot_reload/shape_change_const_add_slot/main.2.dart @@ -0,0 +1,46 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4243 + +void helper() { + a = const A(1, null, null, null, null); +} + +class A { + final x, y, z, w, u; + const A(this.x, this.y, this.z, this.w, this.u); +} + +var a; + +Future main() async { + helper(); + await hotReload(); + helper(); + await hotReload(); + helper(); +} +/** DIFF **/ +/* +@@ -8,12 +8,12 @@ + // https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4243 + + void helper() { +- a = const A(1, null, null); ++ a = const A(1, null, null, null, null); + } + + class A { +- final x, y, z; +- const A(this.x, this.y, this.z); ++ final x, y, z, w, u; ++ const A(this.x, this.y, this.z, this.w, this.u); + } + + var a; +*/ diff --git a/tests/hot_reload/shape_change_const_remove_slot/config.json b/tests/hot_reload/shape_change_const_remove_slot/config.json new file mode 100644 index 00000000000..6a5fe2dad56 --- /dev/null +++ b/tests/hot_reload/shape_change_const_remove_slot/config.json @@ -0,0 +1,6 @@ +{ + "expectedErrors": { + "1": "Const class cannot remove fields: Library:'hot-reload-test:///main.dart' Class: A", + "2": "Const class cannot remove fields: Library:'hot-reload-test:///main.dart' Class: A" + } +} \ No newline at end of file diff --git a/tests/hot_reload/shape_change_const_remove_slot/main.0.dart b/tests/hot_reload/shape_change_const_remove_slot/main.0.dart new file mode 100644 index 00000000000..c37394d7792 --- /dev/null +++ b/tests/hot_reload/shape_change_const_remove_slot/main.0.dart @@ -0,0 +1,27 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/d9502e2a906ceeb7c8e9d2e1ff15e2251dae80ce/runtime/vm/isolate_reload_test.cc#L4306 + +class A { + final x, y, z; + const A(this.x, this.y, this.z); +} + +var a; + +void helper() { + a = const A(1, 2, 3); +} + +Future main() async { + helper(); + await hotReload(expectRejection: true); + helper(); + await hotReload(expectRejection: true); + helper(); +} diff --git a/tests/hot_reload/shape_change_const_remove_slot/main.1.reject.dart b/tests/hot_reload/shape_change_const_remove_slot/main.1.reject.dart new file mode 100644 index 00000000000..762a159aa4d --- /dev/null +++ b/tests/hot_reload/shape_change_const_remove_slot/main.1.reject.dart @@ -0,0 +1,48 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/d9502e2a906ceeb7c8e9d2e1ff15e2251dae80ce/runtime/vm/isolate_reload_test.cc#L4306 + +class A { + final x, y; + const A(this.x, this.y); +} + +var a; + +void helper() { + a = const A(1, null); +} + +Future main() async { + helper(); + await hotReload(expectRejection: true); + helper(); + await hotReload(expectRejection: true); + helper(); +} +/** DIFF **/ +/* +@@ -8,14 +8,14 @@ + // https://github.com/dart-lang/sdk/blob/d9502e2a906ceeb7c8e9d2e1ff15e2251dae80ce/runtime/vm/isolate_reload_test.cc#L4306 + + class A { +- final x, y, z; +- const A(this.x, this.y, this.z); ++ final x, y; ++ const A(this.x, this.y); + } + + var a; + + void helper() { +- a = const A(1, 2, 3); ++ a = const A(1, null); + } + + Future main() async { +*/ diff --git a/tests/hot_reload/shape_change_const_remove_slot/main.2.reject.dart b/tests/hot_reload/shape_change_const_remove_slot/main.2.reject.dart new file mode 100644 index 00000000000..a0444b7c957 --- /dev/null +++ b/tests/hot_reload/shape_change_const_remove_slot/main.2.reject.dart @@ -0,0 +1,48 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/d9502e2a906ceeb7c8e9d2e1ff15e2251dae80ce/runtime/vm/isolate_reload_test.cc#L4306 + +class A { + final x, y, w; + const A(this.x, this.y, this.w); +} + +var a; + +void helper() { + a = const A(1, null, null); +} + +Future main() async { + helper(); + await hotReload(expectRejection: true); + helper(); + await hotReload(expectRejection: true); + helper(); +} +/** DIFF **/ +/* +@@ -8,14 +8,14 @@ + // https://github.com/dart-lang/sdk/blob/d9502e2a906ceeb7c8e9d2e1ff15e2251dae80ce/runtime/vm/isolate_reload_test.cc#L4306 + + class A { +- final x, y; +- const A(this.x, this.y); ++ final x, y, w; ++ const A(this.x, this.y, this.w); + } + + var a; + + void helper() { +- a = const A(1, null); ++ a = const A(1, null, null); + } + + Future main() async { +*/ diff --git a/tests/hot_reload/shape_change_retains_hash_const/main.0.dart b/tests/hot_reload/shape_change_retains_hash_const/main.0.dart new file mode 100644 index 00000000000..b1482113ce0 --- /dev/null +++ b/tests/hot_reload/shape_change_retains_hash_const/main.0.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4210 + +void helper() { + a = const A(1); + hash1 = a.hashCode; +} + +class A { + final x; + const A(this.x); +} + +var a, hash1, hash2; + +Future main() async { + helper(); + await hotReload(); + helper(); + Expect.equals(hash1, hash2); +} diff --git a/tests/hot_reload/shape_change_retains_hash_const/main.1.dart b/tests/hot_reload/shape_change_retains_hash_const/main.1.dart new file mode 100644 index 00000000000..41fa26e7c79 --- /dev/null +++ b/tests/hot_reload/shape_change_retains_hash_const/main.1.dart @@ -0,0 +1,49 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// 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. + +import 'package:expect/expect.dart'; +import 'package:reload_test/reload_test_utils.dart'; + +// Adapted from: +// https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4210 + +helper() { + hash2 = a.hashCode; +} + +class A { + final x, y, z; + const A(this.x, this.y, this.z); +} + +var a, hash1, hash2; + +Future main() async { + helper(); + await hotReload(); + helper(); + Expect.equals(hash1, hash2); +} +/** DIFF **/ +/* +@@ -8,14 +8,13 @@ + // Adapted from: + // https://github.com/dart-lang/sdk/blob/368cb645e5ff5baa1d1ed86bfd2e7d818471a652/runtime/vm/isolate_reload_test.cc#L4210 + +-void helper() { +- a = const A(1); +- hash1 = a.hashCode; ++helper() { ++ hash2 = a.hashCode; + } + + class A { +- final x; +- const A(this.x); ++ final x, y, z; ++ const A(this.x, this.y, this.z); + } + + var a, hash1, hash2; +*/