#1260. Finalizer tests fixed and refactored
diff --git a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t01.dart b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t01.dart
index e2333e7..a9118c4 100644
--- a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t01.dart
+++ b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t01.dart
@@ -10,7 +10,7 @@
/// Attaches this finalizer to [value].
///
/// When [value] is longer accessible to the program, while still having an
-/// attachement to this finalizer, the [callback] of this finalizer may be
+/// attachment to this finalizer, the [callback] of this finalizer may be
/// called with [finalizationToken] as argument.
///
/// @description Checks that finalizer can be attached to the different objects
@@ -30,30 +30,31 @@
cnt++;
});
+void clean() {
+ returnedToken = null;
+}
+
@pragma('vm:never-inline')
-void test() {
- Object? obj = Object();
- finalizer.attach(obj, "Just a string");
- print(obj);
+void attachToFinalizer(Object value, dynamic finalizationToken) {
+ finalizer.attach(value, finalizationToken);
+ Expect.isNull(returnedToken);
}
main() async {
- test();
+ attachToFinalizer(Object(), "Just a string");
await triggerGcWithDelay();
Expect.equals("Just a string", returnedToken);
+ clean();
- Object? obj = A();
- finalizer.attach(obj, 15);
- print(obj);
- obj = List.filled(100, 1);
+ attachToFinalizer(A(), 15);
await triggerGcWithDelay();
Expect.equals(15, returnedToken);
+ clean();
- finalizer.attach(obj, []);
- print(obj);
- obj = A();
+ attachToFinalizer(A(), []);
await triggerGcWithDelay();
Expect.equals([], returnedToken);
+ clean();
await triggerGcWithDelay();
Expect.equals(3, cnt);
diff --git a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t02.dart b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t02.dart
index c67dd5c..38b7391 100644
--- a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t02.dart
+++ b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t02.dart
@@ -10,7 +10,7 @@
/// Attaches this finalizer to [value].
///
/// When [value] is longer accessible to the program, while still having an
-/// attachement to this finalizer, the [callback] of this finalizer may be
+/// attachment to this finalizer, the [callback] of this finalizer may be
/// called with [finalizationToken] as argument.
///
/// @description Checks that finalizer with the given [detach] token can be
@@ -28,14 +28,14 @@
});
@pragma('vm:never-inline')
-void test(token) {
+void createAndAttach(token) {
Object value = Object();
finalizer.attach(value, "Finalization token", detach: token);
}
main() async {
A detachToken = A();
- test(detachToken);
+ createAndAttach(detachToken);
finalizer.detach(detachToken);
await triggerGcWithDelay();
Expect.equals(0, cnt);
diff --git a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t03.dart b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t03.dart
index c558066..07f5539 100644
--- a/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t03.dart
+++ b/LanguageFeatures/FinalizationRegistry/ffi/Finalizer/attach_A01_t03.dart
@@ -10,7 +10,7 @@
/// Attaches this finalizer to [value].
///
/// When [value] is longer accessible to the program, while still having an
-/// attachement to this finalizer, the [callback] of this finalizer may be
+/// attachment to this finalizer, the [callback] of this finalizer may be
/// called with [finalizationToken] as argument.
///
/// @description Checks that generic finalizer can be attached to the different
@@ -25,36 +25,31 @@
Object? returnedToken;
int cnt = 0;
-
final Finalizer<int> finalizer = Finalizer((token) {
returnedToken = token;
cnt++;
});
@pragma('vm:never-inline')
-void test(int token) {
- Object value = Object();
- finalizer.attach(value, token);
+void attachToFinalizer(Object value, int finalizationToken) {
+ finalizer.attach(value, finalizationToken);
}
main() async {
- test(1);
+ attachToFinalizer(Object(), 1);
await triggerGcWithDelay();
Expect.equals(1, returnedToken);
- Object? obj = A();
- finalizer.attach(obj, 15);
- print(obj);
- obj = List.filled(100, 1);
+ attachToFinalizer(A(), 15);
+ await triggerGcWithDelay();
+ Expect.equals(15, returnedToken);
await triggerGcWithDelay();
Expect.equals(15, returnedToken);
- finalizer.attach(obj, 14);
- print(obj);
- obj = A();
+ attachToFinalizer(A(), 14);
await triggerGcWithDelay();
- Expect.equals([], returnedToken);
+ Expect.equals(14, returnedToken);
Expect.equals(3, cnt);
await triggerGcWithDelay();
diff --git a/LanguageFeatures/FinalizationRegistry/no_ffi/Finalizer/NoSuchMethod_A01_t01.dart b/LanguageFeatures/FinalizationRegistry/no_ffi/Finalizer/noSuchMethod_A01_t01.dart
similarity index 92%
rename from LanguageFeatures/FinalizationRegistry/no_ffi/Finalizer/NoSuchMethod_A01_t01.dart
rename to LanguageFeatures/FinalizationRegistry/no_ffi/Finalizer/noSuchMethod_A01_t01.dart
index 83e56fa..1a8b483 100644
--- a/LanguageFeatures/FinalizationRegistry/no_ffi/Finalizer/NoSuchMethod_A01_t01.dart
+++ b/LanguageFeatures/FinalizationRegistry/no_ffi/Finalizer/noSuchMethod_A01_t01.dart
@@ -7,7 +7,7 @@
// Invocation invocation
// )
/// Invoked when a non-existent method or property is accessed.
-/// @description Checks that [NoSuchMethodError] is thrown if non-existing
+/// @description Checks that [noSuchMethodError] is thrown if non-existing
/// method or property is accessed.
/// @author iarkh@unipro.ru