Skip to content

Commit

Permalink
[test] Adding a level of indirection for more clarity in constant ide…
Browse files Browse the repository at this point in the history
…ntity tests.

Change-Id: I9aa6c6bf278e8c8357d416d1a25be1eda4a4bf21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398761
Commit-Queue: Mark Zhou <[email protected]>
Reviewed-by: Nate Biggs <[email protected]>
  • Loading branch information
Markzipan authored and Commit Queue committed Dec 4, 2024
1 parent 4c1d453 commit 861fd1e
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/hot_reload/constant_identical/main.0.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ class Fruit {

var x;

helper() {
return const Fruit('Pear');
}

Future<void> main() async {
x = const Fruit('Pear');
Expect.equals('Pear', x.toString());
Expect.identical(x, helper());

await hotReload();
Expect.equals('Pear', x.toString());
Expect.identical(x, const Fruit('Pear'));
Expect.identical(x, helper());
}
7 changes: 7 additions & 0 deletions tests/hot_reload/constant_identical/main.1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@ class Fruit {

var x;

helper() {
return const Fruit('Pear');
}

Future<void> main() async {
x = const Fruit('Pear');
Expect.equals('Pear', x.toString());
Expect.identical(x, helper());

await hotReload();
Expect.equals('Pear', x.toString());
Expect.identical(x, const Fruit('Pear'));
Expect.identical(x, helper());
}
/** DIFF **/
/*
Expand Down
33 changes: 33 additions & 0 deletions tests/hot_reload/constant_nonidentical/main.0.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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
// Extended with logic to check for non-identity.

class Fruit {
final String name;
const Fruit(this.name);
String toString() => name;
}

var x;

helper() {
return const Fruit('Pear');
}

Future<void> main() async {
x = const Fruit('Pear');
Expect.equals('Pear', x.toString());
Expect.identical(x, helper());

await hotReload();
Expect.equals('Pear', x.toString());
Expect.identical(x, const Fruit('Pear'));
Expect.notIdentical(x, helper());
}
45 changes: 45 additions & 0 deletions tests/hot_reload/constant_nonidentical/main.1.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// 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
// Extended with logic to check for non-identity.

class Fruit {
final String name;
final String field = 'field';
const Fruit(this.name);
String toString() => name;
}

var x;

helper() {
return const Fruit('Pear');
}

Future<void> main() async {
x = const Fruit('Pear');
Expect.equals('Pear', x.toString());
Expect.identical(x, helper());

await hotReload();
Expect.equals('Pear', x.toString());
Expect.identical(x, const Fruit('Pear'));
Expect.notIdentical(x, helper());
}
/** DIFF **/
/*
@@ -11,6 +11,7 @@
class Fruit {
final String name;
+ final String field = 'field';
const Fruit(this.name);
String toString() => name;
}
*/

0 comments on commit 861fd1e

Please sign in to comment.