Skip to content

Commit

Permalink
[ddc] Porting VM hot reload tests to the hot reload framework related…
Browse files Browse the repository at this point in the history
… to type updates.

Change-Id: I3c42781acd253ac82658593c96ab92ef6c2cdb50
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392466
Commit-Queue: Mark Zhou <markzipan@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
  • Loading branch information
Markzipan authored and Commit Queue committed Nov 7, 2024
1 parent 4436320 commit 5b01285
Show file tree
Hide file tree
Showing 59 changed files with 1,283 additions and 22 deletions.
3 changes: 3 additions & 0 deletions tests/hot_reload/delete_static_field/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exclude": []
}
35 changes: 35 additions & 0 deletions tests/hot_reload/delete_static_field/main.0.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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/63622f03eeaf72983b2f4957fa84da8062693f00/runtime/vm/isolate_reload_test.cc#L5493

// Note: The original VM test checks for allocated objects on the heap after a
// hot reload. There isn't an obvious web analogue, so we've left this off
// unless this side effect becomes visible across platforms.

class C {
int value = 42;
}

class Foo {
static var x = C();
}

late var closure;

helper() {
closure = () => Foo.x.value;
}

Future<void> main() async {
helper();
Expect.equals(42, closure());
await hotReload();

Expect.throws(closure);
}
52 changes: 52 additions & 0 deletions tests/hot_reload/delete_static_field/main.1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// 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/63622f03eeaf72983b2f4957fa84da8062693f00/runtime/vm/isolate_reload_test.cc#L5493

// Note: The original VM test checks for allocated objects on the heap after a
// hot reload. There isn't an obvious web analogue, so we've left this off
// unless this side effect becomes visible across platforms.

class C {
int value = 42;
}

class Foo {}

late var closure;

helper() {}

Future<void> main() async {
helper();
Expect.equals(42, closure());
await hotReload();

Expect.throws(closure);
}
/** DIFF **/
/*
@@ -16,15 +16,11 @@
int value = 42;
}
-class Foo {
- static var x = C();
-}
+class Foo {}
late var closure;
-helper() {
- closure = () => Foo.x.value;
-}
+helper() {}
Future<void> main() async {
helper();
*/
3 changes: 3 additions & 0 deletions tests/hot_reload/existing_field_changes_type/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exclude": []
}
23 changes: 23 additions & 0 deletions tests/hot_reload/existing_field_changes_type/main.0.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// 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 'dart:typed_data';
import 'package:expect/expect.dart';
import 'package:reload_test/reload_test_utils.dart';

// Adapted from:
// https://github.com/dart-lang/sdk/blob/bc58f69e532960a2f1d88f4b282869d6e2ad7cbe/runtime/vm/isolate_reload_test.cc#L5674

class Foo {
int x = 42;
}

Future<void> main() async {
Expect.type<int>(Foo().x);
Expect.equals(42, Foo().x);
await hotReload();

Expect.type<String>(Foo().x);
Expect.equals('42', Foo().x);
}
35 changes: 35 additions & 0 deletions tests/hot_reload/existing_field_changes_type/main.1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 'dart:typed_data';
import 'package:expect/expect.dart';
import 'package:reload_test/reload_test_utils.dart';

// Adapted from:
// https://github.com/dart-lang/sdk/blob/bc58f69e532960a2f1d88f4b282869d6e2ad7cbe/runtime/vm/isolate_reload_test.cc#L5674

class Foo {
String x = '42';
}

