1
0
Fork 0

Add MultiPackageAnalyzer dependency resolution tests

This commit is contained in:
Brendan Szymanski 2026-07-01 20:44:30 -04:00
parent f61a63f167
commit 7ce28c0ba8

View file

@ -0,0 +1,91 @@
import Foundation
import Testing
@testable import SwiftGtkGenCore
@Suite("MultiPackageAnalyzer")
struct MultiPackageAnalysisTests {
/// Builds a minimal multi-package config from mock GIR XML.
private func buildConfig() throws -> MonorepoConfig {
let tmpDir = NSTemporaryDirectory() + "monorepo_test_\(UUID().uuidString)"
try FileManager.default.createDirectory(atPath: tmpDir, withIntermediateDirectories: true)
// GLib: root, no includes (real GLib GIR has no <include> elements)
let glibGIR = """
<?xml version="1.0"?>
<repository version="1.2"
xmlns="http://www.gtk.org/introspection/core/1.0"
xmlns:c="http://www.gtk.org/introspection/c/1.0"
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<c:include name="glib.h"/>
<package name="glib-2.0"/>
<namespace name="GLib" version="2.0"
shared-library="libglib-2.0.so.0"
c:identifier-prefixes="G">
<class name="Object" c:type="GObject" parent="GObject.InitiallyUnowned"
glib:type-name="GObject" glib:get-type="g_object_get_type"/>
<enumeration name="TestEnum" glib:type-name="GTestEnum"
glib:get-type="g_test_enum_get_type" c:type="GTestEnum">
<member name="value" value="0" c:identifier="G_TEST_ENUM_VALUE"/>
</enumeration>
</namespace>
</repository>
"""
let glibPath = tmpDir + "/GLib-2.0.gir"
try glibGIR.write(toFile: glibPath, atomically: true, encoding: .utf8)
// GObject: includes GLib
let gobjectGIR = """
<?xml version="1.0"?>
<repository version="1.2"
xmlns="http://www.gtk.org/introspection/core/1.0"
xmlns:c="http://www.gtk.org/introspection/c/1.0"
xmlns:glib="http://www.gtk.org/introspection/glib/1.0">
<include name="GLib" version="2.0"/>
<c:include name="glib-object.h"/>
<package name="gobject-2.0"/>
<namespace name="GObject" version="2.0"
shared-library="libgobject-2.0.so.0"
c:identifier-prefixes="G">
<class name="InitiallyUnowned" c:type="GInitiallyUnowned"
parent="GObject.Object" glib:type-name="GInitiallyUnowned"
glib:get-type="g_initially_unowned_get_type"/>
<class name="ParamSpec" c:type="GParamSpec" parent="GObject.InitiallyUnowned"
glib:type-name="GParamSpec" glib:get-type="g_param_spec_get_type"/>
</namespace>
</repository>
"""
let gobjPath = tmpDir + "/GObject-2.0.gir"
try gobjectGIR.write(toFile: gobjPath, atomically: true, encoding: .utf8)
let packages: [PackageEntry] = [
PackageEntry(name: "GLib", girPath: glibPath),
PackageEntry(name: "GObject", girPath: gobjPath),
]
return MonorepoConfig(outputDir: tmpDir, packages: packages)
}
@Test func resolvesDependencyGraph() throws {
let config = try buildConfig()
let analyzer = MultiPackageAnalyzer(config: config)
let analysis = try analyzer.analyze()
#expect(analysis.repositories.count == 2)
#expect(analysis.directDependencies["GLib"] == [])
#expect(analysis.directDependencies["GObject"]?.contains("GLib") == true)
#expect(analysis.transitiveDependencies["GObject"]?.contains("GLib") == true)
#expect(analysis.transitiveDependencies["GLib"]?.isEmpty == true)
}
@Test func generatesPerPackageConfigs() throws {
let config = try buildConfig()
let analyzer = MultiPackageAnalyzer(config: config)
let analysis = try analyzer.analyze()
#expect(analysis.packageConfigs["GLib"]?.library == "GLib")
// GObject depends on GLib
let gobjExtLibs = analysis.packageConfigs["GObject"]?.externalLibraries
#expect(gobjExtLibs?.contains("GLib") == true)
}
}