Hi all,
I'm trying to build on Linux some unit tests that successfully build on Mac, and have discovered that generics do not seem to be properly supported as of Swift 5.6 (despite working on Mac since Xcode 12.5).
Simple demonstration case:
mkdir test && cd test
swift package init
cat <<EOT >./Tests/testTests/testTests.swift
import XCTest
class Colour {
required init() {}
}
class Green: Colour {}
class Blue: Colour {}
class ColourTest<T>: XCTestCase where T: Colour {
func testExample() throws {
let t = T()
XCTAssertNotNil(t)
}
}
class GreenTest: ColourTest<Green> {}
class BlueTest: ColourTest<Blue> {}
EOT
swift test
Result:
/home/ubuntu/test/.build/x86_64-unknown-linux-gnu/debug/testPackageTests.derived/testTests.swift:6:16: error: static stored properties not supported in generic types
static let __allTests = [
~~~~~~ ^
Indeed, this is what testPackageTests.derived/testTests.swift
looks like:
import XCTest
@testable import testTests
fileprivate extension ColourTest {
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
static let __allTests = [
("testExample", testExample),
]
}
@available(*, deprecated, message: "Not actually deprecated. Marked as deprecated to allow inclusion of deprecated tests (which test deprecated functionality) without warnings")
func __testTests__allTests() -> [XCTestCaseEntry] {
return [
testCase(ColourTest.__allTests),
]
ColourTest
is of course a generic class, so it's apparently forbidden to declare the static property on it.
Is a remedy for this known to be on the roadmap? (Should I have posted this under a different category?)
thanks,
-ben