Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -737,11 +737,10 @@ __weak id foo = [Foo alloc]; (void)foo; ]]) ], [ AC_MSG_RESULT(yes) - AC_DEFINE(COMPILER_SUPPORTS_ARC, 1, [Whether the compiler supports ARC]) AC_SUBST(RUNTIME_ARC_TESTS_M, RuntimeARCTests.m) ], [ AC_MSG_RESULT(no) ]) OBJCFLAGS="$old_OBJCFLAGS" Index: new_tests/Makefile ================================================================== --- new_tests/Makefile +++ new_tests/Makefile @@ -42,10 +42,11 @@ OFScryptTests.m \ OFSetTests.m \ OFStringTests.m \ OFSystemInfoTests.m \ OFUTF8StringTests.m \ + ${RUNTIME_ARC_TESTS_M} \ ${USE_SRCS_PLUGINS} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_SUBPROCESSES} \ ${USE_SRCS_THREADS} \ testfile_bin.m \ @@ -191,10 +192,11 @@ -I../src/runtime \ -I../src/test \ -I.. \ -DOBJFWTEST_LOCAL_INCLUDES \ -DPROG_SUFFIX=\"${PROG_SUFFIX}\" +OBJCFLAGS_RuntimeARCTests.m = -fobjc-arc -fobjc-arc-exceptions # Repetition is required for Wii U, as otherwise it cannot find main. Just # moving -lobjfwtest later doesn't work either, as then the linker cannot find # ObjFW symbols. So the only solution is to list everything twice. LIBS := -L../src/test \ -lobjfwtest \ ADDED new_tests/RuntimeARCTests.m Index: new_tests/RuntimeARCTests.m ================================================================== --- new_tests/RuntimeARCTests.m +++ new_tests/RuntimeARCTests.m @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2008-2024 Jonathan Schleifer + * + * All rights reserved. + * + * This file is part of ObjFW. It may be distributed under the terms of the + * Q Public License 1.0, which can be found in the file LICENSE.QPL included in + * the packaging of this file. + * + * Alternatively, it may be distributed under the terms of the GNU General + * Public License, either version 2 or 3, which can be found in the file + * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this + * file. + */ + +#include "config.h" + +#import "ObjFW.h" +#import "ObjFWTest.h" + +@interface RuntimeARCTests: OTTestCase +@end + +@interface RuntimeARCTestClass: OFObject +@end + +@implementation RuntimeARCTests +- (void)testExceptionsDuringInit +{ + OTAssertThrows((void)[[RuntimeARCTestClass alloc] init]); +} + +- (void)testWeakReferences +{ + id object = [[OFObject alloc] init]; + __weak id weak = object; + + OTAssertEqual(weak, object); + + object = nil; + OTAssertNil(weak); +} +@end + +@implementation RuntimeARCTestClass +- (instancetype)init +{ + self = [super init]; + +#if defined(OF_WINDOWS) && defined(OF_AMD64) + /* + * Clang has a bug on Windows where it creates an invalid call into + * objc_retainAutoreleasedReturnValue(). Work around it by not using an + * autoreleased exception. + */ + @throw [[OFException alloc] init]; +#else + @throw [OFException exception]; +#endif + + return self; +} +@end Index: tests/Makefile ================================================================== --- tests/Makefile +++ tests/Makefile @@ -22,11 +22,10 @@ OFValueTests.m \ OFXMLElementBuilderTests.m \ OFXMLNodeTests.m \ OFXMLParserTests.m \ RuntimeTests.m \ - ${RUNTIME_ARC_TESTS_M} \ TestsAppDelegate.m \ ${USE_SRCS_FILES} \ ${USE_SRCS_SOCKETS} \ ${USE_SRCS_WINDOWS} SRCS_SOCKETS = ${OF_HTTP_CLIENT_TESTS_M} \ @@ -151,9 +150,8 @@ CPPFLAGS += -I../src \ -I../src/exceptions \ -I../src/runtime \ -I.. \ -DSTDOUT -OBJCFLAGS_RuntimeARCTests.m = -fobjc-arc -fobjc-arc-exceptions LIBS := ${TESTS_LIBS} ${LIBS} LDFLAGS += ${MAP_LDFLAGS} LD = ${OBJC} DELETED tests/RuntimeARCTests.m Index: tests/RuntimeARCTests.m ================================================================== --- tests/RuntimeARCTests.m +++ tests/RuntimeARCTests.m @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2008-2024 Jonathan Schleifer - * - * All rights reserved. - * - * This file is part of ObjFW. It may be distributed under the terms of the - * Q Public License 1.0, which can be found in the file LICENSE.QPL included in - * the packaging of this file. - * - * Alternatively, it may be distributed under the terms of the GNU General - * Public License, either version 2 or 3, which can be found in the file - * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this - * file. - */ - -#include "config.h" - -#import "TestsAppDelegate.h" - -static OFString *const module = @"Runtime (ARC)"; - -@interface RuntimeARCTest: OFObject -@end - -@implementation RuntimeARCTest -- (instancetype)init -{ - self = [super init]; - -#if defined(OF_WINDOWS) && defined(OF_AMD64) - /* - * Clang has a bug on Windows where it creates an invalid call into - * objc_retainAutoreleasedReturnValue(). Work around it by not using an - * autoreleased exception. - */ - @throw [[OFException alloc] init]; -#else - @throw [OFException exception]; -#endif - - return self; -} -@end - -@implementation TestsAppDelegate (RuntimeARCTests) -- (void)runtimeARCTests -{ - id object; - __weak id weak; - - EXPECT_EXCEPTION(@"Exceptions in init", OFException, - object = [[RuntimeARCTest alloc] init]) - - object = [[OFObject alloc] init]; - weak = object; - TEST(@"weakly referencing an object", weak == object) - - object = nil; - TEST(@"weak references becoming nil", weak == nil) -} -@end Index: tests/TestsAppDelegate.h ================================================================== --- tests/TestsAppDelegate.h +++ tests/TestsAppDelegate.h @@ -97,14 +97,10 @@ @interface TestsAppDelegate (RuntimeTests) - (void)runtimeTests; @end -@interface TestsAppDelegate (RuntimeARCTests) -- (void)runtimeARCTests; -@end - @interface TestsAppDelegate (OFStreamTests) - (void)streamTests; @end @interface TestsAppDelegate (OFValueTests) Index: tests/TestsAppDelegate.m ================================================================== --- tests/TestsAppDelegate.m +++ tests/TestsAppDelegate.m @@ -369,13 +369,10 @@ [[OFFileManager defaultManager] changeCurrentDirectoryPath: @"/apps/objfw-tests"]; #endif [self runtimeTests]; -#ifdef COMPILER_SUPPORTS_ARC - [self runtimeARCTests]; -#endif [self dataTests]; [self dictionaryTests]; [self listTests]; [self valueTests]; [self streamTests];