1
1
import Foundation
2
- @testable import Swiftly
3
- @testable import SwiftlyCore
4
2
import SystemPackage
5
3
import Testing
6
4
@@ -102,18 +100,21 @@ import Testing
102
100
try FileManager . default. removeItem ( atPath: tempFile. string)
103
101
}
104
102
105
- @Test ( " Test clear method removes file " )
106
- func testClearRemovesFile ( ) throws {
103
+ @Test ( " Test clear method truncates the file " )
104
+ func testClearTruncatesFile ( ) async throws {
107
105
let tempFile = fs. mktemp ( ext: " .json " )
108
- let reporter = JsonFileProgressReporter ( filePath: tempFile)
106
+ try await fs. create ( . mode( Int ( 0o644 ) ) , file: tempFile)
107
+ defer { try ? FileManager . default. removeItem ( atPath: tempFile. string) }
108
+ let reporter = try JsonFileProgressReporter ( SwiftlyTests . ctx, filePath: tempFile)
109
+ defer { try ? reporter. close ( ) }
109
110
110
111
reporter. update ( step: 1 , total: 2 , text: " Test " )
111
112
112
- #expect( FileManager . default . fileExists ( atPath : tempFile. string ) )
113
+ #expect( try String ( contentsOf : tempFile) . lengthOfBytes ( using : String . Encoding . utf8 ) > 0 )
113
114
114
115
reporter. clear ( )
115
116
116
- #expect( !FileManager . default . fileExists ( atPath : tempFile. string ) )
117
+ #expect( try String ( contentsOf : tempFile) . lengthOfBytes ( using : String . Encoding . utf8 ) == 0 )
117
118
}
118
119
119
120
@Test ( " Test multiple progress updates create multiple lines " )
@@ -129,8 +130,6 @@ import Testing
129
130
reporter. update ( step: 50 , total: 100 , text: " Processing item 50 " )
130
131
reporter. update ( step: 100 , total: 100 , text: " Processing item 100 " )
131
132
132
- reporter. update ( step: 1 , total: 3 , text: " Step 1 " )
133
- reporter. update ( step: 2 , total: 3 , text: " Step 2 " )
134
133
reporter. complete ( success: true )
135
134
try ? reporter. close ( )
136
135
0 commit comments