From 8a3542f7223fbcbccc6f198a48d92ad21c0881d0 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Tue, 23 Nov 2021 13:30:19 +0100 Subject: [PATCH] Fix test_retain_autoreleased on GNUStep --- .../tests/objc_id_retain_autoreleased.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/objc2-foundation/tests/objc_id_retain_autoreleased.rs b/objc2-foundation/tests/objc_id_retain_autoreleased.rs index 6493b198c..10b0faf6c 100644 --- a/objc2-foundation/tests/objc_id_retain_autoreleased.rs +++ b/objc2-foundation/tests/objc_id_retain_autoreleased.rs @@ -25,22 +25,31 @@ fn create_data(bytes: &[u8]) -> Id { #[test] fn test_retain_autoreleased() { + #[cfg(gnustep)] + unsafe { + objc2::__gnustep_hack::get_class_to_force_linkage() + }; + autoreleasepool(|_| { let data = create_data(b"12"); // The autorelease-return-mechanism has to "warm up" somehow? At least // for some reason the first time this is used it fails. - assert_eq!(retain_count(&data), 2); + assert_eq!(retain_count(&data), if cfg!(gnustep) { 1 } else { 2 }); // When compiled in release mode / with optimizations enabled, // subsequent usage of `retain_autoreleased` will succeed in retaining // the autoreleased value! - let expected_retain_count = if cfg!(debug_assertions) { 2 } else { 1 }; + let expected = if cfg!(all(debug_assertions, not(gnustep))) { + 2 + } else { + 1 + }; let data = create_data(b"34"); - assert_eq!(retain_count(&data), expected_retain_count); + assert_eq!(retain_count(&data), expected); let data = create_data(b"56"); - assert_eq!(retain_count(&data), expected_retain_count); + assert_eq!(retain_count(&data), expected); // Here we manually clean up the autorelease, so it will always be 1. let data = autoreleasepool(|_| create_data(b"78"));