From df89882146ff950bd01e5b02db7d91f331d6160f Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 14 Dec 2024 20:47:00 +0100 Subject: [PATCH 1/3] Update generator to swift 6.0 --- .github/workflows/ci.yml | 4 +- Package.swift | 2 +- generator/Package.swift | 2 +- .../Sources/Generator/generator-help.swift | 2 +- .../Tests/GeneratorTests/GeneratorTests.swift | 41 ++++++++++--------- 5 files changed, 26 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0e14a2e42..766484ecc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - name: Run tests run: swift test generator-tests: - runs-on: macos-13 + runs-on: macos-14 env: RUNALL: "true" steps: @@ -29,7 +29,7 @@ jobs: - name: Run tests run: swift test --package-path ./generator generator-template-tests: - runs-on: macos-13 + runs-on: macos-14 steps: - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 diff --git a/Package.swift b/Package.swift index 35292fd26..efb80e032 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.3 +// swift-tools-version:6.0 import PackageDescription import Foundation diff --git a/generator/Package.swift b/generator/Package.swift index 318d64f6c..f8f8b1f0c 100644 --- a/generator/Package.swift +++ b/generator/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.7 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription diff --git a/generator/Sources/Generator/generator-help.swift b/generator/Sources/Generator/generator-help.swift index 76c19e46b..0c3aa21d8 100644 --- a/generator/Sources/Generator/generator-help.swift +++ b/generator/Sources/Generator/generator-help.swift @@ -25,7 +25,7 @@ class GeneratorHelp { } catch { throw GeneratorError.remoteError("No remote file found") } - let data = try String(contentsOf: url) ?? "" + let data = try String(contentsOf: url, encoding: .utf8) let fileData = Data(data.utf8) json = try JSONSerialization.jsonObject(with: fileData, options: []) as? [String: Any] ?? [:] } diff --git a/generator/Tests/GeneratorTests/GeneratorTests.swift b/generator/Tests/GeneratorTests/GeneratorTests.swift index 6909c9a16..26da747c0 100644 --- a/generator/Tests/GeneratorTests/GeneratorTests.swift +++ b/generator/Tests/GeneratorTests/GeneratorTests.swift @@ -1,25 +1,26 @@ -import XCTest +import Testing @testable import Generator -class GeneratorTests: XCTestCase { - func testAllTestsIncluded() { - let generatorHelp = GeneratorHelp(exercise: "two-fer", filePath: "./Tests/GeneratorTests/files/all-tests-included") - XCTAssertNoThrow(try generatorHelp.toml()) - let expected = ["1cf3e15a-a3d7-4a87-aeb3-ba1b43bc8dce", "3549048d-1a6e-4653-9a79-b0bda163e8d5", "b4c6dbb8-b4fb-42c2-bafd-10785abe7709"] - XCTAssertEqual(generatorHelp.uuids, expected) - } +@Test("Testing having all tests be included") +func testAllTestsIncluded() { + let generatorHelp = GeneratorHelp(exercise: "two-fer", filePath: "./Tests/GeneratorTests/files/all-tests-included") + #expect(throws: Never.self) {try generatorHelp.toml()} + let expected = ["1cf3e15a-a3d7-4a87-aeb3-ba1b43bc8dce", "3549048d-1a6e-4653-9a79-b0bda163e8d5", "b4c6dbb8-b4fb-42c2-bafd-10785abe7709"] + #expect(generatorHelp.uuids == expected) +} - func testAllTestsRemoved() { - let generatorHelp = GeneratorHelp(exercise: "two-fer", filePath: "./Tests/GeneratorTests/files/all-test-removed") - XCTAssertNoThrow(try generatorHelp.toml()) - let expected: [String] = [] - XCTAssertEqual(generatorHelp.uuids, expected) - } +@Test("Testing having all tests be removed") +func testAllTestsRemoved() { + let generatorHelp = GeneratorHelp(exercise: "two-fer", filePath: "./Tests/GeneratorTests/files/all-test-removed") + #expect(throws: Never.self) {try generatorHelp.toml()} + let expected: [String] = [] + #expect(generatorHelp.uuids == expected) +} - func testTwoTestsRemoved() { - let generatorHelp = GeneratorHelp(exercise: "two-fer", filePath: "./Tests/GeneratorTests/files/two-tests-removed") - XCTAssertNoThrow(try generatorHelp.toml()) - let expected = ["b4c6dbb8-b4fb-42c2-bafd-10785abe7709"] - XCTAssertEqual(generatorHelp.uuids, expected) - } +@Test("Testing having two tests be removed") +func testTwoTestsRemoved() { + let generatorHelp = GeneratorHelp(exercise: "two-fer", filePath: "./Tests/GeneratorTests/files/two-tests-removed") + #expect(throws: Never.self) {try generatorHelp.toml()} + let expected = ["b4c6dbb8-b4fb-42c2-bafd-10785abe7709"] + #expect(generatorHelp.uuids == expected) } From d419249db942350a6fb6ff851f058bcdc5ce4992 Mon Sep 17 00:00:00 2001 From: meatball Date: Sat, 14 Dec 2024 20:50:00 +0100 Subject: [PATCH 2/3] Use beta versio --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 766484ecc..06d7d88ec 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,7 +19,7 @@ jobs: - name: Run tests run: swift test generator-tests: - runs-on: macos-14 + runs-on: macos-15 env: RUNALL: "true" steps: @@ -29,7 +29,7 @@ jobs: - name: Run tests run: swift test --package-path ./generator generator-template-tests: - runs-on: macos-14 + runs-on: macos-15 steps: - name: Checkout code uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 From 51cd48c186acddcf26b0fe4a4edd06929e41d9e0 Mon Sep 17 00:00:00 2001 From: meatball Date: Tue, 17 Dec 2024 23:31:59 +0100 Subject: [PATCH 3/3] Update to use swift 6 formatter --- generator/Package.swift | 4 ++-- generator/Sources/Generator/main.swift | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/generator/Package.swift b/generator/Package.swift index f8f8b1f0c..fe6f1780c 100644 --- a/generator/Package.swift +++ b/generator/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:6.0 +// swift-tools-version:5.7 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription @@ -11,7 +11,7 @@ let package = Package( dependencies: [ .package(url: "https://github.com/stencilproject/Stencil.git", from: "0.15.1"), .package(url: "https://github.com/LebJe/TOMLKit.git", from: "0.5.5"), - .package(url: "https://github.com/apple/swift-format", from: "508.0.1"), + .package(url: "https://github.com/apple/swift-format", from: "600.0.0"), ], targets: [ // Targets are the basic building blocks of a package. A target can define a module or a test suite. diff --git a/generator/Sources/Generator/main.swift b/generator/Sources/Generator/main.swift index b5db548dc..69489e35d 100644 --- a/generator/Sources/Generator/main.swift +++ b/generator/Sources/Generator/main.swift @@ -42,7 +42,7 @@ class Generator { var text = "" let configuration = Configuration() let swiftFormat = SwiftFormatter(configuration: configuration) - try swiftFormat.format(source: template, assumingFileURL: nil, to: &text) + try swiftFormat.format(source: template, assumingFileURL: nil, selection: .infinite, to: &text) try text.write(toFile: path, atomically: true, encoding: .utf8) }