summaryrefslogtreecommitdiff
path: root/platform/darwin/test/MGLTestAssertionHandler.m
blob: 4b504427b5fb03fdaff46c30af2f1c3e2c62543a (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#import "MGLTestAssertionHandler.h"

@implementation MGLTestAssertionHandler

- (instancetype)initWithTestCase:(XCTestCase *)testCase {
    if ((self = [super init])) {
        _testCase = testCase;
    }
    return self;
}

- (void)handleFailureInMethod:(SEL)selector
                       object:(id)object
                         file:(NSString *)fileName
                   lineNumber:(NSInteger)line
                  description:(NSString *)format, ...
{
    va_list args;
    va_start(args, format);
    NSString *description = [[NSString alloc] initWithFormat:format arguments:args];
    va_end(args);
    
    NSString *condition = [NSString stringWithFormat:
                           @"`[%@ %@]`",
                           object, NSStringFromSelector(selector)
                           ];

    if (self.testCase && self.shouldFail) {
        _XCTPreformattedFailureHandler(self.testCase,
                                       YES,
                                       fileName,
                                       line,
                                       condition,
                                       description
                                       );
    }
    else {
        NSLog(@"Assertion Failure: %@:%lu: %@ - %@",
              fileName,
              line,
              condition,
              description);
    }
}
 
- (void)handleFailureInFunction:(NSString *)functionName
                           file:(NSString *)fileName
                     lineNumber:(NSInteger)line
                    description:(NSString *)format, ...
{
    va_list args;
    va_start(args, format);
    NSString *description = [[NSString alloc] initWithFormat:format arguments:args];
    va_end(args);

    NSString *condition = [NSString stringWithFormat:
                           @"`%@`",
                           functionName];

    if (self.testCase && self.shouldFail) {
        _XCTPreformattedFailureHandler(self.testCase,
                                       YES,
                                       fileName,
                                       line,
                                       condition,
                                       description);
    }
    else {
        NSLog(@"Assertion Failure: %@:%lu: %@ - %@",
              fileName,
              line,
              condition,
              description);
    }
}
@end