Skip to content

Commit 98111a3

Browse files
committed
Update Test.traits setter to simply filter applicable values rather than crashing when non-applicable values were encountered
1 parent 15837ac commit 98111a3

1 file changed

Lines changed: 8 additions & 10 deletions

File tree

Sources/Testing/Test.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,15 @@ public struct Test: Sendable {
9090
_properties.value.traits
9191
}
9292
set {
93-
// Prevent programmatically adding suite traits to test functions or test
94-
// traits to test suites.
95-
func traitsAreCorrectlyTyped() -> Bool {
96-
if isSuite {
97-
return newValue.allSatisfy { $0 is any SuiteTrait }
98-
} else {
99-
return newValue.allSatisfy { $0 is any TestTrait }
100-
}
93+
// When setting traits, we take care to only apply those that are
94+
// applicable. For example, if a trait only conforms to `SuiteTrait` and
95+
// not `TestTrait`, it should only be applied to suites, and not tests.
96+
let applicableTraits = if isSuite {
97+
newValue.filter { $0 is any SuiteTrait }
98+
} else {
99+
newValue.filter { $0 is any TestTrait }
101100
}
102-
precondition(traitsAreCorrectlyTyped(), "Programmatically added an inapplicable trait to test \(self)")
103-
_setValue(newValue, forKeyPath: \.traits)
101+
_setValue(applicableTraits, forKeyPath: \.traits)
104102
}
105103
}
106104

0 commit comments

Comments
 (0)