113 lines
3.5 KiB
Swift
113 lines
3.5 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import GObjectGeneratorCore
|
|
|
|
@Suite("MonorepoConfig")
|
|
struct MonorepoConfigTests {
|
|
|
|
@Test func parsesValidMonorepoConfig() throws {
|
|
let toml = """
|
|
output_dir = "."
|
|
|
|
[packages.Gtk]
|
|
gir = "/usr/share/gir-1.0/Gtk-4.0.gir"
|
|
|
|
[packages.Gdk]
|
|
gir = "/usr/share/gir-1.0/Gdk-4.0.gir"
|
|
concurrency = "mainActor"
|
|
|
|
[packages.GObject]
|
|
gir = "/usr/share/gir-1.0/GObject-2.0.gir"
|
|
"""
|
|
|
|
let dict = try TOMLReader.parse(toml)
|
|
let config = try MonorepoConfig.from(toml: dict, defaultOutputDir: ".")
|
|
|
|
#expect(config.outputDir == ".")
|
|
#expect(config.packages.count == 3)
|
|
#expect(config.packages[0].name == "GObject")
|
|
#expect(config.packages[0].girPath == "/usr/share/gir-1.0/GObject-2.0.gir")
|
|
#expect(config.packages[0].concurrency == nil)
|
|
#expect(config.packages[1].name == "Gdk")
|
|
#expect(config.packages[1].concurrency == .mainActor)
|
|
#expect(config.packages[2].name == "Gtk")
|
|
#expect(config.packages[2].concurrency == nil)
|
|
}
|
|
|
|
@Test func parsesPackagesWithObjectOverrides() throws {
|
|
let dict: [String: Any] = [
|
|
"output_dir": "Sources",
|
|
"packages": [
|
|
"Gtk": [
|
|
"gir": "/usr/share/gir-1.0/Gtk-4.0.gir",
|
|
"object": [
|
|
"Gtk.Widget": ["status": "generate", "concurrency": "mainActor"],
|
|
"Gtk.Legacy": ["status": "ignore"],
|
|
],
|
|
],
|
|
],
|
|
]
|
|
|
|
let config = try MonorepoConfig.from(toml: dict, defaultOutputDir: ".")
|
|
|
|
#expect(config.packages.count == 1)
|
|
#expect(config.packages[0].objects.count == 2)
|
|
|
|
if case .object(let name, let overrides) = config.packages[0].objects[0] {
|
|
#expect(name == "Gtk.Legacy")
|
|
#expect(overrides.status == .ignore)
|
|
} else {
|
|
Issue.record("Expected .object config for first entry")
|
|
}
|
|
|
|
if case .object(let name, let overrides) = config.packages[0].objects[1] {
|
|
#expect(name == "Gtk.Widget")
|
|
#expect(overrides.concurrency == .mainActor)
|
|
} else {
|
|
Issue.record("Expected .object config for second entry")
|
|
}
|
|
}
|
|
|
|
@Test func rejectsMissingGir() throws {
|
|
let dict: [String: Any] = [
|
|
"packages": [
|
|
"Broken": [
|
|
"concurrency": "mainActor",
|
|
],
|
|
],
|
|
]
|
|
do {
|
|
_ = try MonorepoConfig.from(toml: dict, defaultOutputDir: ".")
|
|
Issue.record("Expected error for missing gir")
|
|
} catch {
|
|
// Expected
|
|
}
|
|
}
|
|
|
|
@Test func usesDefaultOutputDirWhenNotSpecified() throws {
|
|
let dict: [String: Any] = [
|
|
"packages": [
|
|
"Gtk": ["gir": "/usr/share/gir-1.0/Gtk-4.0.gir"],
|
|
],
|
|
]
|
|
|
|
let config = try MonorepoConfig.from(toml: dict, defaultOutputDir: "/custom/output")
|
|
|
|
#expect(config.outputDir == "/custom/output")
|
|
}
|
|
|
|
@Test func preservesSortedOrder() throws {
|
|
let dict: [String: Any] = [
|
|
"packages": [
|
|
"Zeta": ["gir": "/z"],
|
|
"Alpha": ["gir": "/a"],
|
|
],
|
|
]
|
|
|
|
let config = try MonorepoConfig.from(toml: dict, defaultOutputDir: ".")
|
|
|
|
#expect(config.packages.count == 2)
|
|
#expect(config.packages[0].name == "Alpha")
|
|
#expect(config.packages[1].name == "Zeta")
|
|
}
|
|
}
|