Skip to content

Commit f792e5f

Browse files
committed
Refactor progress file parsing and improve test validation
1 parent 6a07745 commit f792e5f

File tree

2 files changed

+16
-15
lines changed

2 files changed

+16
-15
lines changed

Sources/SwiftlyCore/FileManager+FilePath.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,6 @@ extension String {
190190
try self.write(to: URL(fileURLWithPath: path.string), atomically: atomically, encoding: enc)
191191
}
192192

193-
public func append(to path: FilePath, encoding enc: String.Encoding = .utf8) throws {
194-
if !FileManager.default.fileExists(atPath: path.string) {
195-
try self.write(to: path, atomically: true, encoding: enc)
196-
return
197-
}
198-
}
199-
200193
public init(contentsOf path: FilePath, encoding enc: String.Encoding = .utf8) throws {
201194
try self.init(contentsOf: URL(fileURLWithPath: path.string), encoding: enc)
202195
}

Tests/SwiftlyTests/InstallTests.swift

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ import Testing
267267
/// Verify that progress information is written to the progress file when specified.
268268
@Test(.testHomeMockedToolchain()) func installProgressFile() async throws {
269269
let progressFile = fs.mktemp(ext: ".json")
270+
try await fs.create(.mode(0o644), file: progressFile)
270271

271272
try await SwiftlyTests.runCommand(Install.self, [
272273
"install", "5.7.0",
@@ -276,20 +277,27 @@ import Testing
276277

277278
#expect(try await fs.exists(atPath: progressFile))
278279

280+
let decoder = JSONDecoder()
279281
let progressContent = try String(contentsOfFile: progressFile.string)
280-
let lines = progressContent.components(separatedBy: .newlines).filter { !$0.isEmpty }
282+
let progressInfo = try progressContent.split(separator: "\n")
283+
.filter { !$0.isEmpty }
284+
.map { line in
285+
try decoder.decode(ProgressInfo.self, from: Data(line.utf8))
286+
}
281287

282-
#expect(!lines.isEmpty, "Progress file should contain progress entries")
288+
#expect(!progressInfo.isEmpty, "Progress file should contain progress entries")
283289

284-
// Verify that at least one progress entry exists
285-
let hasProgressEntry = lines.contains { line in
286-
line.contains("\"step\"") && line.contains("\"percent\"") && line.contains("\"timestamp\"")
290+
// Verify that at least one step progress entry exists
291+
let hasStepEntry = progressInfo.contains { info in
292+
if case .step = info { return true }
293+
return false
287294
}
288-
#expect(hasProgressEntry, "Progress file should contain step progress entries")
295+
#expect(hasStepEntry, "Progress file should contain step progress entries")
289296

290297
// Verify that a completion entry exists
291-
let hasCompletionEntry = lines.contains { line in
292-
line.contains("\"complete\"") && line.contains("\"success\"")
298+
let hasCompletionEntry = progressInfo.contains { info in
299+
if case .complete = info { return true }
300+
return false
293301
}
294302
#expect(hasCompletionEntry, "Progress file should contain completion entry")
295303

0 commit comments

Comments
 (0)