Skip to content

Commit 8f192fc

Browse files
authored
feat: Merge pull request #2 from LLCFreedom-Space/swift-6
feat: update swift version
2 parents ecf0714 + 47a9b52 commit 8f192fc

10 files changed

Lines changed: 91 additions & 76 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515
jobs:
1616
analyze:
1717
name: Analyze
18-
runs-on: macos-14
18+
runs-on: macos-15
1919
permissions:
2020
security-events: write
2121

@@ -35,6 +35,7 @@ jobs:
3535

3636
- name: Build
3737
run: swift build
38-
38+
3939
- name: Perform CodeQL Analysis
4040
uses: github/codeql-action/analyze@v4
41+

.github/workflows/docc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
environment:
1919
name: github-pages
2020
url: ${{ steps.deployment.outputs.page_url }}
21-
runs-on: macos-14
21+
runs-on: macos-15
2222

2323
steps:
2424
- name: Checkout 🛎️

.github/workflows/lint.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ concurrency:
99

1010
jobs:
1111
SwiftLint:
12-
runs-on: macOS-14
12+
runs-on: macOS-15
1313
steps:
1414
- name: Checkout
1515
uses: actions/checkout@v4
16+
1617
- name: Select Xcode
1718
uses: maxim-lobanov/setup-xcode@v1
1819
with:
19-
xcode-version: "15.0.1"
20+
xcode-version: "16.3.0"
21+
2022
- name: Install SwiftLint
2123
run: brew install swiftlint
24+
25+
- name: Verify SwiftLint version
26+
run: swiftlint version
27+
2228
- name: Run SwiftLint
23-
run: swiftlint --strict
29+
run: swiftlint --strict --config .swiftlint.yml

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ jobs:
1919
# macOS
2020
# =========================
2121
macos:
22-
runs-on: macos-14
22+
runs-on: macos-15
2323
steps:
2424
- name: Checkout
2525
uses: actions/checkout@v4
2626
- name: Select Xcode
2727
uses: maxim-lobanov/setup-xcode@v1
2828
with:
29-
xcode-version: "15.0.1"
29+
xcode-version: "16.3.0"
3030
- name: Cache SwiftPM
3131
uses: actions/cache@v4
3232
with:
@@ -45,7 +45,7 @@ jobs:
4545
# =========================
4646
linux:
4747
runs-on: ubuntu-latest
48-
container: swift:5.9-jammy
48+
container: swift:6.0-jammy
4949
steps:
5050
- name: Checkout
5151
uses: actions/checkout@v4

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ disabled_rules: # rule identifiers to exclude from running
55
- todo
66
- unused_capture_list
77
- trailing_whitespace
8+
- void_return
89
opt_in_rules: # some rules are only opt-in
910
- array_init
1011
# Prefer using Array(seq) over seq.map { $0 } to convert a sequence into an Array.

