macos: add TemporaryConfig for AI to write test cases

This commit is contained in:
Lukas
2026-03-09 15:29:44 +01:00
parent 8784636547
commit 32934445cf
2 changed files with 21 additions and 1 deletions

View File

@@ -53,7 +53,7 @@ extension Ghostty {
/// - Parameters:
/// - path: An optional preferred config file path. Pass `nil` to load the default configuration files.
/// - finalize: Whether to finalize the configuration to populate default values.
static private func loadConfig(at path: String?, finalize: Bool) -> ghostty_config_t? {
static func loadConfig(at path: String?, finalize: Bool) -> ghostty_config_t? {
// Initialize the global configuration.
guard let cfg = ghostty_config_new() else {
logger.critical("ghostty_config_new failed")

View File

@@ -0,0 +1,20 @@
import Testing
@testable import Ghostty
/// Create a temporary config file and delete it when this is deallocated
class TemporaryConfig: Ghostty.Config {
let temporaryFile: URL
init(_ configText: String, finalize: Bool = false) throws {
let temporaryFile = FileManager.default.temporaryDirectory
.appendingPathComponent(UUID().uuidString)
.appendingPathExtension("ghostty")
try configText.write(to: temporaryFile, atomically: true, encoding: .utf8)
self.temporaryFile = temporaryFile
super.init(config: Self.loadConfig(at: temporaryFile.path(), finalize: finalize))
}
deinit {
try? FileManager.default.removeItem(at: temporaryFile)
}
}