89 lines
3.2 KiB
Swift
89 lines
3.2 KiB
Swift
//
|
|
// AppPathsTests.swift
|
|
//
|
|
// Copyright 2026 Brendan Szymanski <hello@bscubed.dev>
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU General Public License
|
|
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
//
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
//
|
|
|
|
import Foundation
|
|
import Testing
|
|
|
|
@testable import LuminateCore
|
|
|
|
@Suite struct AppPathsTests {
|
|
@Test("An absolute override is used verbatim")
|
|
func overrideWins() {
|
|
let path = AppPaths.dataDirectory(
|
|
environment: [AppPaths.dataDirectoryOverrideVariable: "/override/luminate"],
|
|
home: URL(filePath: "/home/test"),
|
|
temporaryDirectory: URL(filePath: "/tmp")
|
|
)
|
|
#expect(path == URL(filePath: "/override/luminate"))
|
|
}
|
|
|
|
#if canImport(Darwin)
|
|
@Test("Injected home receives the Application Support application directory")
|
|
func applicationSupportHome() {
|
|
let path = AppPaths.dataDirectory(
|
|
environment: [:],
|
|
home: URL(filePath: "/Users/test"),
|
|
temporaryDirectory: URL(filePath: "/tmp")
|
|
)
|
|
#expect(path.path == "/Users/test/Library/Application Support/luminate")
|
|
}
|
|
#else
|
|
@Test("Absolute XDG data home receives the lowercase application directory")
|
|
func xdgDataHome() {
|
|
let path = AppPaths.dataDirectory(
|
|
environment: ["XDG_DATA_HOME": "/data"],
|
|
home: URL(filePath: "/home/test"),
|
|
temporaryDirectory: URL(filePath: "/tmp")
|
|
)
|
|
#expect(path.path == "/data/luminate")
|
|
}
|
|
|
|
@Test("Relative XDG data home is ignored")
|
|
func relativeXDGDataHome() {
|
|
let path = AppPaths.dataDirectory(
|
|
environment: ["XDG_DATA_HOME": "relative"],
|
|
home: URL(filePath: "/home/test"),
|
|
temporaryDirectory: URL(filePath: "/tmp")
|
|
)
|
|
#expect(path.path == "/home/test/.local/share/luminate")
|
|
}
|
|
|
|
@Test("Root home is a valid Linux data location")
|
|
func rootHome() {
|
|
let path = AppPaths.dataDirectory(
|
|
environment: [:],
|
|
home: URL(filePath: "/"),
|
|
temporaryDirectory: URL(filePath: "/tmp")
|
|
)
|
|
#expect(path.path == "/.local/share/luminate")
|
|
}
|
|
#endif
|
|
|
|
@Test("Missing home falls back to the temporary directory")
|
|
func missingHome() {
|
|
let path = AppPaths.dataDirectory(
|
|
environment: [:],
|
|
home: nil,
|
|
temporaryDirectory: URL(filePath: "/tmp/luminate-test")
|
|
)
|
|
#expect(path.path == "/tmp/luminate-test/luminate")
|
|
}
|
|
}
|