Skip to content

Commit 51dd952

Browse files
committed
Slightly nicer way to skip tests
1 parent d0bf886 commit 51dd952

11 files changed

+103
-209
lines changed

Tests/PackageCollectionsSigningTests/CertificatePolicyTests.swift

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ import TSCBasic
1818

1919
class CertificatePolicyTests: XCTestCase {
2020
func test_RSA_validate_happyCase() throws {
21-
if !isSupportedPlatform {
22-
try XCTSkipIf(true)
23-
}
21+
try skipIfUnsupportedPlatform()
2422

2523
fixture(name: "Collections") { directoryPath in
2624
let certPath = directoryPath.appending(components: "Signing", "Test_rsa.cer")
@@ -40,9 +38,7 @@ class CertificatePolicyTests: XCTestCase {
4038
}
4139

4240
func test_EC_validate_happyCase() throws {
43-
if !isSupportedPlatform {
44-
try XCTSkipIf(true)
45-
}
41+
try skipIfUnsupportedPlatform()
4642

4743
fixture(name: "Collections") { directoryPath in
4844
let certPath = directoryPath.appending(components: "Signing", "Test_ec.cer")
@@ -62,9 +58,7 @@ class CertificatePolicyTests: XCTestCase {
6258
}
6359

6460
func test_validate_untrustedRoot() throws {
65-
if !isSupportedPlatform {
66-
try XCTSkipIf(true)
67-
}
61+
try skipIfUnsupportedPlatform()
6862

6963
fixture(name: "Collections") { directoryPath in
7064
let certPath = directoryPath.appending(components: "Signing", "Test_rsa.cer")
@@ -89,9 +83,7 @@ class CertificatePolicyTests: XCTestCase {
8983
}
9084

9185
func test_validate_expiredCert() throws {
92-
if !isSupportedPlatform {
93-
try XCTSkipIf(true)
94-
}
86+
try skipIfUnsupportedPlatform()
9587

9688
fixture(name: "Collections") { directoryPath in
9789
let certPath = directoryPath.appending(components: "Signing", "Test_rsa.cer")
@@ -121,9 +113,7 @@ class CertificatePolicyTests: XCTestCase {
121113
try XCTSkipIf(true)
122114
#endif
123115

124-
if !isSupportedPlatform {
125-
try XCTSkipIf(true)
126-
}
116+
try skipIfUnsupportedPlatform()
127117

128118
fixture(name: "Collections") { directoryPath in
129119
let certPath = directoryPath.appending(components: "Signing", "development-revoked.cer")
@@ -168,9 +158,7 @@ class CertificatePolicyTests: XCTestCase {
168158
try XCTSkipIf(true)
169159
#endif
170160

171-
if !isSupportedPlatform {
172-
try XCTSkipIf(true)
173-
}
161+
try skipIfUnsupportedPlatform()
174162

175163
fixture(name: "Collections") { directoryPath in
176164
let certPath = directoryPath.appending(components: "Signing", "development.cer")
@@ -234,9 +222,7 @@ class CertificatePolicyTests: XCTestCase {
234222
try XCTSkipIf(true)
235223
#endif
236224

237-
if !isSupportedPlatform {
238-
try XCTSkipIf(true)
239-
}
225+
try skipIfUnsupportedPlatform()
240226

241227
fixture(name: "Collections") { directoryPath in
242228
// This must be an Apple Distribution cert
@@ -301,9 +287,7 @@ class CertificatePolicyTests: XCTestCase {
301287
try XCTSkipIf(true)
302288
#endif
303289

304-
if !isSupportedPlatform {
305-
try XCTSkipIf(true)
306-
}
290+
try skipIfUnsupportedPlatform()
307291

308292
fixture(name: "Collections") { directoryPath in
309293
let certPath = directoryPath.appending(components: "Signing", "development.cer")
@@ -370,9 +354,7 @@ class CertificatePolicyTests: XCTestCase {
370354
try XCTSkipIf(true)
371355
#endif
372356

373-
if !isSupportedPlatform {
374-
try XCTSkipIf(true)
375-
}
357+
try skipIfUnsupportedPlatform()
376358

377359
fixture(name: "Collections") { directoryPath in
378360
// This must be an Apple Distribution cert

Tests/PackageCollectionsSigningTests/CertificateTests.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import TSCBasic
1717

1818
class CertificateTests: XCTestCase {
1919
func test_withRSAKey_fromDER() throws {
20-
if !isSupportedPlatform {
21-
try XCTSkipIf(true)
22-
}
20+
try skipIfUnsupportedPlatform()
2321

2422
fixture(name: "Collections") { directoryPath in
2523
let path = directoryPath.appending(components: "Signing", "Test_rsa.cer")
@@ -42,9 +40,7 @@ class CertificateTests: XCTestCase {
4240
}
4341

4442
func test_withECKey_fromDER() throws {
45-
if !isSupportedPlatform {
46-
try XCTSkipIf(true)
47-
}
43+
try skipIfUnsupportedPlatform()
4844

4945
fixture(name: "Collections") { directoryPath in
5046
let path = directoryPath.appending(components: "Signing", "Test_ec.cer")

Tests/PackageCollectionsSigningTests/KeyTests+EC.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import TSCBasic
1717

1818
class ECKeyTests: XCTestCase {
1919
func testPublicKeyFromCertificate() throws {
20-
if !isSupportedPlatform {
21-
try XCTSkipIf(true)
22-
}
20+
try skipIfUnsupportedPlatform()
2321

2422
fixture(name: "Collections") { directoryPath in
2523
let path = directoryPath.appending(components: "Signing", "Test_ec.cer")
@@ -31,17 +29,13 @@ class ECKeyTests: XCTestCase {
3129
}
3230

3331
func testPublicKeyFromPEM() throws {
34-
if !isSupportedPlatform {
35-
try XCTSkipIf(true)
36-
}
32+
try skipIfUnsupportedPlatform()
3733

3834
XCTAssertNoThrow(try ECPublicKey(pem: ecPublicKey.bytes))
3935
}
4036

4137
func testPrivateKeyFromPEM() throws {
42-
if !isSupportedPlatform {
43-
try XCTSkipIf(true)
44-
}
38+
try skipIfUnsupportedPlatform()
4539

4640
XCTAssertNoThrow(try ECPrivateKey(pem: ecPrivateKey.bytes))
4741
}

Tests/PackageCollectionsSigningTests/KeyTests+RSA.swift

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import TSCBasic
1717

1818
class RSAKeyTests: XCTestCase {
1919
func testPublicKeyFromCertificate() throws {
20-
if !isSupportedPlatform {
21-
try XCTSkipIf(true)
22-
}
20+
try skipIfUnsupportedPlatform()
2321

2422
fixture(name: "Collections") { directoryPath in
2523
let path = directoryPath.appending(components: "Signing", "Test_rsa.cer")
@@ -31,17 +29,13 @@ class RSAKeyTests: XCTestCase {
3129
}
3230

3331
func testPublicKeyFromPEM() throws {
34-
if !isSupportedPlatform {
35-
try XCTSkipIf(true)
36-
}
32+
try skipIfUnsupportedPlatform()
3733

3834
XCTAssertNoThrow(try RSAPublicKey(pem: rsaPublicKey.bytes))
3935
}
4036

4137
func testPrivateKeyFromPEM() throws {
42-
if !isSupportedPlatform {
43-
try XCTSkipIf(true)
44-
}
38+
try skipIfUnsupportedPlatform()
4539

4640
XCTAssertNoThrow(try RSAPrivateKey(pem: rsaPrivateKey.bytes))
4741
}

Tests/PackageCollectionsSigningTests/PackageCollectionSigningTest.swift

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ import TSCBasic
1919

2020
class PackageCollectionSigningTests: XCTestCase {
2121
func test_RSA_signAndValidate_happyCase() throws {
22-
if !isSupportedPlatform {
23-
try XCTSkipIf(true)
24-
}
22+
try skipIfUnsupportedPlatform()
2523

2624
fixture(name: "Collections") { directoryPath in
2725
let jsonDecoder = JSONDecoder.makeWithDefaults()
@@ -53,9 +51,7 @@ class PackageCollectionSigningTests: XCTestCase {
5351
}
5452

5553
func test_RSA_signAndValidate_collectionMismatch() throws {
56-
if !isSupportedPlatform {
57-
try XCTSkipIf(true)
58-
}
54+
try skipIfUnsupportedPlatform()
5955

6056
fixture(name: "Collections") { directoryPath in
6157
let collection1 = PackageCollectionModel.V1.Collection(
@@ -111,9 +107,7 @@ class PackageCollectionSigningTests: XCTestCase {
111107
}
112108

113109
func test_EC_signAndValidate_happyCase() throws {
114-
if !isSupportedPlatform {
115-
try XCTSkipIf(true)
116-
}
110+
try skipIfUnsupportedPlatform()
117111

118112
fixture(name: "Collections") { directoryPath in
119113
let jsonDecoder = JSONDecoder.makeWithDefaults()
@@ -145,9 +139,7 @@ class PackageCollectionSigningTests: XCTestCase {
145139
}
146140

147141
func test_EC_signAndValidate_collectionMismatch() throws {
148-
if !isSupportedPlatform {
149-
try XCTSkipIf(true)
150-
}
142+
try skipIfUnsupportedPlatform()
151143

152144
fixture(name: "Collections") { directoryPath in
153145
let collection1 = PackageCollectionModel.V1.Collection(
@@ -208,9 +200,7 @@ class PackageCollectionSigningTests: XCTestCase {
208200
try XCTSkipIf(true)
209201
#endif
210202

211-
if !isSupportedPlatform {
212-
try XCTSkipIf(true)
213-
}
203+
try skipIfUnsupportedPlatform()
214204

215205
fixture(name: "Collections") { directoryPath in
216206
let jsonDecoder = JSONDecoder.makeWithDefaults()
@@ -302,9 +292,7 @@ class PackageCollectionSigningTests: XCTestCase {
302292
try XCTSkipIf(true)
303293
#endif
304294

305-
if !isSupportedPlatform {
306-
try XCTSkipIf(true)
307-
}
295+
try skipIfUnsupportedPlatform()
308296

309297
fixture(name: "Collections") { directoryPath in
310298
let jsonDecoder = JSONDecoder.makeWithDefaults()
@@ -397,9 +385,7 @@ class PackageCollectionSigningTests: XCTestCase {
397385
try XCTSkipIf(true)
398386
#endif
399387

400-
if !isSupportedPlatform {
401-
try XCTSkipIf(true)
402-
}
388+
try skipIfUnsupportedPlatform()
403389

404390
fixture(name: "Collections") { directoryPath in
405391
let jsonDecoder = JSONDecoder.makeWithDefaults()
@@ -453,9 +439,7 @@ class PackageCollectionSigningTests: XCTestCase {
453439
try XCTSkipIf(true)
454440
#endif
455441

456-
if !isSupportedPlatform {
457-
try XCTSkipIf(true)
458-
}
442+
try skipIfUnsupportedPlatform()
459443

460444
fixture(name: "Collections") { directoryPath in
461445
let jsonDecoder = JSONDecoder.makeWithDefaults()

Tests/PackageCollectionsSigningTests/SignatureTests.swift

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ import TSCBasic
1717

1818
class SignatureTests: XCTestCase {
1919
func test_RS256_generateAndValidate_happyCase() throws {
20-
if !isSupportedPlatform {
21-
try XCTSkipIf(true)
22-
}
20+
try skipIfUnsupportedPlatform()
2321

2422
fixture(name: "Collections") { directoryPath in
2523
let jsonEncoder = JSONEncoder()
@@ -45,9 +43,7 @@ class SignatureTests: XCTestCase {
4543
}
4644

4745
func test_RS256_generateAndValidate_keyMismatch() throws {
48-
if !isSupportedPlatform {
49-
try XCTSkipIf(true)
50-
}
46+
try skipIfUnsupportedPlatform()
5147

5248
fixture(name: "Collections") { directoryPath in
5349
let jsonEncoder = JSONEncoder()
@@ -76,9 +72,7 @@ class SignatureTests: XCTestCase {
7672
}
7773

7874
func test_ES256_generateAndValidate_happyCase() throws {
79-
if !isSupportedPlatform {
80-
try XCTSkipIf(true)
81-
}
75+
try skipIfUnsupportedPlatform()
8276

8377
fixture(name: "Collections") { directoryPath in
8478
let jsonEncoder = JSONEncoder()
@@ -104,9 +98,7 @@ class SignatureTests: XCTestCase {
10498
}
10599

106100
func test_ES256_generateAndValidate_keyMismatch() throws {
107-
if !isSupportedPlatform {
108-
try XCTSkipIf(true)
109-
}
101+
try skipIfUnsupportedPlatform()
110102

111103
fixture(name: "Collections") { directoryPath in
112104
let jsonEncoder = JSONEncoder()

Tests/PackageCollectionsSigningTests/SigningTests+ECKey.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import XCTest
1515

1616
class ECKeySigningTests: XCTestCase {
1717
func test_signAndValidate_happyCase() throws {
18-
if !isSupportedPlatform {
19-
try XCTSkipIf(true)
20-
}
18+
try skipIfUnsupportedPlatform()
2119

2220
let privateKey = try ECPrivateKey(pem: ecPrivateKey.bytes)
2321
let publicKey = try ECPublicKey(pem: ecPublicKey.bytes)
@@ -28,9 +26,7 @@ class ECKeySigningTests: XCTestCase {
2826
}
2927

3028
func test_signAndValidate_mismatch() throws {
31-
if !isSupportedPlatform {
32-
try XCTSkipIf(true)
33-
}
29+
try skipIfUnsupportedPlatform()
3430

3531
let privateKey = try ECPrivateKey(pem: ecPrivateKey.bytes)
3632
let publicKey = try ECPublicKey(pem: ecPublicKey.bytes)

Tests/PackageCollectionsSigningTests/SigningTests+RSAKey.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ import XCTest
1515

1616
class RSAKeySigningTests: XCTestCase {
1717
func test_signAndValidate_happyCase() throws {
18-
if !isSupportedPlatform {
19-
try XCTSkipIf(true)
20-
}
18+
try skipIfUnsupportedPlatform()
2119

2220
let privateKey = try RSAPrivateKey(pem: rsaPrivateKey.bytes)
2321
let publicKey = try RSAPublicKey(pem: rsaPublicKey.bytes)
@@ -28,9 +26,7 @@ class RSAKeySigningTests: XCTestCase {
2826
}
2927

3028
func test_signAndValidate_mismatch() throws {
31-
if !isSupportedPlatform {
32-
try XCTSkipIf(true)
33-
}
29+
try skipIfUnsupportedPlatform()
3430

3531
let privateKey = try RSAPrivateKey(pem: rsaPrivateKey.bytes)
3632
let publicKey = try RSAPublicKey(pem: rsaPublicKey.bytes)

Tests/PackageCollectionsSigningTests/Utilities.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,11 @@
1010

1111
import Dispatch
1212
import Foundation
13+
import XCTest
1314

1415
@testable import PackageCollectionsSigning
1516
import TSCBasic
1617

17-
#if os(macOS)
18-
let isSupportedPlatform = true
19-
#else
20-
let isSupportedPlatform = false
21-
#endif
22-
2318
// Update this when running ENABLE_REAL_CERT_TEST tests
2419
let expectedSubjectUserID = "<USER ID>"
2520

@@ -170,3 +165,12 @@ extension String {
170165
[UInt8](self.utf8)
171166
}
172167
}
168+
169+
extension XCTestCase {
170+
func skipIfUnsupportedPlatform() throws {
171+
#if os(macOS)
172+
#else
173+
throw XCTSkip("Skipping test on unsupported platform")
174+
#endif
175+
}
176+
}

0 commit comments

Comments
 (0)