Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283import Foundationimport Testing
@testable import ParcelDev
struct SetupToolsTests { private let config = URL(fileURLWithPath: "/tmp/tool-fixture/mise.toml")
private func version( requested: String = "1.2.3", installed: DevJSON = .bool(false), path: String = "/tmp/tool-fixture/mise.toml" ) -> DevJSON { .object([ "requested_version": .string(requested), "installed": installed, "source": .object(["path": .string(path)]), ]) }
@Test func installsOnlyCurrentConfigPins() throws { let tools = DevJSON.object([ "aqua:fixture/tool": .array([version(), version(requested: "2.3.4", installed: .bool(true))]), "node": .array([version(requested: "latest", path: "/global/mise.toml")]), ]) #expect(try SetupTools.pins(in: tools, config: config) == .init(count: 2, missing: ["aqua:fixture/tool@1.2.3"])) }
@Test func installedPinsNeedNoInstallation() throws { let tools = DevJSON.object(["tool": .array([version(installed: .bool(true))])]) #expect(try SetupTools.pins(in: tools, config: config) == .init(count: 1, missing: [])) }
@Test func normalizesSourcePathsAndOrdersInstallRequests() throws { let tools = DevJSON.object([ "z": .array([version(path: "/tmp/tool-fixture/../tool-fixture/mise.toml")]), "a": .array([version()]), ]) #expect(try SetupTools.pins(in: tools, config: config).missing == ["a@1.2.3", "z@1.2.3"]) }
@Test func resolvesSymlinkedConfigSources() throws { let directory = FileManager.default.temporaryDirectory.appendingPathComponent("setup-tools-\(UUID())") try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: false) defer { do { try FileManager.default.removeItem(at: directory) } catch { Issue.record(error) } } let config = directory.appendingPathComponent("mise.toml") let alias = directory.appendingPathComponent("alias.toml") try Data("[tools]\n".utf8).write(to: config) try FileManager.default.createSymbolicLink(at: alias, withDestinationURL: config) let tools = DevJSON.object(["tool": .array([version(path: alias.path)])]) #expect(try SetupTools.pins(in: tools, config: config).missing == ["tool@1.2.3"]) }
@Test(arguments: ["latest", "1.2", "1.2.3-beta", "v1.2.3", "1.2.3\n", "١.٢.٣"]) func rejectsNonExactPins(requested: String) { let tools = DevJSON.object(["tool": .array([version(requested: requested)])]) #expect(throws: DevError.self) { try SetupTools.pins(in: tools, config: config) } }
@Test(arguments: [DevJSON.string("false"), .number(0), .null]) func rejectsCoercedInstalledState(installed: DevJSON) { let tools = DevJSON.object(["tool": .array([version(installed: installed)])]) #expect(throws: DevError.self) { try SetupTools.pins(in: tools, config: config) } }
@Test func rejectsNoCurrentPinsAndMalformedStructures() { let fixtures: [DevJSON] = [ .object([:]), .array([]), .object(["tool": .object([:])]), .object(["tool": .array([version(path: "/global/mise.toml")])]), .object(["tool": .array([.object(["source": .object([:])])])]), .object(["tool": .array([.object(["source": .object(["path": .null])])])]), .object(["tool": .array([.object(["source": .string("invalid")])])]), ] for fixture in fixtures { #expect(throws: DevError.self) { try SetupTools.pins(in: fixture, config: config) } } }
@Test func rejectsUnexpectedArguments() { #expect(throws: DevError.self) { try SetupTools.run(command: "unknown", args: []) } #expect(throws: DevError.self) { try SetupTools.run(command: "install-tools", args: ["unexpected"]) } }}