Skip to content

Commit

Permalink
Attempt solution at a custom XFail for XCTest..
Browse files Browse the repository at this point in the history
  • Loading branch information
bkhouri committed Mar 3, 2025
1 parent 2d64529 commit f3625a8
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 24 deletions.
30 changes: 30 additions & 0 deletions Sources/_InternalTestSupport/Commands.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,38 @@
import SPMBuildCore
import XCTest

public struct XFailCaseName {
let testName: String
let reason: String

public init(_ testName: String, because reason: String) {
self.testName = testName
self.reason = reason
}
}
open class BuildSystemProviderTestCase: XCTestCase {
open var buildSystemProvider: BuildSystemProvider.Kind {
fatalError("\(self) does not implement \(#function)")
}

open var xFailTestCaseNames: [XFailCaseName] {
return []
}

override open func recordFailure(withDescription description: String, inFile filePath: String, atLine lineNumber: Int, expected: Bool) {
// Get current test name:
print("--->> In recordFailure: Test name is >>>\(self.name)<<<")

if self.xFailTestCaseNames.map({ item in item.testName }).contains(self.name) {
// do nothing
print("--->> In recordFailure: Test name is >>>\(self.name)<<< is expected to fail, so mark as passed!!")
} else {
super.recordFailure(
withDescription: description,
inFile: filePath,
atLine: lineNumber,
expected: expected
)
}
}
}
29 changes: 23 additions & 6 deletions Tests/BuildTests/BuildPlanTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6880,17 +6880,34 @@ class BuildPlanSwiftBuildTests: BuildPlanTestCase {
return .swiftbuild
}

override open var xFailTestCaseNames: [XFailCaseName] {
return [
XFailCaseName(
String(describing: testDuplicateProductNamesWithNonDefaultLibsThrowError.self),
because: "This test is not expected to fail.. it should pass.",
),
XFailCaseName(
String(describing: testTargetsWithPackageAccess.self),
because: "Skip until swift build system can support this case",
),
// XFailCaseName(
// String(describing: testTestModule.self),
// because: "Skip until swift build system can support this case."
// )
]
}

override func testDuplicateProductNamesWithNonDefaultLibsThrowError() async throws {
try await super.testDuplicateProductNamesWithNonDefaultLibsThrowError()
}

override func testTargetsWithPackageAccess() async throws {
throw XCTSkip("Skip until swift build system can support this case.")
}
// override func testTargetsWithPackageAccess() async throws {
// throw XCTSkip("Skip until swift build system can support this case.")
// }

override func testTestModule() async throws {
throw XCTSkip("Skip until swift build system can support this case.")
}
// override func testTestModule() async throws {
// throw XCTSkip("Skip until swift build system can support this case.")
// }

override func testPackageNameFlag() async throws {
#if os(Windows)
Expand Down
65 changes: 47 additions & 18 deletions Tests/CommandsTests/RunCommandTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import XCTest

import class Basics.AsyncProcess

class RunCommandTestCase: BuildSystemProviderTestCase {
class RunCommandTestCase: CommandsBuildProviderTestCase {
override func setUpWithError() throws {
try XCTSkipIf(type(of: self) == RunCommandTestCase.self, "Pay no attention to the class behind the curtain.")
}
Expand Down Expand Up @@ -291,28 +291,57 @@ class RunCommandSwiftBuildTests: RunCommandTestCase {
try await super.testUsage()
}

override func testMultipleExecutableAndExplicitExecutable() async throws {
try XCTSkip("https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
override open var xFailTestCaseNames: [XFailCaseName] {
return [
XFailCaseName(
String(describing: testMultipleExecutableAndExplicitExecutable.self),
because: "https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal",
),
XFailCaseName(
String(describing: testUnknownProductAndArgumentPassing.self),
because: "https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal",
),
XFailCaseName(
String(describing: testPackageWithExcutableTargetsContainsPlatformConditionalsBuildsSuccessfullyInDebugConfig.self),
because: "Test fixture fails to build",
),
XFailCaseName(
String(describing: testPackageWithExcutableTargetsContainsPlatformConditionalsBuildsSuccessfullyInReleaseConfig.self),
because: "Test fixture fails to build",
),
XFailCaseName(
String(describing: testToolsetDebugger.self),
because: "Test fixture fails to build",
),
XFailCaseName(
String(describing: testUnreachableExecutable.self),
because: "Need to investigate test failure",
),
]
}

override func testUnknownProductAndArgumentPassing() async throws {
try XCTSkip("https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
}
// override func testMultipleExecutableAndExplicitExecutable() async throws {
// try XCTSkip("https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
// }

override func testPackageWithExcutableTargetsContainsPlatformConditionalsBuildsSuccessfullyInDebugConfig() async throws {
try XCTSkip("Test fixture fails to build")
}
// override func testUnknownProductAndArgumentPassing() async throws {
// try XCTSkip("https://github.com/swiftlang/swift-package-manager/issues/8279: Swift run using Swift Build does not output executable content to the terminal")
// }

override func testPackageWithExcutableTargetsContainsPlatformConditionalsBuildsSuccessfullyInReleaseConfig() async throws {
try XCTSkip("Test fixture fails to build")
}
// override func testPackageWithExcutableTargetsContainsPlatformConditionalsBuildsSuccessfullyInDebugConfig() async throws {
// try XCTSkip("Test fixture fails to build")
// }

override func testToolsetDebugger() async throws {
try XCTSkip("Test fixture fails to build")
}
// override func testPackageWithExcutableTargetsContainsPlatformConditionalsBuildsSuccessfullyInReleaseConfig() async throws {
// try XCTSkip("Test fixture fails to build")
// }

override func testUnreachableExecutable() async throws {
try XCTSkip("Need to investigate test failure")
}
// override func testToolsetDebugger() async throws {
// try XCTSkip("Test fixture fails to build")
// }

// override func testUnreachableExecutable() async throws {
// try XCTSkip("Need to investigate test failure")
// }

}

0 comments on commit f3625a8

Please sign in to comment.