From 06fd03e72e5167c42b533a953396fbfe7dffd3eb Mon Sep 17 00:00:00 2001 From: ikelax <163678144+ikelax@users.noreply.github.com> Date: Tue, 28 Jan 2025 18:41:19 +0100 Subject: [PATCH] Migrate tests to swift-testing (#22) The tests were migrated to swift-testing because it is supported on Windows unlike Nimble. Furthermore, I added a job for running the tests on Windows to the pipeline. Since the project does not rely anymore on Quick and Nimble for the tests, I removed the packages. swift-testing does not have to be included as dependency. I removed SwiftDependencyGraphsTests because the file was generated by XCode or SwiftPM and I did not use it. I split ContainsVertexWithTests.swift since I found the file too big and I lost the overview. Closes https://github.com/ikelax/swift-dependency-graphs/issues/15 See pull request https://github.com/ikelax/swift-dependency-graphs/pull/22 --- .github/workflows/testing.yml | 15 +++ Package.resolved | 65 +------------ Package.swift | 4 +- .../ContainsTests/C4ContainsVertexTests.swift | 24 +++++ .../C4ContainsVertexWithTests.swift | 37 ++++++++ .../ContainsTests/EmptyGraph.swift | 25 +++++ .../ContainsVertexWithTests.swift | 91 ------------------- .../SwiftDependencyGraphsTests/Dfs/Path.swift | 88 ++++++++---------- .../SwiftDependencyGraphsTests.swift | 7 -- 9 files changed, 142 insertions(+), 214 deletions(-) create mode 100644 Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexTests.swift create mode 100644 Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexWithTests.swift create mode 100644 Tests/SwiftDependencyGraphsTests/ContainsTests/EmptyGraph.swift delete mode 100644 Tests/SwiftDependencyGraphsTests/ContainsVertexWithTests.swift delete mode 100644 Tests/SwiftDependencyGraphsTests/SwiftDependencyGraphsTests.swift diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index f87d1a9..06cabc4 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -30,3 +30,18 @@ jobs: eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" brew install xcbeautify set -o pipefail && swift test | xcbeautify --renderer github-actions + test-windows: + name: Test on Windows Server 2022 + runs-on: windows-2022 + steps: + - uses: compnerd/gha-setup-swift@main + with: + branch: swift-6.0-release + tag: 6.0-RELEASE + - uses: actions/checkout@v4 + - name: Test + run: | + Set-StrictMode -Version Latest + $ErrorActionPreference = "Stop" + $PSNativeCommandUseErrorActionPreference = $true + swift test diff --git a/Package.resolved b/Package.resolved index ebee246..2f8ba9b 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,60 +1,6 @@ { - "originHash" : "d2b30721124292e39b999beabef97a5a8e1680b0986e272531a064e85385927e", + "originHash" : "034e385c751c6af014263c63cdc6988fd6cd19e2b0a2e1bdd822f496ff903ad9", "pins" : [ - { - "identity" : "cwlcatchexception", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mattgallagher/CwlCatchException.git", - "state" : { - "revision" : "07b2ba21d361c223e25e3c1e924288742923f08c", - "version" : "2.2.1" - } - }, - { - "identity" : "cwlpreconditiontesting", - "kind" : "remoteSourceControl", - "location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git", - "state" : { - "revision" : "0139c665ebb45e6a9fbdb68aabfd7c39f3fe0071", - "version" : "2.2.2" - } - }, - { - "identity" : "nimble", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Quick/Nimble.git", - "state" : { - "revision" : "edaedc1ec86f14ac6e2ca495b94f0ff7150d98d0", - "version" : "12.3.0" - } - }, - { - "identity" : "quick", - "kind" : "remoteSourceControl", - "location" : "https://github.com/Quick/Quick.git", - "state" : { - "revision" : "1163a1b1b114a657c7432b63dd1f92ce99fe11a6", - "version" : "7.6.2" - } - }, - { - "identity" : "swift-algorithms", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-algorithms.git", - "state" : { - "revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", - "version" : "1.2.0" - } - }, - { - "identity" : "swift-argument-parser", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-argument-parser.git", - "state" : { - "revision" : "41982a3656a71c768319979febd796c6fd111d5c", - "version" : "1.5.0" - } - }, { "identity" : "swift-collections", "kind" : "remoteSourceControl", @@ -64,15 +10,6 @@ "version" : "1.1.4" } }, - { - "identity" : "swift-numerics", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-numerics.git", - "state" : { - "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", - "version" : "1.0.2" - } - }, { "identity" : "swiftlintplugins", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index 5cabbf0..eb4e707 100644 --- a/Package.swift +++ b/Package.swift @@ -13,8 +13,6 @@ let package = Package( targets: ["DependencyGraphs"]) ], dependencies: [ - .package(url: "https://github.com/Quick/Quick.git", from: "7.0.0"), - .package(url: "https://github.com/Quick/Nimble.git", from: "12.0.0"), .package( url: "https://github.com/apple/swift-collections.git", .upToNextMinor(from: "1.1.0") @@ -32,7 +30,7 @@ let package = Package( ), .testTarget( name: "DependencyGraphsTests", - dependencies: ["DependencyGraphs", "Quick", "Nimble"] + dependencies: ["DependencyGraphs"] ), ] ) diff --git a/Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexTests.swift b/Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexTests.swift new file mode 100644 index 0000000..1aa6b2e --- /dev/null +++ b/Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexTests.swift @@ -0,0 +1,24 @@ +import Testing + +@testable import DependencyGraphs + +@Suite("C4 with vertices v1, v2, v3 and v4") struct C4ContainsVertexTests { + @Test("contains the vertex v1") func v1() { + #expect(TestGraph.directedC4().contains(vertex: vertex1) == true) + } + + @Test("does not contain the vertex v5") func notV5() { + #expect(TestGraph.directedC4().contains(vertex: vertex5) == false) + } + + @Test("contains the vertex v1' with v1' ≠ v1 and v1'.id = v1.id") func id1() { + let vertexWithId1 = Vertex(id: vertex1.id, label: "not 1") + #expect(TestGraph.directedC4().contains(vertex: vertexWithId1) == true) + } + + @Test("does not contain the vertex v1' with v1' ≠ v1 and v1'.label = v1.label") func notLabel1() { + // C4 has only vertices with the ids 1, 2, 3 and 4. + let vertexWithLabel1 = Vertex(id: 5, label: "1") + #expect(TestGraph.directedC4().contains(vertex: vertexWithLabel1) == false) + } +} diff --git a/Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexWithTests.swift b/Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexWithTests.swift new file mode 100644 index 0000000..0f4bd2e --- /dev/null +++ b/Tests/SwiftDependencyGraphsTests/ContainsTests/C4ContainsVertexWithTests.swift @@ -0,0 +1,37 @@ +import Testing + +@testable import DependencyGraphs + +@Suite("C4 with vertices v1, v2, v3 and v4") struct C4ContainsVertexWithTests { + @Test("contains a vertex with an odd id") func oddId() { + #expect( + TestGraph.directedC4().contains(vertexWith: { vertexInGraph in + !vertexInGraph.id.isMultiple(of: 2) + }) == true + ) + } + + @Test("does not contain a vertex with an id that is divisible by 5") func notDivisibleBy5() { + #expect( + TestGraph.directedC4().contains(vertexWith: { vertexInGraph in + vertexInGraph.id.isMultiple(of: 5) + }) == false + ) + } + + @Test("contains a vertex with a label that starts with 3") func labelStartsWith3() { + #expect( + TestGraph.directedC4().contains(vertexWith: { vertexInGraph in + vertexInGraph.label.starts(with: "3") + }) == true + ) + } + + @Test("does not contain a vertex with a label that ends with .") func labelEndsWithDot() { + #expect( + TestGraph.directedC4().contains(vertexWith: { vertexInGraph in + vertexInGraph.label.hasSuffix(".") + }) == false + ) + } +} diff --git a/Tests/SwiftDependencyGraphsTests/ContainsTests/EmptyGraph.swift b/Tests/SwiftDependencyGraphsTests/ContainsTests/EmptyGraph.swift new file mode 100644 index 0000000..36c5eb9 --- /dev/null +++ b/Tests/SwiftDependencyGraphsTests/ContainsTests/EmptyGraph.swift @@ -0,0 +1,25 @@ +import Testing + +@testable import DependencyGraphs + +@Suite("the empty graph") struct ContainsVertexWithTests { + + @Test("does not contain the vertex v") func notVertexV() { + #expect(TestGraph.empty.contains(vertex: vertex1) == false) + } + + @Test("does not contain a vertex with an even id") func notEvenId() { + #expect( + TestGraph.empty.contains(vertexWith: { vertexInGraph in vertexInGraph.id.isMultiple(of: 2) + }) == false + ) + } + + @Test("does not contain a vertex with a label that starts with a") func notLabelA() { + #expect( + TestGraph.empty.contains(vertexWith: { vertexInGraph in + vertexInGraph.label.starts(with: "a") + }) == false + ) + } +} diff --git a/Tests/SwiftDependencyGraphsTests/ContainsVertexWithTests.swift b/Tests/SwiftDependencyGraphsTests/ContainsVertexWithTests.swift deleted file mode 100644 index c1c5a8a..0000000 --- a/Tests/SwiftDependencyGraphsTests/ContainsVertexWithTests.swift +++ /dev/null @@ -1,91 +0,0 @@ -import Nimble -import Quick - -@testable import DependencyGraphs - -class ContainsVertexWithTests: QuickSpec { - // swiftlint:disable:next function_body_length - override class func spec() { - - // C4 has only vertices with the ids 1, 2, 3 and 4. - let vertexWithLabel1 = Vertex(id: 5, label: "1") - let vertexWithId1 = Vertex(id: vertex1.id, label: "not 1") - - describe("C4 with vertices v1, v2, v3 and v4") { - it("contains the vertex v1") { - expect(TestGraph.directedC4().contains(vertex: vertex1)).to(beTrue()) - } - - it("does not contain the vertex v5") { - expect(TestGraph.directedC4().contains(vertex: vertex5)).to(beFalse()) - } - - it("contains the vertex v1' with v1' ≠ v1 and v1'.id = v1.id") { - expect(TestGraph.directedC4().contains(vertex: vertexWithId1)).to(beTrue()) - } - - it("does not contain the vertex v1' with v1' ≠ v1 and v1'.label = v1.label") { - expect(TestGraph.directedC4().contains(vertex: vertexWithLabel1)).to( - beFalse()) - } - - it("contains a vertex with an odd id") { - expect( - TestGraph.directedC4().contains(vertexWith: { vertexInGraph in - !vertexInGraph.id.isMultiple(of: 2) - }) - ).to( - beTrue()) - } - - it("does not contain a vertex with an id that is divisible by 5") { - expect( - TestGraph.directedC4().contains(vertexWith: { vertexInGraph in - vertexInGraph.id.isMultiple(of: 5) - }) - ).to( - beFalse()) - } - - it("contains a vertex with a label that starts with 3") { - expect( - TestGraph.directedC4().contains(vertexWith: { vertexInGraph in - vertexInGraph.label.starts(with: "3") - }) - ).to( - beTrue()) - } - - it("does not contain a vertex with a label that ends with .") { - expect( - TestGraph.directedC4().contains(vertexWith: { vertexInGraph in - vertexInGraph.label.hasSuffix(".") - }) - ).to( - beFalse()) - } - } - - describe("the empty graph") { - it("does not contain the vertex v") { - expect(TestGraph.empty.contains(vertex: vertex1)).to(beFalse()) - } - - it("does not contain a vertex with an even id") { - expect( - TestGraph.empty.contains(vertexWith: { vertexInGraph in vertexInGraph.id.isMultiple(of: 2) - }) - ).to(beFalse()) - } - - it("does not contain a vertex with a label that starts with a") { - expect( - TestGraph.empty.contains(vertexWith: { vertexInGraph in - vertexInGraph.label.starts(with: "a") - }) - ).to( - beFalse()) - } - } - } -} diff --git a/Tests/SwiftDependencyGraphsTests/Dfs/Path.swift b/Tests/SwiftDependencyGraphsTests/Dfs/Path.swift index 0d9ce9d..8f0a663 100644 --- a/Tests/SwiftDependencyGraphsTests/Dfs/Path.swift +++ b/Tests/SwiftDependencyGraphsTests/Dfs/Path.swift @@ -1,58 +1,48 @@ -import Nimble -import Quick +import Testing @testable import DependencyGraphs -class DfsPathTests: QuickSpec { - override class func spec() { - describe("starting from vertex 1 in forwards direction") { - describe("visits all vertices") { - it("with the public method") { - expect( - TestGraph.path().depthFirstSearch( - startingFrom: vertex1, in: .forwards, reduceWith: appendReducer, withInitialValue: [] - ) - ) - .to(equal([vertex1, vertex2, vertex3, vertex4, vertex5])) - } +@Suite("starting from vertex 1 in forwards direction") struct DfsPathTests { + @Suite("visits all vertices") struct VisitAllVerticesTests { + @Test("with the public method") func dfs() { + #expect( + TestGraph.path().depthFirstSearch( + startingFrom: vertex1, in: .forwards, reduceWith: appendReducer, withInitialValue: [] + ) + == [vertex1, vertex2, vertex3, vertex4, vertex5]) + } - it("with the private method") { - expect( - TestGraph.path().depthFirstSearchImpl( - startingFrom: vertex1, in: .forwards, withVisited: [], reduceWith: appendReducer, - withInitialValue: []) - ) - .to(equal([vertex1, vertex2, vertex3, vertex4, vertex5])) - } - } + @Test("with the private method") func dfsImpl() { + #expect( + TestGraph.path().depthFirstSearchImpl( + startingFrom: vertex1, in: .forwards, withVisited: [], reduceWith: appendReducer, + withInitialValue: []) + == [vertex1, vertex2, vertex3, vertex4, vertex5]) + } + } - it("stops at 2 because 3 was already discovered") { - expect( - TestGraph.path().depthFirstSearchImpl( - startingFrom: vertex1, in: .forwards, withVisited: [vertex3], - reduceWith: appendReducer, withInitialValue: []) - ) - .to(equal([vertex1, vertex2])) - } + @Test("stops at 2 because 3 was already discovered") func stops() { + #expect( + TestGraph.path().depthFirstSearchImpl( + startingFrom: vertex1, in: .forwards, withVisited: [vertex3], + reduceWith: appendReducer, withInitialValue: []) + == [vertex1, vertex2]) + } - it("visits no vertices because all were already discovered") { - expect( - TestGraph.path().depthFirstSearchImpl( - startingFrom: vertex1, in: .forwards, - withVisited: [vertex1, vertex2, vertex3, vertex4, vertex5], - reduceWith: appendReducer, withInitialValue: emptyVertexList) - ) - .to(equal([])) - } + @Test("visits no vertices because all were already discovered") func allDiscovered() { + #expect( + TestGraph.path().depthFirstSearchImpl( + startingFrom: vertex1, in: .forwards, + withVisited: [vertex1, vertex2, vertex3, vertex4, vertex5], + reduceWith: appendReducer, withInitialValue: emptyVertexList) + == []) + } - it("visits no vertices because 1 was already discovered") { - expect( - TestGraph.path().depthFirstSearchImpl( - startingFrom: vertex1, in: .forwards, withVisited: [vertex1], - reduceWith: appendReducer, withInitialValue: emptyVertexList) - ) - .to(equal([])) - } - } + @Test("visits no vertices because 1 was already discovered") func nextDiscovered() { + #expect( + TestGraph.path().depthFirstSearchImpl( + startingFrom: vertex1, in: .forwards, withVisited: [vertex1], + reduceWith: appendReducer, withInitialValue: emptyVertexList) + == []) } } diff --git a/Tests/SwiftDependencyGraphsTests/SwiftDependencyGraphsTests.swift b/Tests/SwiftDependencyGraphsTests/SwiftDependencyGraphsTests.swift deleted file mode 100644 index af51269..0000000 --- a/Tests/SwiftDependencyGraphsTests/SwiftDependencyGraphsTests.swift +++ /dev/null @@ -1,7 +0,0 @@ -import Testing - -@testable import DependencyGraphs - -@Test func example() async throws { - // Write your test here and use APIs like `#expect(...)` to check expected conditions. -}