57 lines
1.6 KiB
Swift
57 lines
1.6 KiB
Swift
import Testing
|
|
@_spi(SGTKInternal) import Gtk
|
|
@_spi(Portico) import Portico
|
|
|
|
@MainActor @Suite struct TeardownTests {
|
|
|
|
// MARK: - No GTK needed
|
|
|
|
@Test func nodeRegistryCancelsTokens() {
|
|
let box = StateBox(0)
|
|
var count = 0
|
|
let registry = NodeRegistry()
|
|
registry.add(box.subscribe { _ in count += 1 })
|
|
box.set(1)
|
|
#expect(count == 1)
|
|
registry.teardown()
|
|
box.set(2)
|
|
#expect(count == 1)
|
|
}
|
|
|
|
@Test func trackerTeardownStopsReevaluation() {
|
|
let box = StateBox(0)
|
|
var evaluateCount = 0
|
|
let tracker = DependencyTracker { _ = box.get(); evaluateCount += 1 }
|
|
tracker.run()
|
|
#expect(evaluateCount == 1)
|
|
box.set(1)
|
|
#expect(evaluateCount == 2)
|
|
tracker.teardown()
|
|
box.set(2)
|
|
#expect(evaluateCount == 2)
|
|
}
|
|
|
|
@Test func nodeRegistryTeardownIsIdempotent() {
|
|
let box = StateBox(0)
|
|
var count = 0
|
|
let registry = NodeRegistry()
|
|
registry.add(box.subscribe { _ in count += 1 })
|
|
box.set(1)
|
|
#expect(count == 1)
|
|
registry.teardown()
|
|
registry.teardown() // must not crash
|
|
box.set(2)
|
|
#expect(count == 1)
|
|
}
|
|
|
|
// MARK: - GTK-dependent
|
|
|
|
@Test(.serialized) func nodeRegistryDisconnectsSignalHandle() {
|
|
guard Gtk.initCheck() else { return }
|
|
let button = Gtk.Button(label: "test")
|
|
let ctx = MountContext()
|
|
ctx.registry.add(button.connectClicked { _ in })
|
|
// Teardown must not crash with a real SignalHandle.
|
|
ctx.registry.teardown()
|
|
}
|
|
}
|