-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helpers related to the current platform to assist with conditionally running test cases.
- Loading branch information
Showing
2 changed files
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
|
||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
import Basics | ||
|
||
import Testing | ||
|
||
public func isWindows() -> Bool { | ||
#if os(Windows) | ||
return true | ||
#else | ||
return false | ||
#endif | ||
} | ||
|
||
public func isLinux() -> Bool { | ||
#if os(Linux) | ||
return true | ||
#else | ||
return false | ||
#endif | ||
} | ||
|
||
public func isMacOS() -> Bool { | ||
#if os(macOS) | ||
return true | ||
#else | ||
return false | ||
#endif | ||
} | ||
|
||
public func isRealSigningIdentityTestEnabled() -> Bool { | ||
#if ENABLE_REAL_SIGNING_IDENTITY_TEST | ||
return true | ||
#else | ||
return false | ||
#endif | ||
} | ||
|
||
public func isEnvironmentVariableSet(_ variableName: EnvironmentKey) -> Bool { | ||
guard let value = Environment.current[variableName] else { return false } | ||
return !value.isEmpty | ||
} |
35 changes: 35 additions & 0 deletions
35
Tests/_InternalTestSupportTests/PlatformHelpersTests.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the Swift open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See http://swift.org/LICENSE.txt for license information | ||
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import _InternalTestSupport | ||
import Basics | ||
import Testing | ||
|
||
struct testisEnvironmentVariableSet { | ||
@Test( | ||
arguments: [ | ||
(name: "", expected: false), | ||
(name: "DOES_NOT_EXIST", expected: false), | ||
(name: "HOME", expected: true) | ||
] | ||
) | ||
func testisEnvironmentVariableSetReturnsExpectedValue(name: String, expected: Bool) { | ||
// GIVEN we have an environment variable name | ||
let variableName = EnvironmentKey(name) | ||
|
||
// WHEN we call isEnvironmentVariableSet(varaiblename) | ||
let actual = isEnvironmentVariableSet(variableName) | ||
|
||
// THEN we expect to return true | ||
#expect(actual == expected, "Actual is not as expected") | ||
} | ||
} |