Future<void> main() async {
Expect.type<int>(Foo().x);
Expect.equals(42, Foo().x);
await hotReload();

Expect.type<String>(Foo().x);
Expect.equals('42', Foo().x);
}
/** DIFF **/
/*
@@ -10,7 +10,7 @@
// https://github.com/dart-lang/sdk/blob/bc58f69e532960a2f1d88f4b282869d6e2ad7cbe/runtime/vm/isolate_reload_test.cc#L5674
class Foo {
- int x = 42;
+ String x = '42';
}
Future<void> main() async {
*/
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Future<void> main() async {

await hotReload();

Expect.contains(
"type 'B' is not a subtype of type 'A' of 'function result'", helper());
Expect.contains("type 'B' is not a subtype of type 'A'", helper());
Expect.equals(1, hotReloadGeneration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ Future<void> main() async {

await hotReload();

Expect.contains(
"type 'B' is not a subtype of type 'A' of 'function result'", helper());
Expect.contains("type 'B' is not a subtype of type 'A'", helper());
Expect.equals(1, hotReloadGeneration);
}
/** DIFF **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ Future<void> main() async {

// B is no longer a subtype of A.
Expect.equals(
"type '(A) => bool' is not a subtype of type "
"'(B) => bool' of 'function result'",
helper());
"type '(A) => bool' is not a subtype of type '(B) => bool'", helper());
Expect.equals(1, hotReloadGeneration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ Future<void> main() async {

// B is no longer a subtype of A.
Expect.equals(
"type '(A) => bool' is not a subtype of type "
"'(B) => bool' of 'function result'",
helper());
"type '(A) => bool' is not a subtype of type '(B) => bool'", helper());
Expect.equals(1, hotReloadGeneration);
}
/** DIFF **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ Future<void> main() async {

// B is no longer a subtype of A.
Expect.contains(
"type 'List<B>' is not a subtype of type 'List<A>' of 'function result'",
helper());
"type 'List<B>' is not a subtype of type 'List<A>'", helper());
Expect.equals(1, hotReloadGeneration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ Future<void> main() async {

// B is no longer a subtype of A.
Expect.contains(
"type 'List<B>' is not a subtype of type 'List<A>' of 'function result'",
helper());
"type 'List<B>' is not a subtype of type 'List<A>'", helper());
Expect.equals(1, hotReloadGeneration);
}
/** DIFF **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Future<void> main() async {

await hotReload();

Expect.contains(
"type 'A' is not a subtype of type 'B' of 'function result'", helper());
Expect.contains("type 'A' is not a subtype of type 'B'", helper());
Expect.equals(1, hotReloadGeneration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ Future<void> main() async {

await hotReload();

Expect.contains(
"type 'A' is not a subtype of type 'B' of 'function result'", helper());
Expect.contains("type 'A' is not a subtype of type 'B'", helper());
Expect.equals(1, hotReloadGeneration);
}
/** DIFF **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ Future<void> main() async {

await hotReload();

Expect.contains(
"type 'B' is not a subtype of type 'A' of 'function result'", helper());
Expect.contains("type 'B' is not a subtype of type 'A'", helper());
Expect.equals(1, hotReloadGeneration);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ Future<void> main() async {

await hotReload();

Expect.contains(
"type 'B' is not a subtype of type 'A' of 'function result'", helper());
Expect.contains("type 'B' is not a subtype of type 'A'", helper());
Expect.equals(1, hotReloadGeneration);
}
/** DIFF **/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exclude": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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/63622f03eeaf72983b2f4957fa84da8062693f00/runtime/vm/isolate_reload_test.cc#L5929

class A {}

class B extends A {}

typedef bool Predicate(B b);

Predicate value = init();
init() => (A a) => true;

String helper() {
try {
return value.toString();
} catch (e) {
return e.toString();
}
}

Future<void> main() async {
Expect.contains('Closure: (A) => bool', helper());

await hotReload();

// B is no longer a subtype of A.
Expect.contains(
"type '(A) => bool' is not a subtype of type '(B) => bool'", helper());
}
Original file line number Diff line number Diff line change
@@ -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:expect/expect.dart';
import 'package:reload_test/reload_test_utils.dart';

// Adapted from:
// https://github.com/dart-lang/sdk/blob/63622f03eeaf72983b2f4957fa84da8062693f00/runtime/vm/isolate_reload_test.cc#L5929

class A {}

class B {}

typedef bool Predicate(B b);

Predicate value = init();
init() => (A a) => true;

String helper() {
try {
return value.toString();
} catch (e) {
return e.toString();
}
}

Future<void> main() async {
Expect.contains('Closure: (A) => bool', helper());

await hotReload();

// B is no longer a subtype of A.
Expect.contains(
"type '(A) => bool' is not a subtype of type '(B) => bool'", helper());
}
/** DIFF **/
/*
@@ -10,7 +10,7 @@
class A {}
-class B extends A {}
+class B {}
typedef bool Predicate(B b);
*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"exclude": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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/63622f03eeaf72983b2f4957fa84da8062693f00/runtime/vm/isolate_reload_test.cc#L5841

class A {}

class B extends A {}

List<A> value = init();
init() => List<B>.empty();

String helper() {
try {
return value.toString();
} catch (e) {
return e.toString();
}
}

Future<void> main() async {
Expect.equals('[]', helper());

await hotReload();

// B is no longer a subtype of A.
Expect.contains(
"type 'List<B>' is not a subtype of type 'List<A>'", helper());
}
Loading

0 comments on commit 5b01285

Please sign in to comment.