ObjFW  Check-in [5cd1585ae1]

Overview
Comment:ObjFWTest: Add OTAssert()
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: 5cd1585ae158abecf3e1485b3b852e0e8b7447c5ba95103529df984484256971
User & Date: js on 2024-02-06 23:01:44
Other Links: branch diff | manifest | tags
Context
2024-02-10
00:27
Build ObjFWTest only as a static library check-in: 1cd17a28dd user: js tags: objfwtest
2024-02-06
23:01
ObjFWTest: Add OTAssert() check-in: 5cd1585ae1 user: js tags: objfwtest
21:27
Fix compiling ObjFWTest as .framework on macOS check-in: e96d4372a0 user: js tags: objfwtest
Changes

Modified src/test/Makefile from [20281734c6] to [7573a19b66].

1
2
3
4
5
6
7
8
9
10
11

12

13
14
15


16
17
18
19
20
21
22
1
2
3
4
5
6
7
8
9
10
11
12

13
14
15

16
17
18
19
20
21
22
23
24











+
-
+


-
+
+







include ../../extra.mk

DISTCLEAN = Info.plist

SHARED_LIB = ${OBJFWTEST_SHARED_LIB}
STATIC_LIB = ${OBJFWTEST_STATIC_LIB}
FRAMEWORK = ${OBJFWTEST_FRAMEWORK}
LIB_MAJOR = ${OBJFWTEST_LIB_MAJOR}
LIB_MINOR = ${OBJFWTEST_LIB_MINOR}
LIB_PATCH = ${OBJFWTEST_LIB_PATCH}

SRCS = OTAssert.m	\
SRCS = OTTestCase.m
       OTTestCase.m
INCLUDES := ${SRCS:.m=.h}	\
	    ObjFWTest.h
SRCS += OTAppDelegate.m
SRCS += OTAppDelegate.m			\
	OTAssertionFailedException.m

includesubdir = ObjFWTest

include ../../buildsys.mk

CPPFLAGS += -I. 			\
	    -I..			\

Modified src/test/OTAppDelegate.m from [36e6efa285] to [d77755a8a2].

18
19
20
21
22
23
24


25
26
27
28
29
30
31
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33







+
+







#import "OTAppDelegate.h"

#import "OFSet.h"
#import "OFValue.h"

#import "OTTestCase.h"

#import "OTAssertionFailedException.h"

OF_APPLICATION_DELEGATE(OTAppDelegate)

@implementation OTAppDelegate
- (OFSet OF_GENERIC(Class) *)testClasses
{
	Class *classes = objc_copyClassList(NULL);
	OFMutableSet *testClasses;
84
85
86
87
88
89
90

91
92
93


















94
95
96
97
98
99
100
101
86
87
88
89
90
91
92
93



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119







+
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+









	for (Class class in testClasses) {
		for (OFValue *test in [self testsInClass: class]) {
			void *pool = objc_autoreleasePoolPush();
			OTTestCase *instance =
			    [[[class alloc] init] autorelease];

			@try {
			[instance setUp];
			[instance performSelector: test.pointerValue];
			[instance tearDown];
				[instance setUp];
				[instance performSelector: test.pointerValue];
			} @catch (OTAssertionFailedException *e) {
				/*
				 * If an assertion during -[setUp], don't run
				 * the test.
				 * If an assertion fails during a test, abort
				 * the test.
				 */
			}
			@try {
				[instance tearDown];
			} @catch (OTAssertionFailedException *e) {
				/*
				 * If an assertion fails during -[tearDown],
				 * abort the tear down.
				 */
			}

			objc_autoreleasePoolPop(pool);
		}
	}

	[OFApplication terminate];
}
@end

Added src/test/OTAssert.h version [43ca8fc8fa].



































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * 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.
 */

#define OTAssert(cond, ...) \
	OTAssertImpl(self, _cmd, cond, @#cond, @__FILE__, __LINE__,	\
	    ## __VA_ARGS__, nil)
#define OTAssertTrue(cond, ...) OTAssert(cond == true, ## __VA_ARGS__)
#define OTAssertFalse(cond, ...) OTAssert(cond == false, ## __VA_ARGS__)
#define OTAssertEqual(a, b, ...) OTAssert(a == b, ## __VA_ARGS__)
#define OTAssertNotEqual(a, b, ...) OTAssert(a != b, ## __VA_ARGS__)
#define OTAssertEqualObjects(a, b, ...) OTAssert([a isEqual: b], ## __VA_ARGS__)
#define OTAssertNotEqualObjects(a, b, ...) \
	OTAssert(![a isEqual: b], ## __VA_ARGS__)

#ifdef __cplusplus
extern "C" {
#endif
extern void OTAssertImpl(id testCase, SEL test, bool condition, OFString *check,
    OFString *file, size_t line, ...);
#ifdef __cplusplus
}
#endif

Added src/test/OTAssert.m version [8c54d0fe0f].



























































1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * 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 "OFColor.h"
#import "OFStdIOStream.h"
#import "OFString.h"

#import "OTAssertionFailedException.h"

void
OTAssertImpl(id testCase, SEL test, bool condition, OFString *check,
    OFString *file, size_t line, ...)
{
	void *pool;
	va_list arguments;
	OFConstantString *format;
	OFString *message = nil;

	if (condition)
		return;

	pool = objc_autoreleasePoolPush();

	va_start(arguments, line);
	format = va_arg(arguments, OFConstantString *);

	if (format != nil)
		message = [[[OFString alloc]
		    initWithFormat: format
			 arguments: arguments] autorelease];

	va_end(arguments);

	[OFStdErr setForegroundColor: [OFColor red]];
	[OFStdErr writeFormat: @"-[%@ %s]: Condition failed: %@%@%@\n",
			       [testCase className], sel_getName(test),
			       check, (message != nil ? @": " : @""),
			       (message != nil ? message : @"")];
	[OFStdErr reset];

	objc_autoreleasePoolPop(pool);

	@throw [OTAssertionFailedException exception];
}

Added src/test/OTAssertionFailedException.h version [ae3f64510c].




















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * 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.
 */

#import "OFException.h"

@interface OTAssertionFailedException: OFException
@end

Added src/test/OTAssertionFailedException.m version [f90fe6b716].






















1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
/*
 * Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
 *
 * 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 "OTAssertionFailedException.h"

@implementation OTAssertionFailedException
@end

Modified src/test/OTTestCase.h from [65a29e60d8] to [2add704de5].

17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
17
18
19
20
21
22
23



24
25
26
27
28
29







-
-
-






# import "OFObject.h"
#else
# import <ObjFW/OFObject.h>
#endif

OF_ASSUME_NONNULL_BEGIN

/**
 * @class OTTestCase OTTestCase.h ObjFWTest/OTTestCase.h
 */
@interface OTTestCase: OFObject
- (void)setUp;
- (void)tearDown;
@end

OF_ASSUME_NONNULL_END

Modified src/test/ObjFWTest.h from [92263f43ba] to [c6fa64803a].

10
11
12
13
14
15
16

10
11
12
13
14
15
16
17







+
 * 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.
 */

#import "OTTestCase.h"
#import "OTAssert.h"