diff --git a/tests/hot_reload/enum_values_to_string/main.0.dart b/tests/hot_reload/enum_values_to_string/main.0.dart new file mode 100644 index 00000000000..f6e9df20d05 --- /dev/null +++ b/tests/hot_reload/enum_values_to_string/main.0.dart @@ -0,0 +1,26 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L3546 + +enum Fruit { Apple, Banana } + +helper() { + String r = ''; + r += Fruit.Apple.toString(); + r += ' '; + r += Fruit.Banana.toString(); + return r; +} + +Future main() async { + Expect.equals('Fruit.Apple Fruit.Banana', helper()); + await hotReload(); + + Expect.equals('Fruit.Apple Fruit.Cantaloupe Fruit.Banana', helper()); +} diff --git a/tests/hot_reload/enum_values_to_string/main.1.dart b/tests/hot_reload/enum_values_to_string/main.1.dart new file mode 100644 index 00000000000..bcc60c203c2 --- /dev/null +++ b/tests/hot_reload/enum_values_to_string/main.1.dart @@ -0,0 +1,47 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L3546 + +enum Fruit { Apple, Cantaloupe, Banana } + +helper() { + String r = ''; + r += Fruit.Apple.toString(); + r += ' '; + r += Fruit.Cantaloupe.toString(); + r += ' '; + r += Fruit.Banana.toString(); + return r; +} + +Future main() async { + Expect.equals('Fruit.Apple Fruit.Banana', helper()); + await hotReload(); + + Expect.equals('Fruit.Apple Fruit.Cantaloupe Fruit.Banana', helper()); +} + +/** DIFF **/ +/* + // Adapted from: + // https://github.com/dart-lang/sdk/blob/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L3546 + +-enum Fruit { Apple, Banana } ++enum Fruit { Apple, Cantaloupe, Banana } + + helper() { + String r = ''; + r += Fruit.Apple.toString(); + r += ' '; ++ r += Fruit.Cantaloupe.toString(); ++ r += ' '; + r += Fruit.Banana.toString(); + return r; + } +*/ diff --git a/tests/hot_reload/function_replacement/main.0.dart b/tests/hot_reload/function_replacement/main.0.dart new file mode 100644 index 00000000000..c202cf25a36 --- /dev/null +++ b/tests/hot_reload/function_replacement/main.0.dart @@ -0,0 +1,20 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L47 + +helper() { + return 4; +} + +Future main() async { + Expect.equals(4, helper()); + await hotReload(); + + Expect.equals(10, helper()); +} diff --git a/tests/hot_reload/function_replacement/main.1.dart b/tests/hot_reload/function_replacement/main.1.dart new file mode 100644 index 00000000000..d72c4d1ab24 --- /dev/null +++ b/tests/hot_reload/function_replacement/main.1.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L47 + +helper() { + return 10; +} + +Future main() async { + Expect.equals(4, helper()); + await hotReload(); + + Expect.equals(10, helper()); +} + +/** DIFF **/ +/* + // https://github.com/dart-lang/sdk/blob/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L47 + + helper() { +- return 4; ++ return 10; + } + + Future main() async { +*/ diff --git a/tests/hot_reload/patch_static_initializer_with_closure/main.0.dart b/tests/hot_reload/patch_static_initializer_with_closure/main.0.dart new file mode 100644 index 00000000000..f92c7d660d4 --- /dev/null +++ b/tests/hot_reload/patch_static_initializer_with_closure/main.0.dart @@ -0,0 +1,20 @@ +// Copyright (c) 2025, 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/174ce4005f34bc860d1a4189ff21292b0796c94b/runtime/vm/isolate_reload_test.cc#L6091 + +dynamic field = (a) => 'a$a'; + +Future main() async { + dynamic f = field; + Expect.equals('ab', f('b')); + await hotReload(); + + dynamic g = field; + Expect.equals('ac', g('c')); +} diff --git a/tests/hot_reload/patch_static_initializer_with_closure/main.1.dart b/tests/hot_reload/patch_static_initializer_with_closure/main.1.dart new file mode 100644 index 00000000000..fdcd2d485ce --- /dev/null +++ b/tests/hot_reload/patch_static_initializer_with_closure/main.1.dart @@ -0,0 +1,32 @@ +// Copyright (c) 2025, 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/174ce4005f34bc860d1a4189ff21292b0796c94b/runtime/vm/isolate_reload_test.cc#L6091 + +dynamic field = (_, __) => 'Not executed'; + +Future main() async { + dynamic f = field; + Expect.equals('ab', f('b')); + await hotReload(); + + dynamic g = field; + Expect.equals('ac', g('c')); +} + +/** DIFF **/ +/* + // Adapted from: + // https://github.com/dart-lang/sdk/blob/174ce4005f34bc860d1a4189ff21292b0796c94b/runtime/vm/isolate_reload_test.cc#L6091 + +-dynamic field = (a) => 'a$a'; ++dynamic field = (_, __) => 'Not executed'; + + Future main() async { + dynamic f = field; +*/ diff --git a/tests/hot_reload/run_new_field_initializers_syntax_error/config.json b/tests/hot_reload/run_new_field_initializers_syntax_error/config.json new file mode 100644 index 00000000000..e3c3e3454e0 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_syntax_error/config.json @@ -0,0 +1,5 @@ +{ + "expectedErrors": { + "1": "Error: Expected an identifier, but got '...'" + } +} \ No newline at end of file diff --git a/tests/hot_reload/run_new_field_initializers_syntax_error/main.0.dart b/tests/hot_reload/run_new_field_initializers_syntax_error/main.0.dart new file mode 100644 index 00000000000..9e387a72445 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_syntax_error/main.0.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L5209 + +// When an initializer expression has a syntax error, we detect it at reload +// time. + +class Foo { + int x = 4; +} + +late Foo value; +helper() { + value = Foo(); + return value.x; +} + +Future main() async { + Expect.equals(4, helper()); + // Add the field y with a syntax error in the initializing expression. + // The reload fails because the initializing expression is parsed at + // class finalization time. + await hotReload(expectRejection: true); +} diff --git a/tests/hot_reload/run_new_field_initializers_syntax_error/main.1.reject.dart b/tests/hot_reload/run_new_field_initializers_syntax_error/main.1.reject.dart new file mode 100644 index 00000000000..b85b6aacbf6 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_syntax_error/main.1.reject.dart @@ -0,0 +1,48 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L5209 + +// When an initializer expression has a syntax error, we detect it at reload +// time. + +class Foo { + int x = 4; + int y = ......; +} + +late Foo value; +helper() { + return value.y; +} + +Future main() async { + Expect.equals(4, helper()); + // Add the field y with a syntax error in the initializing expression. + // The reload fails because the initializing expression is parsed at + // class finalization time. + await hotReload(expectRejection: true); +} + +/** DIFF **/ +/* + + class Foo { + int x = 4; ++ int y = ......; + } + + late Foo value; + helper() { +- value = Foo(); +- return value.x; ++ return value.y; + } + + Future main() async { +*/ diff --git a/tests/hot_reload/run_new_field_initializers_syntax_error2/config.json b/tests/hot_reload/run_new_field_initializers_syntax_error2/config.json new file mode 100644 index 00000000000..e3c3e3454e0 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_syntax_error2/config.json @@ -0,0 +1,5 @@ +{ + "expectedErrors": { + "1": "Error: Expected an identifier, but got '...'" + } +} \ No newline at end of file diff --git a/tests/hot_reload/run_new_field_initializers_syntax_error2/main.0.dart b/tests/hot_reload/run_new_field_initializers_syntax_error2/main.0.dart new file mode 100644 index 00000000000..9c18c07f3f1 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_syntax_error2/main.0.dart @@ -0,0 +1,31 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L5247 + +// When an initializer expression has a syntax error, we detect it at reload +// time. + +class Foo { + Foo() { /* default constructor */ } + int x = 4; +} + +late Foo value; +helper() { + value = Foo(); + return value.x; +} + +Future main() async { + Expect.equals(4, helper()); + // Add the field y with a syntax error in the initializing expression. + // The reload fails because the initializing expression is parsed at + // class finalization time. + await hotReload(expectRejection: true); +} diff --git a/tests/hot_reload/run_new_field_initializers_syntax_error2/main.1.reject.dart b/tests/hot_reload/run_new_field_initializers_syntax_error2/main.1.reject.dart new file mode 100644 index 00000000000..97a39396734 --- /dev/null +++ b/tests/hot_reload/run_new_field_initializers_syntax_error2/main.1.reject.dart @@ -0,0 +1,49 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L5247 + +// When an initializer expression has a syntax error, we detect it at reload +// time. + +class Foo { + Foo() { /* default constructor */ } + int x = 4; + int y = ......; +} + +late Foo value; +helper() { + return value.y; +} + +Future main() async { + Expect.equals(4, helper()); + // Add the field y with a syntax error in the initializing expression. + // The reload fails because the initializing expression is parsed at + // class finalization time. + await hotReload(expectRejection: true); +} + +/** DIFF **/ +/* + class Foo { + Foo() { /* default constructor */ } + int x = 4; ++ int y = ......; + } + + late Foo value; + helper() { +- value = Foo(); +- return value.x; ++ return value.y; + } + + Future main() async { +*/ diff --git a/tests/hot_reload/shape_change_mutual_reference/main.0.dart b/tests/hot_reload/shape_change_mutual_reference/main.0.dart new file mode 100644 index 00000000000..65b3bd2613f --- /dev/null +++ b/tests/hot_reload/shape_change_mutual_reference/main.0.dart @@ -0,0 +1,28 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L4140 + +class A { + var x; + get yourself => this; +} + +var retained1; +var retained2; + +Future main() async { + retained1 = new A(); + retained2 = new A(); + retained1.x = retained2; + retained2.x = retained1; + Expect.identical(retained1.x.yourself, retained2); + Expect.identical(retained2.x.yourself, retained1); + + await hotReload(); +} diff --git a/tests/hot_reload/shape_change_mutual_reference/main.1.dart b/tests/hot_reload/shape_change_mutual_reference/main.1.dart new file mode 100644 index 00000000000..30de9b01318 --- /dev/null +++ b/tests/hot_reload/shape_change_mutual_reference/main.1.dart @@ -0,0 +1,55 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L4140 + +class A { + var x; + var y; + var z; + var w; + get yourself => this; +} + +var retained1; +var retained2; + +Future main() async { + retained1 = new A(); + retained2 = new A(); + retained1.x = retained2; + retained2.x = retained1; + Expect.identical(retained1.x.yourself, retained2); + Expect.identical(retained2.x.yourself, retained1); + + await hotReload(); + + Expect.identical(retained1.x.yourself, retained2); + Expect.identical(retained2.x.yourself, retained1); +} + +/** DIFF **/ +/* + + class A { + var x; ++ var y; ++ var z; ++ var w; + get yourself => this; + } + +@@ -25,4 +28,7 @@ Future main() async { + Expect.identical(retained2.x.yourself, retained1); + + await hotReload(); ++ ++ Expect.identical(retained1.x.yourself, retained2); ++ Expect.identical(retained2.x.yourself, retained1); + } +*/ diff --git a/tests/hot_reload/top_level_parse_error/config.json b/tests/hot_reload/top_level_parse_error/config.json new file mode 100644 index 00000000000..6163a758ebc --- /dev/null +++ b/tests/hot_reload/top_level_parse_error/config.json @@ -0,0 +1,5 @@ +{ + "expectedErrors": { + "1": "Variables must be declared using the keywords 'const', 'final', 'var' or a type name" + } +} \ No newline at end of file diff --git a/tests/hot_reload/top_level_parse_error/main.0.dart b/tests/hot_reload/top_level_parse_error/main.0.dart new file mode 100644 index 00000000000..75d7ac33359 --- /dev/null +++ b/tests/hot_reload/top_level_parse_error/main.0.dart @@ -0,0 +1,18 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L1257 + +helper() { + return 4; +} + +Future main() async { + Expect.equals(4, helper()); + await hotReload(expectRejection: true); +} diff --git a/tests/hot_reload/top_level_parse_error/main.1.reject.dart b/tests/hot_reload/top_level_parse_error/main.1.reject.dart new file mode 100644 index 00000000000..2fa3c30b083 --- /dev/null +++ b/tests/hot_reload/top_level_parse_error/main.1.reject.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2025, 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/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L1257 + +kjsadkfjaksldfjklsadf; +helper() { + return 4; +} + +Future main() async { + Expect.equals(4, helper()); + await hotReload(expectRejection: true); +} + +/** DIFF **/ +/* + // Adapted from: + // https://github.com/dart-lang/sdk/blob/13f5fc6b168d8b6e5843d17fb9ba77f1343a7dfe/runtime/vm/isolate_reload_test.cc#L1257 + ++kjsadkfjaksldfjklsadf; + helper() { + return 4; + } +*/