-
-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathTNSTestCommon.m
49 lines (40 loc) · 1.33 KB
/
TNSTestCommon.m
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
#import "TNSTestCommon.h"
static NSMutableString* TNSTestOutput;
// TODO: Thread safe
bool TNSIsConfigurationDebug() {
#ifdef DEBUG
return true;
#else
return false;
#endif
}
NSString* TNSGetOutput() {
if (TNSTestOutput == nil) {
TNSTestOutput = [NSMutableString new];
}
return TNSTestOutput;
}
void TNSLog(NSString* message) {
[(NSMutableString*)TNSGetOutput() appendFormat:@"%@", message];
}
void TNSClearOutput() {
TNSTestOutput = nil;
}
void TNSSaveResults(NSString* result) {
NSFileManager* fileManager = [NSFileManager defaultManager];
NSString* documentsDirectory = [[[fileManager URLsForDirectory:NSDocumentDirectory
inDomains:NSUserDomainMask] lastObject] path];
NSString* path = [[documentsDirectory stringByAppendingPathComponent:@"junit-result"] stringByAppendingPathExtension:@"xml"];
[fileManager removeItemAtPath:path
error:nil];
NSError* error = nil;
[result writeToFile:path
atomically:YES
encoding:NSUTF8StringEncoding
error:&error];
if (error) {
@throw [NSException exceptionWithName:NSGenericException
reason:error.localizedDescription
userInfo:nil];
}
}