Package.resolved

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -18,6 +18,7 @@ let package = Package(
1818
dependencies: [
1919
// 💧 A server-side Swift web framework.
2020
.package(url: "https://github.com/vapor/vapor.git", from: "4.115.0"),
21+
// 📄 Swift-DocC plugin for generating documentation.
2122
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.0.0"),
2223
],
2324
targets: [
@@ -32,13 +33,8 @@ let package = Package(
3233
.testTarget(
3334
name: "ErrorMiddlewareTests",
3435
dependencies: [
35-
.target(
36-
name: "ErrorMiddleware"
37-
),
38-
.product(
39-
name: "XCTVapor",
40-
package: "vapor"
41-
),
36+
.target(name: "ErrorMiddleware"),
37+
.product(name: "VaporTesting", package: "vapor")
4238
]
4339
)
4440
]

Sources/ErrorMiddleware/ErrorMiddleware.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public extension ErrorMiddleware {
5656
httpStatus = appError.status
5757
headers = appError.headers
5858
identifier = appError.identifier
59-
status = appError.status.code.description
59+
status = "\(appError.status.code)"
6060
code = "\(appError.status.code.description).\(number).\(appError.number)"
6161
case let abort as AbortError:
6262
/// This is an abort error, we should use its status, reason, and headers
@@ -73,17 +73,17 @@ public extension ErrorMiddleware {
7373
httpStatus = .internalServerError
7474
headers = [:]
7575
identifier = error.errorDescription
76-
status = "500"
77-
code = "500.\(number).0000"
76+
status = "\(HTTPStatus.internalServerError.code)"
77+
code = "\(HTTPStatus.internalServerError.code).\(number).0000"
7878
default:
7979
/// Not an abort error, and not debuggable or in dev mode
8080
/// Just deliver a generic 500 to avoid exposing any sensitive error info
8181
reason = "Something went wrong."
8282
httpStatus = .internalServerError
8383
headers = [:]
8484
identifier = "something_went_wrong"
85-
status = "500"
86-
code = "500.\(number).0000"
85+
status = "\(HTTPStatus.internalServerError.code)"
86+
code = "\(HTTPStatus.internalServerError.code).\(number).0000"
8787
}
8888
/// Report the error to logger.
8989
req.logger.report(error: error)

Tests/ErrorMiddlewareTests/ErrorMiddlewareTests.swift

Lines changed: 39 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,53 +15,56 @@
1515
// You should have received a copy of the GNU Affero General Public License
1616
// along with this program. If not, see <https://www.gnu.org/licenses/>.
1717

18-
import XCTVapor
1918
@testable import ErrorMiddleware
19+
import VaporTesting
20+
import Testing
2021

21-
final class ErrorMiddlewareTests: XCTestCase {
22-
// swiftlint: disable implicitly_unwrapped_optional
23-
var app: Application!
24-
// swiftlint: enable implicitly_unwrapped_optional
25-
override func setUp() async throws {
26-
app = try await Application.make(.testing)
27-
app.post("order") { _ -> String in
28-
return "done"
22+
@Suite("Error middleware tests")
23+
struct ErrorMiddlewareTests {
24+
private func withApp(_ test: (Application) async throws -> ()) async throws {
25+
let app = try await Application.make(.testing)
26+
do {
27+
app.post("order") { _ -> String in
28+
return "done"
29+
}
30+
try await test(app)
31+
} catch {
32+
throw error
2933
}
30-
}
31-
32-
override func tearDown() async throws {
3334
try await app.asyncShutdown()
3435
}
3536

36-
func testErrorMiddlewareSnakeCase() throws {
37-
let app = Application(.testing)
38-
defer { app.shutdown() }
39-
app.middleware.use(ErrorMiddleware.custom(environment: app.environment, for: 1))
37+
@Test("Error middleware snake case")
38+
func errorMiddlewareSnakeCase() async throws {
39+
try await withApp { app in
40+
app.middleware.use(ErrorMiddleware.custom(environment: app.environment, for: 1))
4041

41-
try app.testable().test(.GET, "order") { res throws in
42-
let error = try res.content.decode(ErrorResponse.self, using: app.errorDecode)
43-
XCTAssertEqual(error.isError, true)
44-
XCTAssertEqual(error.reason, "Not Found")
45-
XCTAssertEqual(error.error, "404")
46-
XCTAssertEqual(error.status, "404")
47-
XCTAssertEqual(error.code, "404.1.")
48-
XCTAssertEqual(error.errorUri, "https://example.com/doc/errors")
42+
try await app.test(.GET, "order") { res throws in
43+
let error = try res.content.decode(ErrorResponse.self, using: app.errorDecode)
44+
#expect(error.isError == true)
45+
#expect(error.reason == "Not Found")
46+
#expect(error.error == "404")
47+
#expect(error.status == "404")
48+
#expect(error.code == "404.1.")
49+
#expect(error.errorUri == "https://example.com/doc/errors")
50+
}
4951
}
5052
}
5153

52-
func testErrorMiddlewareDefaultCase() throws {
53-
let app = Application(.testing)
54-
defer { app.shutdown() }
55-
app.middleware.use(ErrorMiddleware.custom(environment: app.environment, for: 1, keyEncodingStrategy: .useDefaultKeys))
54+
@Test("Error middleware default case")
55+
func errorMiddlewareDefaultCase() async throws {
56+
try await withApp { app in
57+
app.middleware.use(ErrorMiddleware.custom(environment: app.environment, for: 1, keyEncodingStrategy: .useDefaultKeys))
5658

57-
try app.testable().test(.GET, "order") { res throws in
58-
let error = try res.content.decode(ErrorResponse.self)
59-
XCTAssertEqual(error.isError, true)
60-
XCTAssertEqual(error.reason, "Not Found")
61-
XCTAssertEqual(error.error, "404")
62-
XCTAssertEqual(error.status, "404")
63-
XCTAssertEqual(error.code, "404.1.")
64-
XCTAssertEqual(error.errorUri, "https://example.com/doc/errors")
59+
try await app.test(.GET, "order") { res throws in
60+
let error = try res.content.decode(ErrorResponse.self)
61+
#expect(error.isError == true)
62+
#expect(error.reason == "Not Found")
63+
#expect(error.error == "404")
64+
#expect(error.status == "404")
65+
#expect(error.code == "404.1.")
66+
#expect(error.errorUri == "https://example.com/doc/errors")
67+
}
6568
}
6669
}
6770
}

Tests/ErrorMiddlewareTests/ErrorResponseTests.swift

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,14 @@
2222
// Created by Mykola Buhaiov on 18.06.2024.
2323
//
2424

25-
import XCTest
26-
import XCTVapor
2725
@testable import ErrorMiddleware
26+
import VaporTesting
27+
import Testing
2828

29-
/// Unit tests for the `ErrorResponse` equatable conformance.
30-
final class ErrorResponseTests: XCTestCase {
31-
// swiftlint: disable implicitly_unwrapped_optional
32-
var app: Application!
33-
// swiftlint: enable implicitly_unwrapped_optional
34-
override func setUp() async throws {
35-
app = try await Application.make(.testing)
36-
}
37-
38-
override func tearDown() async throws {
39-
try await app.asyncShutdown()
40-
}
41-
/// Tests the equality of two `ErrorResponse` instances.
42-
func testErrorResponseEquatable() {
29+
@Suite("Error response tests")
30+
struct ErrorResponseTests {
31+
@Test("Error response equatable")
32+
func errorResponseEquatable() {
4333
let firstErrorResponse = ErrorResponse(
4434
isError: true,
4535
reason: "reason of error",
@@ -57,10 +47,10 @@ final class ErrorResponseTests: XCTestCase {
5747
errorUri: "error uri"
5848
)
5949
// Assert that the two instances are equal.
60-
XCTAssertEqual(firstErrorResponse, secondErrorResponse)
50+
#expect(firstErrorResponse == secondErrorResponse)
6151
// Modify a property in the second instance.
6252
secondErrorResponse.code = "4"
6353
// Assert that the two instances are not equal after the modification.
64-
XCTAssertNotEqual(firstErrorResponse, secondErrorResponse)
54+
#expect(firstErrorResponse != secondErrorResponse)
6555
}
6656
}

0 commit comments

Comments
 (0)