Skip to content

Commit b50b7ec

Browse files
committed
another fix
1 parent 9f5ffeb commit b50b7ec

File tree

1 file changed

+27
-4
lines changed

1 file changed

+27
-4
lines changed

Crashlytics/UnitTests/FIRCLSContextManagerTests.m

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,28 @@ @interface FIRCLSContextManagerTests : XCTestCase
4141
@implementation FIRCLSContextManagerTests
4242

4343
- (void)setUp {
44+
[super setUp];
45+
46+
// This is a more robust way to create a temporary directory for testing.
47+
NSString *tempDirectoryTemplate =
48+
[NSTemporaryDirectory() stringByAppendingPathComponent:@"FIRCLSContextManagerTests.XXXXXX"];
49+
const char *tempDirectoryTemplateCString = [tempDirectoryTemplate fileSystemRepresentation];
50+
char *tempDirectoryNameCString = (char *)malloc(strlen(tempDirectoryTemplateCString) + 1);
51+
strcpy(tempDirectoryNameCString, tempDirectoryTemplateCString);
52+
53+
char *result = mkdtemp(tempDirectoryNameCString);
54+
if (!result) {
55+
XCTFail(@"Couldn't create temporary directory.");
56+
}
57+
58+
NSString *tempDirectoryPath =
59+
[[NSFileManager defaultManager] stringWithFileSystemRepresentation:tempDirectoryNameCString
60+
length:strlen(result)];
61+
free(tempDirectoryNameCString);
62+
4463
self.fileManager = [[FIRCLSMockFileManager alloc] init];
45-
[[NSFileManager defaultManager] createDirectoryAtPath:self.fileManager.rootPath
46-
withIntermediateDirectories:YES
47-
attributes:nil
48-
error:nil];
64+
self.fileManager.rootPath = tempDirectoryPath;
65+
4966
[self.fileManager createReportDirectories];
5067
[self.fileManager setupNewPathForExecutionIdentifier:TestContextReportID];
5168

@@ -57,6 +74,12 @@ - (void)setUp {
5774
NSString *reportPath =
5875
[self.fileManager.activePath stringByAppendingPathComponent:TestContextReportID];
5976

77+
// The report needs to be initialized with a path that actually exists.
78+
[[NSFileManager defaultManager] createDirectoryAtPath:reportPath
79+
withIntermediateDirectories:YES
80+
attributes:nil
81+
error:nil];
82+
6083
self.report = [[FIRCLSInternalReport alloc] initWithPath:reportPath
6184
executionIdentifier:TestContextReportID];
6285

0 commit comments

Comments
 (0)