Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103import Foundationimport Testing
@testable import ParcelDev
struct DevSupportTests { @Test func processPreservesStatusAndBothStreams() throws { let result = try DevProcess.run("/bin/bash", ["-c", "printf output; printf failure >&2; exit 17"]) #expect(result.status == 17) #expect(result.output == "output") #expect(result.errorOutput == "failure") #expect(throws: DevError.self) { try DevProcess.checked("/bin/bash", ["-c", "exit 3"]) } } @Test func processInputCannotDeadlockLargeOutput() throws { let input = Data(repeating: 65, count: 256_000) let result = try DevProcess.run("/bin/cat", [], input: input) #expect(result.status == 0) #expect(result.stdout == input) } @Test func processHonorsDirectoryAndEnvironment() throws { let result = try DevProcess.run( "/bin/bash", ["-c", "printf '%s:%s' \"$PWD\" \"$VALUE\""], directory: URL(fileURLWithPath: "/"), environment: ["VALUE": "explicit"]) #expect(result.output == "/:explicit") } @Test func jsonRoundTripsEveryShapeAndRejectsMalformedInput() throws { let value: DevJSON = .object(["list": .array([.string("text"), .number(1.5), .bool(true), .null])]) #expect(try DevJSON.decode(value.encoded()) == value) #expect(throws: (any Error).self) { try DevJSON.decode(Data("[broken".utf8)) } #expect(throws: DevError.self) { try DevJSON.bool(false).requireString() } } @Test func omittedProcessEnvironmentInheritsPath() throws { let expected = try #require(ProcessInfo.processInfo.environment["PATH"]) let result = try DevProcess.run("/usr/bin/env", []) let path = try #require(result.output.components(separatedBy: .newlines).first { $0.hasPrefix("PATH=") }) #expect(String(path.dropFirst(5)) == expected) }
@Test func productSettingsAreDataAndCannotExecuteCommands() throws { let root = FileManager.default.temporaryDirectory.appendingPathComponent("parcel-product-\(UUID())") let scripts = root.appendingPathComponent("Scripts") try FileManager.default.createDirectory(at: scripts, withIntermediateDirectories: true) defer { do { try FileManager.default.removeItem(at: root) } catch { Issue.record("Could not remove product fixture: \(error)") } } let settings = scripts.appendingPathComponent("product.env") try "export PRODUCT_TEST_TOOL_VALUE='literal value'\n".write(to: settings, atomically: true, encoding: .utf8) #expect(try DevProduct.read(root: root).require("PRODUCT_TEST_TOOL_VALUE") == "literal value") #expect(throws: DevError.self) { try DevProduct.read(root: root).require("MISSING") } let marker = root.appendingPathComponent("executed") for value in ["$(touch \(marker.path))", "`touch \(marker.path)`", "\"$HOME\"", "invalid; exit 0"] { try "export PRODUCT_TEST_TOOL_VALUE=\(value)\n".write(to: settings, atomically: true, encoding: .utf8) #expect(throws: DevError.self) { try DevProduct.read(root: root) } #expect(!FileManager.default.fileExists(atPath: marker.path)) } }
@Test func nameWordsKeepUnicodeAndFoldOnceWithoutSplittingIdentifiers() { let words = NameScanner.words(Array("alpha_BETA Élan42 123 loadName quorvex\u{301}".unicodeScalars)) #expect(words.map(\.value) == ["alpha", "BETA", "Élan42", "123", "loadName", "quorvex"]) #expect(words.map(\.folded) == ["alpha", "beta", "élan42", "123", "loadname", "quorvex"]) }
@Test func hexEncodingPreservesEveryByteAndEmptyInput() { #expect(DevHex.string([UInt8]()) == "") #expect(DevHex.string([UInt8(0), 15, 16, 255]) == "000f10ff") #expect(DevHex.string(UInt8.min...UInt8.max).count == 512) }
@Test func processFilesArePrivateAndRemovedAfterSuccessOrInspectionFailure() throws { var prepared: URL? let result = try DevProcess.run("/bin/cat", [], input: Data("private input".utf8)) { directory in prepared = directory func permissions(_ path: URL) throws -> Int { let attributes = try FileManager.default.attributesOfItem(atPath: path.path) return try #require(attributes[.posixPermissions] as? NSNumber).intValue } let directoryMode = try permissions(directory) #expect(directoryMode == 0o700) for name in ["stdin", "stdout", "stderr"] { let fileMode = try permissions(directory.appendingPathComponent(name)) #expect(fileMode == 0o600) } } #expect(result.output == "private input") #expect(!FileManager.default.fileExists(atPath: try #require(prepared).path)) #expect(throws: DevError.self) { try DevProcess.run("/bin/cat", [], input: Data()) { directory in prepared = directory throw DevError("Inspection failed") } } #expect(!FileManager.default.fileExists(atPath: try #require(prepared).path)) }
@Test func unknownCommandsFail() { #expect(throws: DevError.self) { try ParcelDev.run([]) } #expect(throws: DevError.self) { try ParcelDev.run(["unknown"]) } }}