@@ -98,125 +98,117 @@ final class AnalyzeErrorTests: AppTestCase {
9898 }
9999
100100 Current . shell. run = Self . defaultShellRun
101+ }
101102
102- Current . mastodonPost = { [ socialPosts = self . socialPosts] _, message in
103- socialPosts. withValue { $0. append ( message) }
103+ override func invokeTest( ) {
104+ withDependencies {
105+ $0. date. now = . t0
106+ $0. environment. allowSocialPosts = { true }
107+ $0. environment. mastodonPost = { @Sendable [ socialPosts = self . socialPosts] _, message in
108+ socialPosts. withValue { $0. append ( message) }
109+ }
110+ } operation: {
111+ super. invokeTest ( )
104112 }
105113 }
106114
107115 func test_analyze_refreshCheckout_failed( ) async throws {
108- try await withDependencies {
109- $0. date. now = . t0
110- } operation: {
111- Current . shell. run = { @Sendable cmd, path in
112- switch cmd {
113- case _ where cmd. description. contains ( " git clone https://github.com/foo/1 " ) :
114- throw SimulatedError ( )
115-
116- case . gitFetchAndPruneTags where path. hasSuffix ( " foo-1 " ) :
117- throw SimulatedError ( )
118-
119- default :
120- return try Self . defaultShellRun ( cmd, path)
121- }
122- }
123-
124- // MUT
125- try await Analyze . analyze ( client: app. client,
126- database: app. db,
127- mode: . limit( 10 ) )
128-
129- // validate
130- try await defaultValidation ( )
131- try logger. logs. withValue { logs in
132- XCTAssertEqual ( logs. count, 2 )
133- let error = try logs. last. unwrap ( )
134- XCTAssertTrue ( error. message. contains ( " refreshCheckout failed " ) , " was: \( error. message) " )
116+ Current . shell. run = { @Sendable cmd, path in
117+ switch cmd {
118+ case _ where cmd. description. contains ( " git clone https://github.com/foo/1 " ) :
119+ throw SimulatedError ( )
120+
121+ case . gitFetchAndPruneTags where path. hasSuffix ( " foo-1 " ) :
122+ throw SimulatedError ( )
123+
124+ default :
125+ return try Self . defaultShellRun ( cmd, path)
135126 }
136127 }
128+
129+ // MUT
130+ try await Analyze . analyze ( client: app. client,
131+ database: app. db,
132+ mode: . limit( 10 ) )
133+
134+ // validate
135+ try await defaultValidation ( )
136+ try logger. logs. withValue { logs in
137+ XCTAssertEqual ( logs. count, 2 )
138+ let error = try logs. last. unwrap ( )
139+ XCTAssertTrue ( error. message. contains ( " refreshCheckout failed " ) , " was: \( error. message) " )
140+ }
137141 }
138142
139143 func test_analyze_updateRepository_invalidPackageCachePath( ) async throws {
140- try await withDependencies {
141- $0. date. now = . t0
142- } operation: {
143- // setup
144- let pkg = try await Package . find ( badPackageID, on: app. db) . unwrap ( )
145- // This may look weird but its currently the only way to actually create an
146- // invalid package cache path - we need to mess up the package url.
147- pkg. url = " foo/1 "
148- XCTAssertNil ( pkg. cacheDirectoryName)
149- try await pkg. save ( on: app. db)
150-
151- // MUT
152- try await Analyze . analyze ( client: app. client,
153- database: app. db,
154- mode: . limit( 10 ) )
155-
156- // validate
157- try await defaultValidation ( )
158- try logger. logs. withValue { logs in
159- XCTAssertEqual ( logs. count, 2 )
160- let error = try logs. last. unwrap ( )
161- XCTAssertTrue ( error. message. contains ( " AppError.invalidPackageCachePath " ) , " was: \( error. message) " )
162- }
144+ // setup
145+ let pkg = try await Package . find ( badPackageID, on: app. db) . unwrap ( )
146+ // This may look weird but its currently the only way to actually create an
147+ // invalid package cache path - we need to mess up the package url.
148+ pkg. url = " foo/1 "
149+ XCTAssertNil ( pkg. cacheDirectoryName)
150+ try await pkg. save ( on: app. db)
151+
152+ // MUT
153+ try await Analyze . analyze ( client: app. client,
154+ database: app. db,
155+ mode: . limit( 10 ) )
156+
157+ // validate
158+ try await defaultValidation ( )
159+ try logger. logs. withValue { logs in
160+ XCTAssertEqual ( logs. count, 2 )
161+ let error = try logs. last. unwrap ( )
162+ XCTAssertTrue ( error. message. contains ( " AppError.invalidPackageCachePath " ) , " was: \( error. message) " )
163163 }
164164 }
165165
166166 func test_analyze_getPackageInfo_gitCheckout_error( ) async throws {
167- try await withDependencies {
168- $0. date. now = . t0
169- } operation: {
170- // setup
171- Current . shell. run = { @Sendable cmd, path in
172- switch cmd {
173- case . gitCheckout( branch: " main " , quiet: true ) where path. hasSuffix ( " foo-1 " ) :
174- throw SimulatedError ( )
175-
176- default :
177- return try Self . defaultShellRun ( cmd, path)
178- }
167+ // setup
168+ Current . shell. run = { @Sendable cmd, path in
169+ switch cmd {
170+ case . gitCheckout( branch: " main " , quiet: true ) where path. hasSuffix ( " foo-1 " ) :
171+ throw SimulatedError ( )
172+
173+ default :
174+ return try Self . defaultShellRun ( cmd, path)
179175 }
176+ }
180177
181- // MUT
182- try await Analyze . analyze ( client: app. client,
183- database: app. db,
184- mode: . limit( 10 ) )
185-
186- // validate
187- try await defaultValidation ( )
188- try logger. logs. withValue { logs in
189- XCTAssertEqual ( logs. count, 2 )
190- let error = try logs. last. unwrap ( )
191- XCTAssertTrue ( error. message. contains ( " AppError.noValidVersions " ) , " was: \( error. message) " )
192- }
178+ // MUT
179+ try await Analyze . analyze ( client: app. client,
180+ database: app. db,
181+ mode: . limit( 10 ) )
182+
183+ // validate
184+ try await defaultValidation ( )
185+ try logger. logs. withValue { logs in
186+ XCTAssertEqual ( logs. count, 2 )
187+ let error = try logs. last. unwrap ( )
188+ XCTAssertTrue ( error. message. contains ( " AppError.noValidVersions " ) , " was: \( error. message) " )
193189 }
194190 }
195191
196192 func test_analyze_dumpPackage_missing_manifest( ) async throws {
197- try await withDependencies {
198- $0. date. now = . t0
199- } operation: {
200- // setup
201- Current . fileManager. fileExists = { @Sendable path in
202- if path. hasSuffix ( " github.com-foo-1/Package.swift " ) {
203- return false
204- }
205- return true
206- }
207-
208- // MUT
209- try await Analyze . analyze ( client: app. client,
210- database: app. db,
211- mode: . limit( 10 ) )
212-
213- // validate
214- try await defaultValidation ( )
215- try logger. logs. withValue { logs in
216- XCTAssertEqual ( logs. count, 2 )
217- let error = try logs. last. unwrap ( )
218- XCTAssertTrue ( error. message. contains ( " AppError.noValidVersions " ) , " was: \( error. message) " )
193+ // setup
194+ Current . fileManager. fileExists = { @Sendable path in
195+ if path. hasSuffix ( " github.com-foo-1/Package.swift " ) {
196+ return false
219197 }
198+ return true
199+ }
200+
201+ // MUT
202+ try await Analyze . analyze ( client: app. client,
203+ database: app. db,
204+ mode: . limit( 10 ) )
205+
206+ // validate
207+ try await defaultValidation ( )
208+ try logger. logs. withValue { logs in
209+ XCTAssertEqual ( logs. count, 2 )
210+ let error = try logs. last. unwrap ( )
211+ XCTAssertTrue ( error. message. contains ( " AppError.noValidVersions " ) , " was: \( error. message) " )
220212 }
221213 }
222214
0 commit comments