diff --git a/objc2-foundation/tests/objc_id_retain_autoreleased.rs b/objc2-foundation/tests/objc_id_retain_autoreleased.rs index 71ea1a4cc..01b5380f0 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"));