Skip to content

Commit 5653e08

Browse files
committed
Move conditional compilation directive inside tests.
This ensures that the test function always exists, even if the symbol is not defined, so that `--generate-linuxmain` contains the symbol in both cases. When the symbol is undefined, the empty test will vacuously succeed.
1 parent fbd6614 commit 5653e08

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

Tests/SwiftFormatPrettyPrintTests/DifferentiationAttributeTests.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ final class DifferentiationAttributeTests: PrettyPrintTestCase {
4343
assertPrettyPrintEqual(input: input, expected: expected, linelength: 43)
4444
}
4545

46-
#if HAS_DERIVATIVE_REGISTRATION_ATTRIBUTE
47-
func testDerivative() {
46+
func testDerivative() {
47+
#if HAS_DERIVATIVE_REGISTRATION_ATTRIBUTE
4848
let input =
4949
"""
5050
@derivative(of: foo, wrt: x)
@@ -78,9 +78,11 @@ final class DifferentiationAttributeTests: PrettyPrintTestCase {
7878
"""
7979

8080
assertPrettyPrintEqual(input: input, expected: expected, linelength: 28)
81-
}
81+
#endif
82+
}
8283

83-
func testTranspose() {
84+
func testTranspose() {
85+
#if HAS_DERIVATIVE_REGISTRATION_ATTRIBUTE
8486
let input =
8587
"""
8688
@transpose(of: foo, wrt: 0)
@@ -114,6 +116,6 @@ final class DifferentiationAttributeTests: PrettyPrintTestCase {
114116
"""
115117

116118
assertPrettyPrintEqual(input: input, expected: expected, linelength: 27)
117-
}
118-
#endif
119+
#endif
120+
}
119121
}

Tests/SwiftFormatPrettyPrintTests/XCTestManifests.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,9 @@ extension DifferentiationAttributeTests {
207207
// `swift test --generate-linuxmain`
208208
// to regenerate.
209209
static let __allTests__DifferentiationAttributeTests = [
210+
("testDerivative", testDerivative),
210211
("testDifferentiable", testDifferentiable),
212+
("testTranspose", testTranspose),
211213
]
212214
}
213215

0 commit comments

Comments
 (0)