Skip to content

Free fork of NotProton: Windows Steam games in Mac Steam, on CodeWeavers' Wine and Apple's Game Porting Toolkit

Share one scratch directory helper between the tests

NotProtonNot2d2e013d13dd
diff --git a/app/Tests/NotProtonAppTests/BridgePayloadTests.swift b/app/Tests/NotProtonAppTests/BridgePayloadTests.swift
index 42735f4..c8904dd 100644
--- a/app/Tests/NotProtonAppTests/BridgePayloadTests.swift
+++ b/app/Tests/NotProtonAppTests/BridgePayloadTests.swift
@@ -6,12 +6,6 @@ import Testing
@Suite("Bridge payload")
struct BridgePayloadTests {
- private func scratch() throws -> URL {
- let url = URL.temporaryDirectory.appending(path: "np-bridge-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
- }
-
private func fakeResources(in work: URL) throws -> URL {
let root = work.appending(path: "bridge")
try FileManager.default.createDirectory(at: root, withIntermediateDirectories: true)
@@ -25,7 +19,7 @@ struct BridgePayloadTests {
@Test("Locate finds all four resources when present")
func locateFindsAll() throws {
- let work = try scratch()
+ let work = try scratchDirectory("bridge")
defer { try? FileManager.default.removeItem(at: work) }
let root = try fakeResources(in: work)
@@ -35,7 +29,7 @@ struct BridgePayloadTests {
@Test("Locate reports missing resources rather than silently staging nothing")
func locateReportsMissing() throws {
- let work = try scratch()
+ let work = try scratchDirectory("bridge")
defer { try? FileManager.default.removeItem(at: work) }
let root = work.appending(path: "empty-bridge")
@@ -46,7 +40,7 @@ struct BridgePayloadTests {
@Test("Stage writes all six bridge paths from four resources")
func stageWritesAll() throws {
- let work = try scratch()
+ let work = try scratchDirectory("bridge")
defer { try? FileManager.default.removeItem(at: work) }
let root = try fakeResources(in: work)
@@ -68,7 +62,7 @@ struct BridgePayloadTests {
@Test("Files at the correct size are left alone on a second run")
func skipsMatchingSize() throws {
- let work = try scratch()
+ let work = try scratchDirectory("bridge")
defer { try? FileManager.default.removeItem(at: work) }
let root = try fakeResources(in: work)
@@ -86,7 +80,7 @@ struct BridgePayloadTests {
@Test("Flat and arch copies are byte-identical")
func duplicatesMatch() throws {
- let work = try scratch()
+ let work = try scratchDirectory("bridge")
defer { try? FileManager.default.removeItem(at: work) }
let root = try fakeResources(in: work)
diff --git a/app/Tests/NotProtonAppTests/InstallPayloadTests.swift b/app/Tests/NotProtonAppTests/InstallPayloadTests.swift
index 63267cd..d069d84 100644
--- a/app/Tests/NotProtonAppTests/InstallPayloadTests.swift
+++ b/app/Tests/NotProtonAppTests/InstallPayloadTests.swift
@@ -6,12 +6,6 @@ import Testing
@Suite("Install payload")
struct InstallPayloadTests {
- private func scratch() throws -> URL {
- let url = URL.temporaryDirectory.appending(path: "np-payload-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
- }
-
private func stage(_ root: URL, dylib: Bool = true, shim: Bool = true, iconmaker: Bool = true, appinfo: Bool = true, signatures: [String] = ["1788400362.json"]) throws {
let files = FileManager.default
let signatureDir = root.appending(path: "signatures/macos.arm64")
@@ -48,7 +42,7 @@ struct InstallPayloadTests {
@Test("Every signature database in the payload is found, in a stable order")
func findsAllSignatureDatabases() throws {
- let root = try scratch()
+ let root = try scratchDirectory("payload")
defer { try? FileManager.default.removeItem(at: root) }
try stage(root, signatures: ["1788652215.json", "1788400362.json", "notes.txt"])
@@ -59,7 +53,7 @@ struct InstallPayloadTests {
@Test("A payload missing an artifact says which one and how to fix it")
func reportsMissingArtifacts() throws {
- let root = try scratch()
+ let root = try scratchDirectory("payload")
defer { try? FileManager.default.removeItem(at: root) }
try stage(root, dylib: false)
@@ -75,7 +69,7 @@ struct InstallPayloadTests {
@Test("A payload with no signature database is refused")
func refusesPayloadWithoutSignatures() throws {
- let root = try scratch()
+ let root = try scratchDirectory("payload")
defer { try? FileManager.default.removeItem(at: root) }
try stage(root, signatures: [])
@@ -89,7 +83,7 @@ struct InstallPayloadTests {
@Test("An empty payload names every missing artifact")
func reportsEverythingMissing() throws {
- let root = try scratch()
+ let root = try scratchDirectory("payload")
defer { try? FileManager.default.removeItem(at: root) }
try stage(root, dylib: false, shim: false, iconmaker: false, appinfo: false, signatures: [])
diff --git a/app/Tests/NotProtonAppTests/MachOBuildTests.swift b/app/Tests/NotProtonAppTests/MachOBuildTests.swift
index 72f0fcc..7a2dbdc 100644
--- a/app/Tests/NotProtonAppTests/MachOBuildTests.swift
+++ b/app/Tests/NotProtonAppTests/MachOBuildTests.swift
@@ -6,12 +6,6 @@ import Testing
@Suite("Mach-O build identity")
struct MachOBuildTests {
- private func scratch() throws -> URL {
- let url = URL.temporaryDirectory.appending(path: "np-macho-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
- }
-
private func dylib(_ body: String, in work: URL, named name: String) throws -> URL {
let source = work.appending(path: "\(name).c")
try Data(body.utf8).write(to: source)
@@ -25,7 +19,7 @@ struct MachOBuildTests {
@Test("Signing a binary does not change which build it is")
func signingPreservesIdentity() throws {
- let work = try scratch()
+ let work = try scratchDirectory("macho")
defer { try? FileManager.default.removeItem(at: work) }
let built = try dylib("int np_probe(void) { return 1; }\n", in: work, named: "probe")
@@ -41,7 +35,7 @@ struct MachOBuildTests {
@Test("Two different builds are told apart")
func differentBuildsDiffer() throws {
- let work = try scratch()
+ let work = try scratchDirectory("macho")
defer { try? FileManager.default.removeItem(at: work) }
let one = try dylib("int np_probe(void) { return 1; }\n", in: work, named: "one")
@@ -52,7 +46,7 @@ struct MachOBuildTests {
@Test("A universal binary is identified by every slice it carries")
func universalBinaryReportsBothSlices() throws {
- let work = try scratch()
+ let work = try scratchDirectory("macho")
defer { try? FileManager.default.removeItem(at: work) }
let source = work.appending(path: "fat.c")
@@ -77,7 +71,7 @@ struct MachOBuildTests {
@Test("Something that is not a binary has no build identity")
func rubbishHasNoIdentity() throws {
- let work = try scratch()
+ let work = try scratchDirectory("macho")
defer { try? FileManager.default.removeItem(at: work) }
let text = work.appending(path: "notes.txt")
diff --git a/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift b/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift
index 13beb9e..0ee6cd1 100644
--- a/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift
+++ b/app/Tests/NotProtonAppTests/PinnedDownloadTests.swift
@@ -16,13 +16,6 @@ struct PinnedDownloadTests {
var all: [String] { lock.lock(); defer { lock.unlock() }; return seen }
}
- private func scratch() throws -> URL {
- let url = FileManager.default.temporaryDirectory
- .appending(path: "notproton-pinned-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
- }
-
// A host directory holding one file under the name the download asks for.
private func host(_ root: URL, named: String, serving bytes: String) throws -> URL {
let dir = root.appending(path: "host-\(UUID().uuidString)")
@@ -41,7 +34,7 @@ struct PinnedDownloadTests {
@Test("Bytes that match the pin are kept")
func keepsMatchingBytes() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("pinned")
defer { try? FileManager.default.removeItem(at: work) }
let body = "the real package"
@@ -57,7 +50,7 @@ struct PinnedDownloadTests {
@Test("Bytes that do not match the pin are refused and nothing is left behind")
func refusesMismatchedBytes() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("pinned")
defer { try? FileManager.default.removeItem(at: work) }
let serving = try host(work, named: "package.tar", serving: "a substituted package")
@@ -80,7 +73,7 @@ struct PinnedDownloadTests {
@Test("A host serving the wrong bytes is passed over for one that does not")
func fallsThroughToAHonestHost() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("pinned")
defer { try? FileManager.default.removeItem(at: work) }
let body = "the real package"
@@ -97,7 +90,7 @@ struct PinnedDownloadTests {
@Test("An archive already on disk that matches is not fetched again")
func reusesMatchingArchive() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("pinned")
defer { try? FileManager.default.removeItem(at: work) }
let body = "the real package"
@@ -124,7 +117,7 @@ struct PinnedDownloadTests {
// survive into the label: a fallthrough to a second host is only visible through it.
@Test("A fetch reports the host the bytes came from")
func reportsTheHostFetchedFrom() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("pinned")
defer { try? FileManager.default.removeItem(at: work) }
let body = "the real package"
diff --git a/app/Tests/NotProtonAppTests/PrefixStoreTests.swift b/app/Tests/NotProtonAppTests/PrefixStoreTests.swift
index 92d313e..97a823a 100644
--- a/app/Tests/NotProtonAppTests/PrefixStoreTests.swift
+++ b/app/Tests/NotProtonAppTests/PrefixStoreTests.swift
@@ -6,12 +6,6 @@ import Testing
@Suite("Prefix store")
struct PrefixStoreTests {
- private func tempDirectory() throws -> URL {
- let dir = FileManager.default.temporaryDirectory.appending(path: "np-pfx-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
- return dir
- }
-
private func write(_ text: String, to url: URL) throws {
try FileManager.default.createDirectory(
at: url.deletingLastPathComponent(), withIntermediateDirectories: true)
@@ -20,7 +14,7 @@ struct PrefixStoreTests {
@Test("Every library path in the file is found, in order, without duplicates")
func readsLibraryPaths() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
// Shaped like the real file: nested blocks, tab separated, an apps block whose
@@ -58,7 +52,7 @@ struct PrefixStoreTests {
@Test("A missing or empty file still yields the default library")
func fallsBackToTheDefaultLibrary() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let missing = PrefixStore.libraries(vdf: dir.appending(path: "nothing.vdf"))
@@ -72,7 +66,7 @@ struct PrefixStoreTests {
@Test("An entry without a pfx is not a prefix")
func skipsEntriesWithoutAPrefix() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
@@ -91,7 +85,7 @@ struct PrefixStoreTests {
@Test("A name comes from the library's own appmanifest, and its absence is not a failure")
func readsTheAppName() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
@@ -122,7 +116,7 @@ struct PrefixStoreTests {
@Test("Sizing a prefix stops at a symlink instead of walking through it")
func doesNotFollowLinksOutOfThePrefix() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
@@ -147,7 +141,7 @@ struct PrefixStoreTests {
@Test("Only the parked prefixes count as backups")
func backupsIgnoreEverythingElseInTheEntry() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
let fm = FileManager.default
@@ -168,7 +162,7 @@ struct PrefixStoreTests {
@Test("Backing up a prefix copies it into a listed slot and leaves the prefix alone")
func backUpCopiesTheLivePrefix() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let prefix = try prefix(in: dir)
try write("save", to: prefix.pfx.appending(path: "user.reg"))
@@ -187,7 +181,7 @@ struct PrefixStoreTests {
@Test("Backing up refuses a game that has never made a prefix")
func backUpRefusesAMissingPrefix() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let prefix = try prefix(in: dir)
try FileManager.default.removeItem(at: prefix.pfx)
@@ -200,7 +194,7 @@ struct PrefixStoreTests {
@Test("A backup carries the time in its name back out as a date")
func backupDetailsReadTheStamp() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
@@ -224,7 +218,7 @@ struct PrefixStoreTests {
@Test("A parked prefix with no readable stamp still lists, without a date")
func backupWithoutAStampHasNoDate() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
@@ -242,7 +236,7 @@ struct PrefixStoreTests {
@Test("A library on the boot volume is named by its folder alone")
func bootVolumeLibraryIsNotQualified() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = PrefixStore.library(at: dir)
@@ -264,7 +258,7 @@ struct PrefixStoreTests {
@Test("A prefix points at the game's install folder while the game is installed")
func findsTheInstallDirectory() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
@@ -317,7 +311,7 @@ struct PrefixStoreTests {
// and carries no PROCESSOR_ARCHITECTURE, so the wrong flavor is invisible without a PE read.
@Test("A prefix names the compatibility tool that built it through its own ntdll")
func readsPrefixArch() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let prefix = try prefix(in: dir)
@@ -335,7 +329,7 @@ struct PrefixStoreTests {
// demanded on the strength of a header that was never read.
@Test("An unreadable header is no arch rather than a wrong one")
func unreadableArchIsNil() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let prefix = try prefix(in: dir)
@@ -370,7 +364,7 @@ struct PrefixStoreTests {
@Test("An idle prefix is not reported as in use")
func idlePrefixIsNotInUse() throws {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
defer { try? FileManager.default.removeItem(at: dir) }
let library = SteamLibrary(root: dir)
try FileManager.default.createDirectory(
@@ -386,7 +380,7 @@ struct PrefixStoreTests {
// Everything below needs the socket directory to be there, since a prefix whose directory
// is absent is answered before lsof is reached at all.
private func prefixWithServerDirectory() throws -> (WinePrefix, URL, URL) {
- let dir = try tempDirectory()
+ let dir = try scratchDirectory("pfx")
let library = SteamLibrary(root: dir)
try FileManager.default.createDirectory(
at: library.compatdata.appending(path: "1574480/pfx"), withIntermediateDirectories: true)
diff --git a/app/Tests/NotProtonAppTests/RunnerSetupTests.swift b/app/Tests/NotProtonAppTests/RunnerSetupTests.swift
index 128003a..c319681 100644
--- a/app/Tests/NotProtonAppTests/RunnerSetupTests.swift
+++ b/app/Tests/NotProtonAppTests/RunnerSetupTests.swift
@@ -5,19 +5,13 @@ import Testing
// Scratch directories rather than the live runner, so these say the same thing on a
// machine that has never had a clone made on it.
-private func scratchDirectory() throws -> URL {
- let url = FileManager.default.temporaryDirectory
- .appending(path: "notproton-setup-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
-}
@Suite("Clean copy resolution")
struct CleanTests {
@Test("The backup beside a file is preferred when it exists")
func backupWins() throws {
- let dir = try scratchDirectory()
+ let dir = try scratchDirectory("setup")
defer { try? FileManager.default.removeItem(at: dir) }
let live = dir.appending(path: "ntdll.dll")
@@ -30,7 +24,7 @@ struct CleanTests {
@Test("A file with no backup resolves to itself")
func noBackupResolvesToSelf() throws {
- let dir = try scratchDirectory()
+ let dir = try scratchDirectory("setup")
defer { try? FileManager.default.removeItem(at: dir) }
let live = dir.appending(path: "wine")
@@ -41,7 +35,7 @@ struct CleanTests {
@Test("The suffix is appended, not substituted for the extension")
func suffixIsAppended() throws {
- let dir = try scratchDirectory()
+ let dir = try scratchDirectory("setup")
defer { try? FileManager.default.removeItem(at: dir) }
let live = dir.appending(path: "ntdll.dll")
@@ -75,7 +69,7 @@ struct PatchInputTests {
}
private func makeRoot(live: Data, backup: Data?) throws -> URL {
- let root = try scratchDirectory()
+ let root = try scratchDirectory("setup")
let dir = root.appending(path: "lib/wine/x86_64-windows")
try FileManager.default.createDirectory(at: dir, withIntermediateDirectories: true)
try live.write(to: dir.appending(path: "ntdll.dll"))
@@ -113,7 +107,7 @@ struct PatchInputTests {
@Test("A missing ntdll is refused")
func missingIsRefused() throws {
- let root = try scratchDirectory()
+ let root = try scratchDirectory("setup")
defer { try? FileManager.default.removeItem(at: root) }
#expect(throws: StepFailure.self) {
@@ -127,7 +121,7 @@ struct ClonedPayloadTests {
@Test("An intact clone is recognised by the payload inside it")
func findsPayload() throws {
- let runners = try scratchDirectory()
+ let runners = try scratchDirectory("setup")
defer { try? FileManager.default.removeItem(at: runners) }
let payload = SupportPaths.clonedRoot(forBuild: "1.2.3.4", runners: runners)
@@ -140,7 +134,7 @@ struct ClonedPayloadTests {
@Test("A clone still shaped as an .app does not count as cloned")
func refusesBundleShapedClone() throws {
- let runners = try scratchDirectory()
+ let runners = try scratchDirectory("setup")
defer { try? FileManager.default.removeItem(at: runners) }
let clone = SupportPaths.runnerRoot(forBuild: "1.2.3.4", runners: runners)
@@ -154,7 +148,7 @@ struct ClonedPayloadTests {
@Test("A clone with no payload in it does not count as cloned")
func refusesCloneWithoutPayload() throws {
- let runners = try scratchDirectory()
+ let runners = try scratchDirectory("setup")
defer { try? FileManager.default.removeItem(at: runners) }
let clone = SupportPaths.runnerRoot(forBuild: "1.2.3.4", runners: runners)
diff --git a/app/Tests/NotProtonAppTests/SteamInstallerTests.swift b/app/Tests/NotProtonAppTests/SteamInstallerTests.swift
index db354f0..c89e421 100644
--- a/app/Tests/NotProtonAppTests/SteamInstallerTests.swift
+++ b/app/Tests/NotProtonAppTests/SteamInstallerTests.swift
@@ -8,12 +8,6 @@ import Testing
@Suite("Steam installer", .serialized)
struct SteamInstallerTests {
- private func scratch() throws -> URL {
- let url = URL.temporaryDirectory.appending(path: "np-install-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
- }
-
private func stockBundle(into work: URL) async throws -> URL {
let manifest = try ValvePackageManifest.bundled()
let bundle = try #require(manifest.bundle)
@@ -113,7 +107,7 @@ struct SteamInstallerTests {
@Test("A full install puts every artifact in place and declares the insert")
func installsEverything() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
let calls = Calls()
@@ -149,7 +143,7 @@ struct SteamInstallerTests {
@Test("Setting the insert keeps the rest of Valve's environment")
func preservesValveEnvironment() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
@@ -169,7 +163,7 @@ struct SteamInstallerTests {
@Test("The bundle is signed inner to outer, so every seal verifies afterwards")
func signsInnerToOuter() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
@@ -190,7 +184,7 @@ struct SteamInstallerTests {
@Test("An insert belonging to something else stops the install and is left alone")
func refusesForeignInsert() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
@@ -213,7 +207,7 @@ struct SteamInstallerTests {
@Test("Installing over an existing install is allowed and refreshes it")
func reinstallIsAllowed() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
@@ -232,7 +226,7 @@ struct SteamInstallerTests {
@Test("A failure while signing puts the plist back, so the bundle still starts")
func revertsInsertWhenSigningFails() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
@@ -259,7 +253,7 @@ struct SteamInstallerTests {
@Test("The plist backup records the state before the first install only")
func backsUpOriginalPlistOnce() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
@@ -274,7 +268,7 @@ struct SteamInstallerTests {
@Test("A missing Steam bundle is reported as its own condition")
func reportsMissingBundle() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
var fixture = try await self.fixture(into: work)
fixture = Fixture(
@@ -294,7 +288,7 @@ struct SteamInstallerTests {
// Straight at the probe, so neither of these needs a Valve bundle to be fetched first.
private func bundle(writable: Bool) throws -> URL {
- let app = try scratch().appending(path: "Steam.app")
+ let app = try scratchDirectory("install").appending(path: "Steam.app")
try FileManager.default.createDirectory(
at: app.appending(path: "Contents/MacOS"), withIntermediateDirectories: true
)
@@ -327,7 +321,7 @@ struct SteamInstallerTests {
// the user to grant a permission that had nothing to do with it.
@Test("A probe that fails for another reason keeps that reason")
func probeFailureKeepsItsOwnReason() throws {
- let app = try scratch().appending(path: "Steam.app")
+ let app = try scratchDirectory("install").appending(path: "Steam.app")
defer { try? FileManager.default.removeItem(at: app.deletingLastPathComponent()) }
let failure = try #require(throws: StepFailure.self) {
@@ -356,7 +350,7 @@ struct SteamInstallerTests {
@Test("A second account installs its own components without touching a patched Steam")
func secondAccountLeavesTheBundleAlone() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
let files = FileManager.default
@@ -396,7 +390,7 @@ struct SteamInstallerTests {
@Test("A Steam carrying a different build of the dylib is patched again")
func differentBuildIsPatched() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
@@ -424,7 +418,7 @@ struct SteamInstallerTests {
@Test("A payload with nothing in it stops the install before anything is touched")
func refusesEmptyPayload() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("install")
defer { try? FileManager.default.removeItem(at: work) }
let fixture = try await self.fixture(into: work)
diff --git a/app/Tests/NotProtonAppTests/SteamRepairTests.swift b/app/Tests/NotProtonAppTests/SteamRepairTests.swift
index 2dc6808..dc17d29 100644
--- a/app/Tests/NotProtonAppTests/SteamRepairTests.swift
+++ b/app/Tests/NotProtonAppTests/SteamRepairTests.swift
@@ -8,12 +8,6 @@ import Testing
@Suite("Steam repair", .serialized)
struct SteamRepairTests {
- private func scratch() throws -> URL {
- let url = URL.temporaryDirectory.appending(path: "np-repair-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
- }
-
private func stagedStockBundle(into work: URL) async throws -> URL {
let manifest = try ValvePackageManifest.bundled()
let bundle = try #require(manifest.bundle)
@@ -27,7 +21,7 @@ struct SteamRepairTests {
@Test("The pinned package unpacks to a bundle that is signed by Valve")
func stagesAValveSignedBundle() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let staged = try await stagedStockBundle(into: work)
@@ -48,7 +42,7 @@ struct SteamRepairTests {
// verifies strictly, so only the authority check catches it. Repair checks both.
@Test("An ad-hoc signed bundle is refused even though it verifies strictly")
func refusesAdHocSignedBundle() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let staged = try await stagedStockBundle(into: work)
@@ -68,7 +62,7 @@ struct SteamRepairTests {
// directories named after the fields repair looks for used to answer for them.
@Test("A path named after the expected fields cannot answer for them")
func refusesFieldsSuppliedByThePath() throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let nested = work
@@ -113,7 +107,7 @@ struct SteamRepairTests {
@Test("A bundle with an added file no longer matches its signature and is refused")
func refusesTamperedBundle() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let staged = try await stagedStockBundle(into: work)
@@ -144,7 +138,7 @@ struct SteamRepairTests {
@Test("Clearing the insert removes that key and nothing else")
func clearsOnlyTheInsert() throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let plist = work.appending(path: "Info.plist")
@@ -174,7 +168,7 @@ struct SteamRepairTests {
@Test("Clearing the insert reports nothing done when there is no plist or no insert")
func clearInsertIsQuietWhenThereIsNothingToDo() throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
#expect(try SteamRepair.clearInsert(at: work.appending(path: "absent.plist")) == false)
@@ -190,7 +184,7 @@ struct SteamRepairTests {
// test that hardcoded the name would still pass if the two diverged.
@Test("Repair removes the backup the installer wrote")
func removesTheBackupTheInstallerWrote() throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let plist = work.appending(path: "Info.plist")
@@ -208,7 +202,7 @@ struct SteamRepairTests {
@Test("Removing a backup that is not there is not a failure")
func absentBackupIsNotAFailure() throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
#expect(try SteamRepair.removeStaleBackup(from: work.appending(path: "backups")) == false)
@@ -218,7 +212,7 @@ struct SteamRepairTests {
@Test("Replacing a bundle leaves Valve's signature intact at the destination")
func replaceInstallsAVerifiableBundle() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let staged = try await stagedStockBundle(into: work)
@@ -245,7 +239,7 @@ struct SteamRepairTests {
@Test("A bundle that is not installed at all is installed rather than refused")
func replaceInstallsWhenNothingIsThere() async throws {
- let work = try scratch()
+ let work = try scratchDirectory("repair")
defer { try? FileManager.default.removeItem(at: work) }
let staged = try await stagedStockBundle(into: work)
diff --git a/app/Tests/NotProtonAppTests/TestSupport.swift b/app/Tests/NotProtonAppTests/TestSupport.swift
new file mode 100644
index 0000000..5013430
--- /dev/null
+++ b/app/Tests/NotProtonAppTests/TestSupport.swift
@@ -0,0 +1,7 @@
+import Foundation
+
+func scratchDirectory(_ label: String) throws -> URL {
+ let url = URL.temporaryDirectory.appending(path: "np-\(label)-\(UUID().uuidString)")
+ try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
+ return url
+}
diff --git a/app/Tests/NotProtonAppTests/UpdateBlockTests.swift b/app/Tests/NotProtonAppTests/UpdateBlockTests.swift
index ddceb43..3d030e4 100644
--- a/app/Tests/NotProtonAppTests/UpdateBlockTests.swift
+++ b/app/Tests/NotProtonAppTests/UpdateBlockTests.swift
@@ -6,15 +6,9 @@ import Testing
@Suite("Update block")
struct UpdateBlockTests {
- private func scratch() throws -> URL {
- let url = URL.temporaryDirectory.appending(path: "np-cfg-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
- return url
- }
-
@Test("Writing the block writes the required copy and the best-effort one")
func writesBothCopies() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let required = work.appending(path: "Steam/steam.cfg")
@@ -36,7 +30,7 @@ struct UpdateBlockTests {
// client is not installed, which is worse than not writing the best-effort copy.
@Test("The best-effort copy is skipped when the client directory is not there")
func skipsBestEffortWhenDirectoryAbsent() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let required = work.appending(path: "Steam/steam.cfg")
@@ -53,7 +47,7 @@ struct UpdateBlockTests {
@Test("Presence is decided by the required copy only")
func presenceFollowsRequiredCopy() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let required = work.appending(path: "steam.cfg")
@@ -70,7 +64,7 @@ struct UpdateBlockTests {
@Test("Removing the block takes every copy it finds and ignores the rest")
func removesEveryCopy() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let present = work.appending(path: "steam.cfg")
@@ -86,7 +80,7 @@ struct UpdateBlockTests {
@Test("Writing over an existing block leaves one block, not two")
func writeIsIdempotent() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let required = work.appending(path: "steam.cfg")
@@ -101,7 +95,7 @@ struct UpdateBlockTests {
// config that turns it off read as one that turns it on.
@Test("The key set to anything but enable is not a block")
func disabledKeyIsNotABlock() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let cfg = work.appending(path: "steam.cfg")
@@ -121,7 +115,7 @@ struct UpdateBlockTests {
// block deleted it, either of which threw away settings nothing to do with NotProton.
@Test("Blocking and unblocking leave the rest of the file alone")
func otherSettingsSurvive() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let cfg = work.appending(path: "steam.cfg")
try Data("BootStrapperInhibitAll=enable\nSomethingElse=1\n".utf8).write(to: cfg)
@@ -141,7 +135,7 @@ struct UpdateBlockTests {
// second one under it, since the last line is the one that counts.
@Test("Blocking replaces a line that turned the block off")
func blockingReplacesADisabledLine() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let cfg = work.appending(path: "steam.cfg")
try Data("BootStrapperInhibitUpdateOnLaunch=disable\nOther=2\n".utf8).write(to: cfg)
@@ -154,7 +148,7 @@ struct UpdateBlockTests {
@Test("A file holding nothing but the block is removed with it")
func aFileOfOnlyTheBlockGoes() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let cfg = work.appending(path: "steam.cfg")
@@ -168,7 +162,7 @@ struct UpdateBlockTests {
// A file the block was never in is not a file this changed, so repair does not report it.
@Test("A file without the block is left as it is")
func aFileWithoutTheBlockIsUntouched() throws {
- let work = try scratch()
+ let work = try scratchDirectory("cfg")
defer { try? FileManager.default.removeItem(at: work) }
let cfg = work.appending(path: "steam.cfg")
try Data("Other=2\n".utf8).write(to: cfg)
diff --git a/app/Tests/NotProtonAppTests/ValveFetcherTests.swift b/app/Tests/NotProtonAppTests/ValveFetcherTests.swift
index 59e825f..3e9e634 100644
--- a/app/Tests/NotProtonAppTests/ValveFetcherTests.swift
+++ b/app/Tests/NotProtonAppTests/ValveFetcherTests.swift
@@ -15,16 +15,9 @@ private final class PhaseLog: @unchecked Sendable {
@Suite("Valve fetcher", .serialized)
struct ValveFetcherTests {
- private func scratchBridge() throws -> URL {
- let bridge = FileManager.default.temporaryDirectory
- .appending(path: "np-valve-\(UUID().uuidString)")
- try FileManager.default.createDirectory(at: bridge, withIntermediateDirectories: true)
- return bridge
- }
-
@Test("An empty bridge gets all ten files, each matching its pin")
func fillsAnEmptyBridge() async throws {
- let bridge = try scratchBridge()
+ let bridge = try scratchDirectory("valve")
defer { try? FileManager.default.removeItem(at: bridge) }
let manifest = try ValvePackageManifest.bundled()
@@ -65,7 +58,7 @@ struct ValveFetcherTests {
@Test("A bridge that is already correct is left alone")
func secondRunWritesNothing() async throws {
- let bridge = try scratchBridge()
+ let bridge = try scratchDirectory("valve")
defer { try? FileManager.default.removeItem(at: bridge) }
let manifest = try ValvePackageManifest.bundled()
@@ -79,7 +72,7 @@ struct ValveFetcherTests {
@Test("A file that is missing or wrong is replaced, and the rest are not touched")
func repairsOnlyWhatIsWrong() async throws {
- let bridge = try scratchBridge()
+ let bridge = try scratchDirectory("valve")
defer { try? FileManager.default.removeItem(at: bridge) }
let manifest = try ValvePackageManifest.bundled()
@@ -104,7 +97,7 @@ struct ValveFetcherTests {
@Test("A file whose extracted bytes do not match its pin stops the whole install")
func refusesAFileThatFailsItsPin() async throws {
- let bridge = try scratchBridge()
+ let bridge = try scratchDirectory("valve")
defer { try? FileManager.default.removeItem(at: bridge) }
// The package still matches its own pin, so this is the second gate, on the extracted
@@ -136,8 +129,8 @@ struct ValveFetcherTests {
// a part-way failure is an extract short a file. Out of disk is the real-world shape.
@Test("A copy that fails part way leaves the previous binary in place")
func keepsPreviousBinaryWhenACopyFails() throws {
- let bridge = try scratchBridge()
- let extracted = try scratchBridge()
+ let bridge = try scratchDirectory("valve")
+ let extracted = try scratchDirectory("valve")
defer {
try? FileManager.default.removeItem(at: bridge)
try? FileManager.default.removeItem(at: extracted)
@@ -200,8 +193,8 @@ struct ValveFetcherTests {
@Test("A package whose bytes do not match its pin is refused, and nothing is installed")
func refusesAPackageThatFailsItsPin() async throws {
- let bridge = try scratchBridge()
- let downloads = try scratchBridge()
+ let bridge = try scratchDirectory("valve")
+ let downloads = try scratchDirectory("valve")
defer {
try? FileManager.default.removeItem(at: bridge)
try? FileManager.default.removeItem(at: downloads)