Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: Add platform helpers #8099

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions Sources/_InternalTestSupport/PlatformHelpers.swift
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 Tests/_InternalTestSupportTests/PlatformHelpersTests.swift
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)
Copy link
Contributor Author

@bkhouri bkhouri Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: this test will likely need to be revisited when addressing #8121 and #8176

]
)
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")
}
}