Skip to content

Commit 1304b04

Browse files
Alex293timsneath
andauthored
Update for Swift6, Swift testing and add editor config (#6)
Co-authored-by: Tim Sneath <[email protected]>
1 parent ff716f2 commit 1304b04

File tree

5 files changed

+53
-44
lines changed

5 files changed

+53
-44
lines changed

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# editorconfig.org
2+
3+
root = true
4+
5+
[*.swift]
6+
indent_style = space
7+
indent_size = 2
8+
trim_trailing_whitespace = true
9+
insert_final_newline = true

Package.swift

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
1-
// swift-tools-version: 5.9
1+
// swift-tools-version: 6.0
22
import PackageDescription
33

44
let dependencies: [Target.Dependency] = [
5-
.product(name: "Algorithms", package: "swift-algorithms"),
6-
.product(name: "Collections", package: "swift-collections"),
7-
.product(name: "ArgumentParser", package: "swift-argument-parser"),
5+
.product(name: "Algorithms", package: "swift-algorithms"),
6+
.product(name: "Collections", package: "swift-collections"),
7+
.product(name: "ArgumentParser", package: "swift-argument-parser"),
88
]
99

1010
let package = Package(
11-
name: "AdventOfCode",
12-
platforms: [.macOS(.v13), .iOS(.v16), .watchOS(.v9), .tvOS(.v16)],
13-
dependencies: [
14-
.package(
15-
url: "https://github.com/apple/swift-algorithms.git",
16-
.upToNextMajor(from: "1.2.0")),
17-
.package(
18-
url: "https://github.com/apple/swift-collections.git",
19-
.upToNextMajor(from: "1.0.0")),
20-
.package(
21-
url: "https://github.com/apple/swift-argument-parser.git",
22-
.upToNextMajor(from: "1.2.0")),
23-
.package(
24-
url: "https://github.com/apple/swift-format.git",
25-
.upToNextMajor(from: "509.0.0"))
26-
],
27-
targets: [
28-
.executableTarget(
29-
name: "AdventOfCode",
30-
dependencies: dependencies,
31-
resources: [.copy("Data")],
32-
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
33-
),
34-
.testTarget(
35-
name: "AdventOfCodeTests",
36-
dependencies: ["AdventOfCode"] + dependencies,
37-
swiftSettings: [.enableUpcomingFeature("BareSlashRegexLiterals")]
38-
)
39-
]
11+
name: "AdventOfCode",
12+
platforms: [.macOS(.v13), .iOS(.v16), .watchOS(.v9), .tvOS(.v16)],
13+
dependencies: [
14+
.package(
15+
url: "https://github.com/apple/swift-algorithms.git",
16+
.upToNextMajor(from: "1.2.0")),
17+
.package(
18+
url: "https://github.com/apple/swift-collections.git",
19+
.upToNextMajor(from: "1.1.4")),
20+
.package(
21+
url: "https://github.com/apple/swift-argument-parser.git",
22+
.upToNextMajor(from: "1.5.0")),
23+
.package(
24+
url: "https://github.com/swiftformat/swift-format.git",
25+
.upToNextMajor(from: "600.0.0"))
26+
],
27+
targets: [
28+
.executableTarget(
29+
name: "AdventOfCode",
30+
dependencies: dependencies,
31+
resources: [.copy("Data")]
32+
),
33+
.testTarget(
34+
name: "AdventOfCodeTests",
35+
dependencies: ["AdventOfCode"] + dependencies
36+
)
37+
],
38+
swiftLanguageModes: [.v6]
4039
)

Sources/AdventDay.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
@_exported import Collections
33
import Foundation
44

5-
protocol AdventDay {
5+
protocol AdventDay: Sendable {
66
associatedtype Answer = Int
77

88
/// The day of the Advent of Code challenge.

Tests/AdventDay.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import XCTest
1+
import Testing
22

33
@testable import AdventOfCode
44

55
// One off test to validate that basic data load testing works
6-
final class AdventDayTests: XCTestCase {
7-
func testInitData() throws {
6+
struct AdventDayTests {
7+
8+
@Test func testInitData() async throws {
89
let challenge = Day00()
9-
XCTAssertTrue(challenge.data.starts(with: "4514"))
10+
#expect(challenge.data.starts(with: "4514"))
1011
}
1112
}

Tests/Day00.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import XCTest
1+
import Testing
22

33
@testable import AdventOfCode
44

55
// Make a copy of this file for every day to ensure the provided smoke tests
66
// pass.
7-
final class Day00Tests: XCTestCase {
7+
struct Day00Tests {
88
// Smoke test data provided in the challenge question
99
let testData = """
1010
1000
@@ -24,13 +24,13 @@ final class Day00Tests: XCTestCase {
2424
2525
"""
2626

27-
func testPart1() throws {
27+
@Test func testPart1() async throws {
2828
let challenge = Day00(data: testData)
29-
XCTAssertEqual(String(describing: challenge.part1()), "6000")
29+
#expect(String(describing: challenge.part1()) == "6000")
3030
}
3131

32-
func testPart2() throws {
32+
@Test func testPart2() async throws {
3333
let challenge = Day00(data: testData)
34-
XCTAssertEqual(String(describing: challenge.part2()), "32000")
34+
#expect(String(describing: challenge.part2()) == "32000")
3535
}
3636
}

0 commit comments

Comments
 (0)