Skip to content

Commit 8b71a84

Browse files
committed
Test: Add platform helpers
Add helpers related to the current platform to assist with conditionally running test cases.
1 parent cb829d8 commit 8b71a84

File tree

2 files changed

+88
-0
lines changed

2 files changed

+88
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
2+
3+
//===----------------------------------------------------------------------===//
4+
//
5+
// This source file is part of the Swift open source project
6+
//
7+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
8+
// Licensed under Apache License v2.0 with Runtime Library Exception
9+
//
10+
// See http://swift.org/LICENSE.txt for license information
11+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
12+
//
13+
//===----------------------------------------------------------------------===//
14+
import Basics
15+
16+
import Testing
17+
18+
public func isWindows() -> Bool {
19+
#if os(Windows)
20+
return true
21+
#else
22+
return false
23+
#endif
24+
}
25+
26+
public func isLinux() -> Bool {
27+
#if os(Linux)
28+
return true
29+
#else
30+
return false
31+
#endif
32+
}
33+
34+
public func isMacOS() -> Bool {
35+
#if os(macOS)
36+
return true
37+
#else
38+
return false
39+
#endif
40+
}
41+
42+
public func isRealSigningIdentityTestEnabled() -> Bool {
43+
#if ENABLE_REAL_SIGNING_IDENTITY_TEST
44+
return true
45+
#else
46+
return false
47+
#endif
48+
}
49+
50+
public func isEnvironmentVariableSet(_ variableName: EnvironmentKey) -> Bool {
51+
guard let value = Environment.current[variableName] else { return false }
52+
return !value.isEmpty
53+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//===----------------------------------------------------------------------===//
2+
//
3+
// This source file is part of the Swift open source project
4+
//
5+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See http://swift.org/LICENSE.txt for license information
9+
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
13+
import _InternalTestSupport
14+
import Basics
15+
import Testing
16+
17+
struct testisEnvironmentVariableSet {
18+
@Test(
19+
arguments: [
20+
(name: "", expected: false),
21+
(name: "DOES_NOT_EXIST", expected: false),
22+
(name: "HOME", expected: true)
23+
]
24+
)
25+
func testisEnvironmentVariableSetReturnsExpectedValue(name: String, expected: Bool) {
26+
// GIVEN we have an environment variable name
27+
let variableName = EnvironmentKey(name)
28+
29+
// WHEN we call isEnvironmentVariableSet(varaiblename)
30+
let actual = isEnvironmentVariableSet(variableName)
31+
32+
// THEN we expect to return true
33+
#expect(actual == expected, "Actual is not as expected")
34+
}
35+
}

0 commit comments

Comments
 (0)