Skip to content

Commit 584cc97

Browse files
Do not load configuration from ~/.swift-testing by default on WASI
WASI does not provide a concept of a user directory, so just skip loading custom tag colors configuration.
1 parent 8f114ba commit 584cc97

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,29 @@ 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-
var swiftTestingDirectoryPath: String {
52+
/// The value of this property is `nil` if the platform does not support the
53+
/// concept of a home directory, or if the home directory could not be
54+
/// determined.
55+
var swiftTestingDirectoryPath: String? {
5356
// The (default) name of the .swift-testing directory.
5457
let swiftTestingDirectoryName = ".swift-testing"
5558

5659
#if os(macOS) || (os(iOS) && targetEnvironment(macCatalyst)) || os(Linux)
5760
if let homeDirectoryPath = _homeDirectoryPath {
5861
return appendPathComponent(swiftTestingDirectoryName, to: homeDirectoryPath)
5962
}
63+
return nil
6064
#elseif os(Windows)
6165
if let appDataDirectoryPath = _appDataDirectoryPath {
6266
return appendPathComponent(swiftTestingDirectoryName, to: appDataDirectoryPath)
6367
}
68+
return nil
69+
#elseif os(WASI)
70+
return nil
6471
#else
6572
#warning("Platform-specific implementation missing: .swift-testing directory location unavailable")
73+
return nil
6674
#endif
67-
return ""
6875
}
6976

7077
/// Read tag colors out of the file `"tag-colors.json"` in a given directory.
@@ -83,7 +90,12 @@ var swiftTestingDirectoryPath: String {
8390
/// assumed to contain a JSON object (a dictionary) where the keys are tags'
8491
/// string values and the values represent tag colors. For a list of the
8592
/// supported formats for tag colors in this dictionary, see <doc:AddingTags>.
86-
func loadTagColors(fromFileInDirectoryAtPath swiftTestingDirectoryPath: String = swiftTestingDirectoryPath) throws -> [Tag: Tag.Color] {
93+
func loadTagColors(fromFileInDirectoryAtPath swiftTestingDirectoryPath: String? = swiftTestingDirectoryPath) throws -> [Tag: Tag.Color] {
94+
guard let swiftTestingDirectoryPath else {
95+
// If the platform does not support user-specific configuration, skip custom
96+
// tag colors.
97+
return [:]
98+
}
8799
// Find the path to the tag-colors.json file and try to load its contents.
88100
let tagColorsPath = appendPathComponent("tag-colors.json", to: swiftTestingDirectoryPath)
89101
let fileHandle = try FileHandle(forReadingAtPath: tagColorsPath)

0 commit comments

Comments
 (0)