Skip to content

Commit e5c1218

Browse files
committed
Move withApp to TestSupport
1 parent b259c21 commit e5c1218

File tree

2 files changed

+59
-44
lines changed

2 files changed

+59
-44
lines changed

Tests/AppTests/AnalyzeErrorTests.swift

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,56 +12,13 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
import Testing
16-
1715
@testable import App
1816

1917
import Dependencies
2018
import Fluent
2119
import ShellOut
22-
23-
24-
#warning("Move this")
20+
import Testing
2521
import Vapor
26-
private func withApp(_ setup: (Application) async throws -> Void = { _ in },
27-
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void = { _ in },
28-
_ logHandler: LogHandler? = nil,
29-
environment: Environment = .testing,
30-
_ test: (Application) async throws -> Void) async throws {
31-
try await AppTestCase.setupDb(environment)
32-
let app = try await AppTestCase.setupApp(environment)
33-
34-
return try await run {
35-
try await setup(app)
36-
try await withDependencies(updateValuesForOperation) {
37-
let logger = logHandler.map { handler in Logger(label: "test", factory: { _ in handler }) }
38-
try await withDependencies {
39-
if let logger {
40-
$0.logger.set(to: logger)
41-
}
42-
} operation: {
43-
try await test(app)
44-
}
45-
}
46-
} defer: {
47-
try await app.asyncShutdown()
48-
}
49-
}
50-
51-
52-
53-
private func defaultShellRun(command: ShellOutCommand, path: String) throws -> String {
54-
switch command {
55-
case .swiftDumpPackage where path.hasSuffix("foo-1"):
56-
return packageSwift1
57-
58-
case .swiftDumpPackage where path.hasSuffix("foo-2"):
59-
return packageSwift2
60-
61-
default:
62-
return ""
63-
}
64-
}
6522

6623

6724
// Test analysis error handling.
@@ -257,6 +214,20 @@ extension AnalyzeErrorTests {
257214
}
258215

259216

217+
private func defaultShellRun(command: ShellOutCommand, path: String) throws -> String {
218+
switch command {
219+
case .swiftDumpPackage where path.hasSuffix("foo-1"):
220+
return packageSwift1
221+
222+
case .swiftDumpPackage where path.hasSuffix("foo-2"):
223+
return packageSwift2
224+
225+
default:
226+
return ""
227+
}
228+
}
229+
230+
260231
private extension GitClient {
261232
struct SetupError: Error { }
262233
static var analyzeErrorTestsMock: Self {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// Copyright Dave Verwer, Sven A. Schmidt, and other contributors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
@testable import App
16+
17+
import Dependencies
18+
import Vapor
19+
20+
21+
func withApp(_ setup: (Application) async throws -> Void = { _ in },
22+
_ updateValuesForOperation: (inout DependencyValues) async throws -> Void = { _ in },
23+
_ logHandler: LogHandler? = nil,
24+
environment: Environment = .testing,
25+
_ test: (Application) async throws -> Void) async throws {
26+
try await AppTestCase.setupDb(environment)
27+
let app = try await AppTestCase.setupApp(environment)
28+
29+
return try await run {
30+
try await setup(app)
31+
try await withDependencies(updateValuesForOperation) {
32+
let logger = logHandler.map { handler in Logger(label: "test", factory: { _ in handler }) }
33+
try await withDependencies {
34+
if let logger {
35+
$0.logger.set(to: logger)
36+
}
37+
} operation: {
38+
try await test(app)
39+
}
40+
}
41+
} defer: {
42+
try await app.asyncShutdown()
43+
}
44+
}

0 commit comments

Comments
 (0)