90 lines
3.5 KiB
Swift
90 lines
3.5 KiB
Swift
// LiveSessionDiagnosticsTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
@testable import LyrebirdLiveCompile
|
|
|
|
#if os(macOS)
|
|
|
|
@Suite("LiveSession diagnostics")
|
|
struct LiveSessionDiagnosticsTests {
|
|
|
|
private func makeEngine() -> SynthesisEngine {
|
|
SynthesisEngine(
|
|
blockSize: 64,
|
|
controlBlockSize: 16,
|
|
sampleRate: 48_000,
|
|
numOutputChannels: 2,
|
|
numInputChannels: 0,
|
|
numAudioBuses: 16,
|
|
numControlBuses: 16,
|
|
eventQueueCapacity: lyrebirdDefaultEventQueueCapacity,
|
|
driver: OfflineDriver()
|
|
)
|
|
}
|
|
|
|
@Test
|
|
func typeErrorYieldsDiagnosticOnUserLine() throws {
|
|
let engine: SynthesisEngine = makeEngine()
|
|
let session: LiveSession = LiveSession(engine: engine)
|
|
// First user-body line forces a Swift type error; line should map to 1.
|
|
let body: String = "let _: Int = \"nope\""
|
|
do {
|
|
_ = try session.compileAndRun(body)
|
|
Issue.record("expected snippetCompileFailed")
|
|
return
|
|
} catch let LiveSessionError.snippetCompileFailed(diagnostics, _) {
|
|
let errors: [Diagnostic] = diagnostics.filter { $0.severity == .error }
|
|
try #require(!errors.isEmpty)
|
|
// The first reported error should land on user line 1.
|
|
#expect(errors.first?.line == 1)
|
|
} catch {
|
|
Issue.record("expected snippetCompileFailed, got \(error)")
|
|
}
|
|
}
|
|
|
|
@Test
|
|
func compilerErrorWrapsUnderlyingForNonCompileFailures() {
|
|
// Force a non-compile error by pointing at a build dir that doesn't exist.
|
|
// The Phase 142 compile path still succeeds (a swiftc invocation with -I
|
|
// pointing at a missing dir surfaces as `compileFailed` via swiftc's own
|
|
// "no such module" — not `compilerError`). Instead, drive a real
|
|
// compilerError case by routing through a LiveCompileError that isn't
|
|
// `compileFailed`. The simplest reachable non-`compileFailed` path is
|
|
// entrySymbolMissing — but a real run with full build dir succeeds.
|
|
// We just verify the type LiveSessionError.compilerError exists and is
|
|
// representable; behavioural coverage of non-compileFailed cases is
|
|
// exercised at the LiveCompiler layer (Phase 142 tests).
|
|
let err: LiveSessionError = LiveSessionError.compilerError(.swiftcNotFound)
|
|
#expect(String(describing: err).contains("swiftc"))
|
|
}
|
|
|
|
@Test
|
|
func diagnosticsContainColumnInformation() throws {
|
|
let engine: SynthesisEngine = makeEngine()
|
|
let session: LiveSession = LiveSession(engine: engine)
|
|
let body: String = "let _: Int = \"nope\""
|
|
do {
|
|
_ = try session.compileAndRun(body)
|
|
Issue.record("expected snippetCompileFailed")
|
|
return
|
|
} catch let LiveSessionError.snippetCompileFailed(diagnostics, _) {
|
|
let errors: [Diagnostic] = diagnostics.filter { $0.severity == .error }
|
|
try #require(!errors.isEmpty)
|
|
// Column should be > 0 (1-based). We don't pin the exact column —
|
|
// swiftc may report on the literal or the assignment depending on
|
|
// version — but it must be positive.
|
|
#expect((errors.first?.column ?? 0) > 0)
|
|
} catch {
|
|
Issue.record("expected snippetCompileFailed, got \(error)")
|
|
}
|
|
}
|
|
}
|
|
|
|
#endif
|