// REPLLauncherTests.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Testing import Foundation @testable import LyrebirdCLI @Suite("REPLLauncher") struct REPLLauncherTests { @Test func swiftBinaryExists() throws { let path: String = try REPLLauncher.findSwift() #expect(FileManager.default.isExecutableFile(atPath: path)) } @Test func buildArgumentsAreSwiftBuild() { // The REPL launch first runs `swift build` so .build/debug artifacts exist // before the REPL is started. #expect(REPLLauncher.buildArguments == ["build"]) } @Test func replArgumentsPointAtBuildArtifacts() { // `swift package repl` was removed from the toolchain. The replacement is // `swift repl` with -I/-L flags pointing at the package's .build/debug. let args: [String] = REPLLauncher.replArguments #expect(args.first == "repl") #expect(args.contains("-I")) #expect(args.contains("-L")) #expect(args.contains(".build/debug/Modules")) #expect(args.contains(".build/debug/LyrebirdC.build")) #expect(args.contains(".build/debug")) #expect(args.contains("-lLyrebird")) } @Test func buildThrowsBuildFailedWhenNoPackageManifest() throws { // Running `swift build` in a directory with no `Package.swift` exits // non-zero. `build(in:)` should surface that as `CLIError.buildFailed` // with a non-zero `exitCode`. let tempDir: URL = FileManager.default.temporaryDirectory.appendingPathComponent( "lyrebird-repl-build-failure-\(UUID().uuidString)" ) try FileManager.default.createDirectory(at: tempDir, withIntermediateDirectories: true) defer { try? FileManager.default.removeItem(at: tempDir) } var thrown: CLIError? do { try REPLLauncher.build(in: tempDir.path) } catch let error as CLIError { thrown = error } guard case .buildFailed(let exitCode) = thrown else { Issue.record("build(in:) did not throw CLIError.buildFailed; got \(String(describing: thrown))") return } #expect(exitCode != 0) } @Test func historyFilePathEndsWithLyrebirdHistory() { #expect(REPLLauncher.historyFilePath.hasSuffix(".lyrebird_history")) } @Test func historyFilePathIsInHomeDirectory() { let home: String = FileManager.default.homeDirectoryForCurrentUser.path #expect(REPLLauncher.historyFilePath.hasPrefix(home)) } @Test func processURLMatchesFindSwift() throws { let swiftPath: String = try REPLLauncher.findSwift() let processURL: URL? = try REPLLauncher.makeProcess().executableURL #expect(processURL == URL(fileURLWithPath: swiftPath)) } @Test func processArgumentsMatchReplArguments() throws { let process: Process = try REPLLauncher.makeProcess() #expect(process.arguments == REPLLauncher.replArguments) } @Test func buildProcessArgumentsMatchBuildArguments() throws { let process: Process = try REPLLauncher.makeProcess(arguments: REPLLauncher.buildArguments) #expect(process.arguments == REPLLauncher.buildArguments) } }