ObjFW  Check-in [e94a061758]

Overview
Comment:ObjFWTest: Add output and show a summary
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | objfwtest
Files: files | file ages | folders
SHA3-256: e94a06175813c2ab332c7fa1c0a7374d1aa3493497df3a4a25635bd2a9f7ab1e
User & Date: js on 2024-02-10 11:30:06
Other Links: branch diff | manifest | tags
Context
2024-02-10
12:55
Add ObjFWTest check-in: 0ceea01454 user: js tags: trunk
12:06
Migrate OFPBKDF2Tests to ObjFWTest check-in: 7c509c3d51 user: js tags: objfwtest
11:30
ObjFWTest: Add output and show a summary check-in: e94a061758 user: js tags: objfwtest
11:02
ObjFWTest.oc: Fix FRAMEWORK_LIBS check-in: dfeede4ec0 user: js tags: objfwtest
Changes

Modified src/test/OTAppDelegate.m from [d77755a8a2] to [7aa90ae52e].

13
14
15
16
17
18
19

20

21
22
23
24
25
26
27
 * file.
 */

#include "config.h"

#import "OTAppDelegate.h"


#import "OFSet.h"

#import "OFValue.h"

#import "OTTestCase.h"

#import "OTAssertionFailedException.h"

OF_APPLICATION_DELEGATE(OTAppDelegate)







>

>







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 * file.
 */

#include "config.h"

#import "OTAppDelegate.h"

#import "OFColor.h"
#import "OFSet.h"
#import "OFStdIOStream.h"
#import "OFValue.h"

#import "OTTestCase.h"

#import "OTAssertionFailedException.h"

OF_APPLICATION_DELEGATE(OTAppDelegate)
79
80
81
82
83
84
85

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
	[tests makeImmutable];
	return tests;
}

- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
	OFSet OF_GENERIC(Class) *testClasses = [self testClasses];





	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];
			} @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







>

>
>
>

>
>


>
|
>
>
>
>
>
>
|











>
>
>
>
>
>
>








>
>
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>



>
>
>




81
82
83
84
85
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
	[tests makeImmutable];
	return tests;
}

- (void)applicationDidFinishLaunching: (OFNotification *)notification
{
	OFSet OF_GENERIC(Class) *testClasses = [self testClasses];
	size_t numSucceeded = 0, numFailed = 0;

	[OFStdOut writeFormat: @"Running %zu test case(s)\n",
			       testClasses.count];

	for (Class class in testClasses) {
		[OFStdOut writeFormat: @"Running tests in %@\n", class];

		for (OFValue *test in [self testsInClass: class]) {
			void *pool = objc_autoreleasePoolPush();
			bool failed = false;
			OTTestCase *instance;

			[OFStdOut setForegroundColor: [OFColor yellow]];
			[OFStdOut writeFormat:
			    @"-[%@ %s]: ",
			    class, sel_getName(test.pointerValue)];

			instance = [[[class alloc] init] autorelease];

			@try {
				[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.
				 */
				[OFStdOut setForegroundColor: [OFColor red]];
				[OFStdOut writeFormat:
				    @"\r-[%@ %s]: failed\n",
				    class, sel_getName(test.pointerValue)];
				[OFStdOut writeLine: e.description];

				failed = true;
			}
			@try {
				[instance tearDown];
			} @catch (OTAssertionFailedException *e) {
				/*
				 * If an assertion fails during -[tearDown],
				 * abort the tear down.
				 */
				if (!failed) {
					[OFStdOut setForegroundColor:
					    [OFColor red]];
					[OFStdOut writeFormat:
					    @"\r-[%@ %s]: failed\n",
					    class,
					    sel_getName(test.pointerValue)];
					[OFStdOut writeLine: e.description];

					failed = true;
				}
			}

			if (!failed) {
				[OFStdOut setForegroundColor: [OFColor green]];
				[OFStdOut writeFormat:
				    @"\r-[%@ %s]: ok\n",
				    class, sel_getName(test.pointerValue)];

				numSucceeded++;
			} else
				numFailed++;

			[OFStdOut reset];

			objc_autoreleasePoolPop(pool);
		}
	}

	[OFStdOut writeFormat: @"%zu test(s) succeeded, %zu test(s) failed.\n",
			       numSucceeded, numFailed];

	[OFApplication terminate];
}
@end

Modified src/test/OTAssert.m from [8c54d0fe0f] to [dfc3f7ba82].

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
 * 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];

}







<
<








<







<
<










<
<
<
<
<
<
<
<
<
|
>

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
 * 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 "OFString.h"

#import "OTAssertionFailedException.h"

void
OTAssertImpl(id testCase, SEL test, bool condition, OFString *check,
    OFString *file, size_t line, ...)
{

	va_list arguments;
	OFConstantString *format;
	OFString *message = nil;

	if (condition)
		return;



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

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

	va_end(arguments);










	@throw [OTAssertionFailedException exceptionWithCondition: check
							  message: message];
}

Modified src/test/OTAssertionFailedException.h from [ae3f64510c] to [434d5612c9].

10
11
12
13
14
15
16

17


18














19


 * 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









>

>
>

>
>
>
>
>
>
>
>
>
>
>
>
>
>

>
>
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
 * 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"
#import "OFString.h"

OF_ASSUME_NONNULL_BEGIN

@interface OTAssertionFailedException: OFException
{
	OFString *_condition;
	OFString *_Nullable _message;
}

@property (readonly, nonatomic) OFString *condition;
@property OF_NULLABLE_PROPERTY (readonly, nonatomic) OFString *message;

+ (instancetype)exceptionWithCondition: (OFString *)condition
			       message: (nullable OFString *)message;
+ (instancetype)exception OF_UNAVAILABLE;
- (instancetype)initWithCondition: (OFString *)condition
			  message: (nullable OFString *)message;
- (instancetype)init OF_UNAVAILABLE;
@end

OF_ASSUME_NONNULL_END

Modified src/test/OTAssertionFailedException.m from [f90fe6b716] to [ca30ea25b3].

14
15
16
17
18
19
20




















































21
 */

#include "config.h"

#import "OTAssertionFailedException.h"

@implementation OTAssertionFailedException




















































@end







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
 */

#include "config.h"

#import "OTAssertionFailedException.h"

@implementation OTAssertionFailedException
@synthesize condition = _condition, message = _message;

+ (instancetype)exceptionWithCondition: (OFString *)condition
			       message: (OFString *)message
{
	return [[[self alloc] initWithCondition: condition
					message: message] autorelease];
}

+ (instancetype)exception
{
	OF_UNRECOGNIZED_SELECTOR
}

- (instancetype)initWithCondition: (OFString *)condition
			  message: (OFString *)message
{
	self = [super init];

	@try {
		_condition = [condition copy];
		_message = [message copy];
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (instancetype)init
{
	OF_INVALID_INIT_METHOD
}

- (void)dealloc
{
	[_condition release];
	[_message release];

	[super dealloc];
}

- (OFString *)description
{
	if (_message != nil)
		return [OFString stringWithFormat: @"Assertion failed: %@: %@",
						   _condition, _message];
	else
		return [OFString stringWithFormat: @"Assertion failed: %@",
						   _condition];
}
@end