Skip to content

Commit 67ec125

Browse files
authored
Simplify swiftTestingDirectoryPath. (#588)
Since all platform-specific paths in this function end in `return nil`, we can simplify a bit. Also a couple of drive-by newline changes. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 6077347 commit 67ec125

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

Sources/Testing/Traits/Tags/Tag.Color+Loading.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ private var _appDataDirectoryPath: String? {
4949
/// On Apple platforms and on Linux, this path is equivalent to
5050
/// `"~/.swift-testing"`. On Windows, it is equivalent to
5151
/// `"%HOMEPATH%\AppData\Local\.swift-testing"`.
52+
///
5253
/// The value of this property is `nil` if the platform does not support the
5354
/// concept of a home directory, or if the home directory could not be
5455
/// determined.
@@ -60,18 +61,20 @@ var swiftTestingDirectoryPath: String? {
6061
if let homeDirectoryPath = _homeDirectoryPath {
6162
return appendPathComponent(swiftTestingDirectoryName, to: homeDirectoryPath)
6263
}
63-
return nil
64+
#elseif SWT_TARGET_OS_APPLE
65+
// Other Apple/Darwin platforms do not support the concept of a home
66+
// directory. One exists for the current user, but it's not something that
67+
// actually contains user-configurable data like a .swift-testing directory.
6468
#elseif os(Windows)
6569
if let appDataDirectoryPath = _appDataDirectoryPath {
6670
return appendPathComponent(swiftTestingDirectoryName, to: appDataDirectoryPath)
6771
}
68-
return nil
6972
#elseif os(WASI)
70-
return nil
73+
// WASI does not support the concept of a home directory.
7174
#else
7275
#warning("Platform-specific implementation missing: .swift-testing directory location unavailable")
73-
return nil
7476
#endif
77+
return nil
7578
}
7679

7780
/// Read tag colors out of the file `"tag-colors.json"` in a given directory.
@@ -96,6 +99,7 @@ func loadTagColors(fromFileInDirectoryAtPath swiftTestingDirectoryPath: String?
9699
// tag colors.
97100
return [:]
98101
}
102+
99103
// Find the path to the tag-colors.json file and try to load its contents.
100104
let tagColorsPath = appendPathComponent("tag-colors.json", to: swiftTestingDirectoryPath)
101105
let fileHandle = try FileHandle(forReadingAtPath: tagColorsPath)

0 commit comments

Comments
 (0)