From 16960a863873b4515eca0b6e6126955596fd7f06 Mon Sep 17 00:00:00 2001 From: Nicholas Shahan Date: Mon, 10 Feb 2025 16:26:00 -0800 Subject: [PATCH] [tests] Fix tests for changing type parameters * Handle inconsistencies in the type of a notice in reload reports. * Update expected error messages when the type parameters of a class change. * Fail reload tests if rejection error was expected but the actual error is null. * Cleanup unused imports in tests. * Delete change_instance_format7 test because it was split into DDC and VM specific versions. Change-Id: I3b4d6cb3126d7c1fad688c393677e053a005687f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408883 Reviewed-by: Mark Zhou Commit-Queue: Nicholas Shahan --- pkg/dev_compiler/test/hot_reload_suite.dart | 2 +- pkg/reload_test/lib/src/_vm_reload_utils.dart | 3 +- .../change_instance_format6/config.json | 3 +- .../change_instance_format6/main.0.dart | 1 - .../main.1.reject.dart | 1 - .../change_instance_format7/main.0.dart | 23 ------------ .../change_instance_format7/main.1.dart | 36 ------------------- .../change_instance_format7_ddc/config.json | 6 ++-- .../change_instance_format7_ddc/main.0.dart | 1 - .../main.1.reject.dart | 1 - .../change_instance_format7_vm/main.0.dart | 1 - .../change_instance_format7_vm/main.1.dart | 1 - .../change_instance_format9/config.json | 3 +- .../change_instance_format9/main.0.dart | 1 - .../main.1.reject.dart | 1 - 15 files changed, 9 insertions(+), 75 deletions(-) delete mode 100644 tests/hot_reload/change_instance_format7/main.0.dart delete mode 100644 tests/hot_reload/change_instance_format7/main.1.dart diff --git a/pkg/dev_compiler/test/hot_reload_suite.dart b/pkg/dev_compiler/test/hot_reload_suite.dart index 60eabf4312a..70877656bb3 100644 --- a/pkg/dev_compiler/test/hot_reload_suite.dart +++ b/pkg/dev_compiler/test/hot_reload_suite.dart @@ -752,7 +752,7 @@ abstract class HotReloadSuiteRunner { return false; } final rejectionMessage = reloadReceipt.rejectionMessage; - if (rejectionMessage != null && + if (rejectionMessage == null || !rejectionMessage.contains(expectedError)) { _print( 'Generation ${reloadReceipt.generation} was rejected but error ' diff --git a/pkg/reload_test/lib/src/_vm_reload_utils.dart b/pkg/reload_test/lib/src/_vm_reload_utils.dart index 9c723817b88..2b96fe9ccf4 100644 --- a/pkg/reload_test/lib/src/_vm_reload_utils.dart +++ b/pkg/reload_test/lib/src/_vm_reload_utils.dart @@ -179,7 +179,8 @@ extension on ReloadReport { final notices = this.json?['notices'] as List?; if (notices != null) { for (final notice in notices) { - if (notice['type'] == 'ReasonForCancelling') { + if (notice['type'] == 'ReasonForCancelling' || + notice['type'] == 'ReasonForCancellingReload') { return notice['message'] as String?; } } diff --git a/tests/hot_reload/change_instance_format6/config.json b/tests/hot_reload/change_instance_format6/config.json index a56eae84069..3deef58553d 100644 --- a/tests/hot_reload/change_instance_format6/config.json +++ b/tests/hot_reload/change_instance_format6/config.json @@ -1,6 +1,5 @@ { "expectedErrors": { - "1": "type parameters have changed" + "1": "Limitation: changing type parameters does not work with hot reload." } } - diff --git a/tests/hot_reload/change_instance_format6/main.0.dart b/tests/hot_reload/change_instance_format6/main.0.dart index 724899077c9..25acc8f243a 100644 --- a/tests/hot_reload/change_instance_format6/main.0.dart +++ b/tests/hot_reload/change_instance_format6/main.0.dart @@ -2,7 +2,6 @@ // 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: diff --git a/tests/hot_reload/change_instance_format6/main.1.reject.dart b/tests/hot_reload/change_instance_format6/main.1.reject.dart index 07033e84025..87e86bf89d6 100644 --- a/tests/hot_reload/change_instance_format6/main.1.reject.dart +++ b/tests/hot_reload/change_instance_format6/main.1.reject.dart @@ -2,7 +2,6 @@ // 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: diff --git a/tests/hot_reload/change_instance_format7/main.0.dart b/tests/hot_reload/change_instance_format7/main.0.dart deleted file mode 100644 index c587070f201..00000000000 --- a/tests/hot_reload/change_instance_format7/main.0.dart +++ /dev/null @@ -1,23 +0,0 @@ -// 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/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4051 - -// Tests reload succeeds when type parameters are changed for allocated class. -// Change: Foo {a, b} -> Foo {a} -// Validate: return value from main is correct. -// Please note: This test works because no instances are created from Foo. - -class Foo { - var a; - var b; -} - -Future main() async { - await hotReload(); -} diff --git a/tests/hot_reload/change_instance_format7/main.1.dart b/tests/hot_reload/change_instance_format7/main.1.dart deleted file mode 100644 index 582b689bc62..00000000000 --- a/tests/hot_reload/change_instance_format7/main.1.dart +++ /dev/null @@ -1,36 +0,0 @@ -// 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/1a486499bf73ee5b007abbe522b94869a1f36d02/runtime/vm/isolate_reload_test.cc#L4051 - -// Tests reload succeeds when type parameters are changed for allocated class. -// Change: Foo {a, b} -> Foo {a} -// Validate: return value from main is correct. -// Please note: This test works because no instances are created from Foo. - -class Foo { - var a; -} - -Future main() async { - await hotReload(); -} - -/** DIFF **/ -/* - // Validate: return value from main is correct. - // Please note: This test works because no instances are created from Foo. - --class Foo { -+class Foo { - var a; -- var b; - } - - Future main() async { -*/ diff --git a/tests/hot_reload/change_instance_format7_ddc/config.json b/tests/hot_reload/change_instance_format7_ddc/config.json index 5162377ab84..fd3d942b5a9 100644 --- a/tests/hot_reload/change_instance_format7_ddc/config.json +++ b/tests/hot_reload/change_instance_format7_ddc/config.json @@ -1,6 +1,8 @@ { - "exclude": ["vm"], + "exclude": [ + "vm" + ], "expectedErrors": { - "1": "type parameters have changed" + "1": "Limitation: changing type parameters does not work with hot reload." } } diff --git a/tests/hot_reload/change_instance_format7_ddc/main.0.dart b/tests/hot_reload/change_instance_format7_ddc/main.0.dart index b5cdf199a28..a903aae84fb 100644 --- a/tests/hot_reload/change_instance_format7_ddc/main.0.dart +++ b/tests/hot_reload/change_instance_format7_ddc/main.0.dart @@ -2,7 +2,6 @@ // 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: diff --git a/tests/hot_reload/change_instance_format7_ddc/main.1.reject.dart b/tests/hot_reload/change_instance_format7_ddc/main.1.reject.dart index 1457bb3a2fa..0c935d510c3 100644 --- a/tests/hot_reload/change_instance_format7_ddc/main.1.reject.dart +++ b/tests/hot_reload/change_instance_format7_ddc/main.1.reject.dart @@ -2,7 +2,6 @@ // 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: diff --git a/tests/hot_reload/change_instance_format7_vm/main.0.dart b/tests/hot_reload/change_instance_format7_vm/main.0.dart index c587070f201..b382055bdd5 100644 --- a/tests/hot_reload/change_instance_format7_vm/main.0.dart +++ b/tests/hot_reload/change_instance_format7_vm/main.0.dart @@ -2,7 +2,6 @@ // 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: diff --git a/tests/hot_reload/change_instance_format7_vm/main.1.dart b/tests/hot_reload/change_instance_format7_vm/main.1.dart index 582b689bc62..01cc5e9904b 100644 --- a/tests/hot_reload/change_instance_format7_vm/main.1.dart +++ b/tests/hot_reload/change_instance_format7_vm/main.1.dart @@ -2,7 +2,6 @@ // 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: diff --git a/tests/hot_reload/change_instance_format9/config.json b/tests/hot_reload/change_instance_format9/config.json index a56eae84069..3deef58553d 100644 --- a/tests/hot_reload/change_instance_format9/config.json +++ b/tests/hot_reload/change_instance_format9/config.json @@ -1,6 +1,5 @@ { "expectedErrors": { - "1": "type parameters have changed" + "1": "Limitation: changing type parameters does not work with hot reload." } } - diff --git a/tests/hot_reload/change_instance_format9/main.0.dart b/tests/hot_reload/change_instance_format9/main.0.dart index a0cf282c3e8..4a16081706b 100644 --- a/tests/hot_reload/change_instance_format9/main.0.dart +++ b/tests/hot_reload/change_instance_format9/main.0.dart @@ -2,7 +2,6 @@ // 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: diff --git a/tests/hot_reload/change_instance_format9/main.1.reject.dart b/tests/hot_reload/change_instance_format9/main.1.reject.dart index cf8b5eca011..63cf42557ab 100644 --- a/tests/hot_reload/change_instance_format9/main.1.reject.dart +++ b/tests/hot_reload/change_instance_format9/main.1.reject.dart @@ -2,7 +2,6 @@ // 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: