forked from migueldeicaza/SwiftGodot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fail the GH build/test steps if the swift build/test actually failed. (…
…migueldeicaza#598) Currently, if the `swift build` or `swift test` commands fail, the GH action step will still be marked as succeeded. This seems to be an artefact of the way we were re-running the tests from within the Godot engine; it resulted in the overall failure count being 0 even if there were actual failures. This PR changes the way we run the tests, and should result in a non-zero exit status if a test does fail. It also separates the XCTest run and the Swift testing run into two steps. The default behaviour of `swift test` is to first run the XCTest engine, then run Swift testing engine. This results in the following confusing output at the end of the test run: ``` Test run started. Testing Library Version: 102 (arm64e-apple-macos13.0) Test run with 0 tests passed after 0.001 seconds. ``` This is the output from the Swift testing engine. Because all our tests are using XCTest, and we have no Swift testing tests, it is saying that 0 tests passed. As it's the last thing in the report, it's a bit confusing and for a while I thought that this was why the exit status was 0. To avoid this confusion, we can explicitly choose a test ending by passing `--disable-swift-testing` or `--disable-xctest`. I have done this in two separate steps, so that the output from each testing engine is clearer. The Swift testing engine step is a null-op right now, so we could remove it, but at some point we might want to migrate some tests to the new testing framework, so I figured it was worth having it there to avoid later confusion.
- Loading branch information
Showing
3 changed files
with
103 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | ||
// Created by Sam Deane on 31/10/24. | ||
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- | ||
|
||
import XCTest | ||
|
||
@testable import SwiftGodot | ||
|
||
/// Test case which runs all the other tests from within the Godot runtime. | ||
/// It doesn't actually matter when this suite is run, but we name it with | ||
/// __ to try to make it run first, since `swift test` seems to run test | ||
/// suites in alphabetical order. | ||
class __GodotTestRunner: XCTestCase { | ||
/// Failure count from the tests run in Godot | ||
static var failureCount = 0 | ||
|
||
/// By the time this test runs, all the other tests have already run | ||
/// in the Godot runtime. We can check the failure count here to see | ||
/// if any tests failed. | ||
func testRunEverythingInGodot() { | ||
XCTAssert(Self.failureCount == 0, "Some tests failed when running in Godot") | ||
} | ||
|
||
/// Set up the Godot runtime and run all the tests in it. | ||
override func run() { | ||
// this call will be re-entered inside the Godot runtime, so we | ||
// need to check if the runtime is already initialized. | ||
if !GodotRuntime.isInitialized { | ||
GodotRuntime.run { | ||
/// make a copy of all the tests and run them in Godot | ||
let allTests = XCTestSuite.default | ||
let suite = XCTestSuite(name: "All Tests In Godot") | ||
for test in allTests.tests { | ||
suite.addTest(test) | ||
} | ||
suite.run() | ||
|
||
// record the failure count | ||
Self.failureCount = suite.testRun!.totalFailureCount | ||
|
||
// shut down the Godot runtime | ||
GodotRuntime.stop() | ||
} | ||
super.run() | ||
} | ||
} | ||
} |