Skip to content

Commit

Permalink
working on adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
leogdion committed Jul 30, 2024
1 parent c9cbc1d commit 3297ad1
Show file tree
Hide file tree
Showing 28 changed files with 140 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,5 @@ xcuserdata
!Demo/SublimationDemoApp.xcodeproj
.mint
# End of https://www.toptal.com/developers/gitignore/api/swift,swiftpm,swiftpackagemanager,xcode,macos

test_output.log
27 changes: 0 additions & 27 deletions Demo/SublimationDemoServer/Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,6 @@
"version" : "4.5.2"
}
},
{
"identity" : "prch",
"kind" : "remoteSourceControl",
"location" : "https://github.com/brightdigit/Prch.git",
"state" : {
"revision" : "600b49cc7a77271ea3d2a9f9e449be081562a087",
"version" : "0.2.1"
}
},
{
"identity" : "prchnio",
"kind" : "remoteSourceControl",
"location" : "https://github.com/brightdigit/PrchNIO.git",
"state" : {
"revision" : "337d0b2f77b0c4ad5b5b3bad6768a9ecd70b003c",
"version" : "0.2.0-beta.1"
}
},
{
"identity" : "prchvapor",
"kind" : "remoteSourceControl",
"location" : "https://github.com/brightdigit/PrchVapor.git",
"state" : {
"revision" : "8c19c645f9c2763014885e42a42096ae61da636b",
"version" : "0.2.0-beta.2"
}
},
{
"identity" : "routing-kit",
"kind" : "remoteSourceControl",
Expand Down
4 changes: 4 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ let package = Package(
.product(name: "Logging", package: "swift-log")
],
swiftSettings: swiftSettings
),
.testTarget(
name: "SublimationTests",
dependencies: ["Sublimation"]
)
]
)
Expand Down
4 changes: 4 additions & 0 deletions Packages/Ngrokit/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ let package = Package(
.product(name: "OpenAPIRuntime", package: "swift-openapi-runtime")
],
swiftSettings: swiftSettings
),
.testTarget(
name: "NgrokitTests",
dependencies: ["Ngrokit"]
)
]
)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions Packages/SublimationBonjour/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ let package = Package(
.product(name: "SwiftProtobuf", package: "swift-protobuf")
],
swiftSettings: swiftSettings
),
.testTarget(
name: "SublimationBonjourTests",
dependencies: ["SublimationBonjour"]
)
]
)
Expand Down
8 changes: 8 additions & 0 deletions Packages/SublimationNgrok/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ let package = Package(
name: "SublimationKVdb",
dependencies: ["SublimationTunnel"],
swiftSettings: swiftSettings
),
.testTarget(
name: "SublimationKVdbTests",
dependencies: ["SublimationKVdb"]
),
.testTarget(
name: "SublimationTunnelTests",
dependencies: ["SublimationTunnel"]
)
]
)
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions Packages/SublimationService/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ let package = Package(
.product(name: "ServiceLifecycle", package: "swift-service-lifecycle")
],
swiftSettings: swiftSettings
),
.testTarget(
name: "SublimationServiceTests",
dependencies: ["SublimationService"]
)
]
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ServiceTests.swift
// SublimationService
//
// Created by Leo Dion on 7/30/24.
//

import XCTest

final class ServiceTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
4 changes: 4 additions & 0 deletions Packages/SublimationVapor/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ let package = Package(
)
],
swiftSettings: swiftSettings
),
.testTarget(
name: "SublimationVaporTests",
dependencies: ["SublimationVapor"]
)
]
)
Expand Down
35 changes: 35 additions & 0 deletions Tests/SublimationTests/SublimationTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// SublimationTests.swift
// Sublimation
//
// Created by Leo Dion on 7/30/24.
//

import XCTest

final class SublimationTests: XCTestCase {

override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
}

func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct results.
// Any test you write for XCTest can be annotated as throws and async.
// Mark your test throws to produce an unexpected failure when your test encounters an uncaught error.
// Mark your test async to allow awaiting for asynchronous code to complete. Check the results with assertions afterwards.
}

func testPerformanceExample() throws {
// This is an example of a performance test case.
self.measure {
// Put the code you want to measure the time of here.
}
}

}
40 changes: 40 additions & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/bin/bash

# Function to run swift test and handle failures
run_test() {
local dir="$1"
local basename=`realpath $dir | xargs -I{} basename {}`
echo "Running tests in $dir"
(cd "$dir" && swift test) &> "$dir/test_output.log"
if [ $? -ne 0 ]; then
echo "Tests failed in $basename. Check $dir/test_output.log for details."
# Kill all background jobs
kill $(jobs -p) 2>/dev/null
exit 1
fi
echo "Tests passed in $basename"
}

# Find all directories containing Swift packages in the specified directory (not subdirectories)
package_dirs=(".")
while IFS= read -r -d $'\0'; do
package_dirs+=("$REPLY")
done < <(find . -mindepth 1 -maxdepth 2 -type d -exec test -e '{}/Package.swift' \; -print0)

# Run tests in parallel
pids=()
for dir in "${package_dirs[@]}"; do
run_test "$dir" &
pids+=($!)
done

# Wait for all tests to complete
for pid in "${pids[@]}"; do
wait $pid
if [ $? -ne 0 ]; then
echo "One of the tests failed. Stopping remaining tests."
exit 1
fi
done

echo "All tests passed."

0 comments on commit 3297ad1

Please sign in to comment.