[tests] Port const tests from vm hot reload suite

Change-Id: I8fedb4afe8f117e54aa17ff85e0415e818b2c62f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389583
Reviewed-by: Nate Biggs <natebiggs@google.com>
Commit-Queue: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Mark Zhou <markzipan@google.com>
This commit is contained in:
Nicholas Shahan
2024-11-28 01:23:24 +00:00
committed by Commit Queue
parent 7969fc0a23
commit 0224206aaa
19 changed files with 635 additions and 0 deletions
@@ -0,0 +1,5 @@
{
"expectedErrors": {
"1": "Const class cannot become non-const: Library:'hot-reload-test:///main.dart' Class: A"
}
}
@@ -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<void> main() async {
helper();
await hotReload(expectRejection: true);
helper();
}
@@ -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<void> 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;
*/
@@ -0,0 +1,5 @@
{
"expectedErrors": {
"1": "Const class cannot become non-const: Library:'hot-reload-test:///main.dart' Class: A"
}
}
@@ -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<void> main() async {
helper();
await hotReload(expectRejection: true);
helper();
}
@@ -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<void> 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;
*/
@@ -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<void> main() async {
x = const Fruit('Pear');
Expect.equals('Pear', x.toString());
await hotReload();
Expect.equals('Pear', x.toString());
Expect.identical(x, const Fruit('Pear'));
}
@@ -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<void> 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 **/
/*
*/
@@ -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<void> main() async {
value = Foo();
a;
b;
c;
d;
await hotReload();
helper();
}
@@ -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<void> 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;
*/
@@ -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<void> main() async {
helper();
await hotReload();
helper();
await hotReload();
helper();
}
@@ -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<void> 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;
*/
@@ -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<void> 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;
*/
@@ -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"
}
}
@@ -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<void> main() async {
helper();
await hotReload(expectRejection: true);
helper();
await hotReload(expectRejection: true);
helper();
}
@@ -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<void> 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<void> main() async {
*/
@@ -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<void> 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<void> main() async {
*/
@@ -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<void> main() async {
helper();
await hotReload();
helper();
Expect.equals(hash1, hash2);
}
@@ -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<void> 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;
*/