Files
swift-mirror/validation-test/Evolution/test_protocol_add_requirements.swift
Slava Pestov 6bf9ab19ff Add preliminary library evolution test for resiliently adding a new protocol requirement
This test ensures that the runtime correctly instantiates resilient conformances,
and that IRGen emits the correct metadata, allowing a conformance that was
compiled before a new requirement was added to present a default implementation
of this requirement.

For now, this runs with --no-backward-deployment, so we only test before/before,
before/after and after/after cases.

Getting after/before working is also an expected capability here, but requires
IRGen witness table emission to know which requirements were satisfied by
defaults, so that they can be dropped if they appear at the end of a witness
table. In turn, this requires serializing SILDefaultWitnessTables. This will
be added in a subsequent patch.

In addition to fixing the above case, I need to write additional tests and
possibly fix bugs related to more elaborate cases involving generics, as well as
default witnesses for properties and subscripts.
2016-03-03 07:37:00 -08:00

56 lines
1.1 KiB
Swift

// RUN: %target-resilience-test --no-backward-deployment
// REQUIRES: executable_test
import StdlibUnittest
import protocol_add_requirements
// Also import modules which are used by StdlibUnittest internally. This
// workaround is needed to link all required libraries in case we compile
// StdlibUnittest with -sil-serialize-all.
import SwiftPrivate
import SwiftPrivatePthreadExtras
#if _runtime(_ObjC)
import ObjectiveC
#endif
var ProtocolAddRequirementsTest = TestSuite("ProtocolAddRequirements")
struct Halogen : ElementProtocol {
var x: Int
func increment() -> Halogen {
return Halogen(x: x + 1)
}
}
func ==(h1: Halogen, h2: Halogen) -> Bool {
return h1.x == h2.x
}
struct ConformingType : AddRequirementsProtocol {
func importantOperation() -> Halogen {
return Halogen(x: 0)
}
#if AFTER
func unimportantOperation() -> Halogen {
return Halogen(x: 10)
}
#endif
}
ProtocolAddRequirementsTest.test("AddRequirements") {
let result = doSomething(ConformingType())
#if BEFORE
let expected = [0, 1, 2].map(Halogen.init)
#else
let expected = [0, 10, 11].map(Halogen.init)
#endif
expectEqual(result, expected)
}
runAllTests()