mirror of
https://github.com/ghostty-org/ghostty.git
synced 2026-04-06 07:38:21 +00:00
macos: add TemporaryConfig for AI to write test cases
This commit is contained in:
@@ -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")
|
||||
|
||||
20
macos/Tests/Ghostty/ConfigTests.swift
Normal file
20
macos/Tests/Ghostty/ConfigTests.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user