-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Tests: Convert Basics/FileSystem/* to Swift Testing #8448
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
Closed
bkhouri
wants to merge
2
commits into
swiftlang:main
from
bkhouri:t/main/convert_pathtests_to_swift_testing
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,43 @@ | ||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2014 - 2025 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 Swift project authors | ||
*/ | ||
|
||
public import Foundation | ||
|
||
public enum OperatingSystem: Hashable, Sendable { | ||
case macOS | ||
case windows | ||
case linux | ||
case android | ||
case unknown | ||
} | ||
|
||
extension ProcessInfo { | ||
#if os(macOS) | ||
public static let hostOperatingSystem = OperatingSystem.macOS | ||
#elseif os(Linux) | ||
public static let hostOperatingSystem = OperatingSystem.linux | ||
#elseif os(Windows) | ||
public static let hostOperatingSystem = OperatingSystem.windows | ||
#else | ||
public static let hostOperatingSystem = OperatingSystem.unknown | ||
#endif | ||
|
||
#if os(Windows) | ||
public static let EOL = "\r\n" | ||
#else | ||
public static let EOL = "\n" | ||
#endif | ||
|
||
#if os(Windows) | ||
public static let exeSuffix = ".exe" | ||
#else | ||
public static let exeSuffix = "" | ||
#endif | ||
} |
This file contains hidden or 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,70 @@ | ||
|
||
/* | ||
This source file is part of the Swift.org open source project | ||
|
||
Copyright (c) 2014 - 2025 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 Swift project authors | ||
*/ | ||
|
||
import class Foundation.FileManager | ||
import class Foundation.ProcessInfo | ||
import Testing | ||
|
||
extension Trait where Self == Testing.ConditionTrait { | ||
/// Skip test if the host operating system does not match the running OS. | ||
public static func requireHostOS(_ os: OperatingSystem, when condition: Bool = true) -> Self { | ||
enabled("This test requires a \(os) host OS.") { | ||
ProcessInfo.hostOperatingSystem == os && condition | ||
} | ||
} | ||
|
||
/// Skip test if the host operating system matches the running OS. | ||
public static func skipHostOS(_ os: OperatingSystem, _ comment: Comment? = nil) -> Self { | ||
disabled(comment ?? "This test cannot run on a \(os) host OS.") { | ||
ProcessInfo.hostOperatingSystem == os | ||
} | ||
} | ||
|
||
/// Skip test unconditionally | ||
public static func skip(_ comment: Comment? = nil) -> Self { | ||
disabled(comment ?? "Unconditional skip, a comment should be added for the reason") { true } | ||
} | ||
|
||
/// Skip test if the environment is self hosted. | ||
public static func skipSwiftCISelfHosted(_ comment: Comment? = nil) -> Self { | ||
disabled(comment ?? "SwiftCI is self hosted") { | ||
ProcessInfo.processInfo.environment["SWIFTCI_IS_SELF_HOSTED"] != nil | ||
} | ||
} | ||
|
||
/// Skip test if the test environment has a restricted network access, i.e. cannot get to internet. | ||
public static func requireUnrestrictedNetworkAccess(_ comment: Comment? = nil) -> Self { | ||
disabled(comment ?? "CI Environment has restricted network access") { | ||
ProcessInfo.processInfo.environment["SWIFTCI_RESTRICTED_NETWORK_ACCESS"] != nil | ||
} | ||
} | ||
|
||
/// Skip test if built by XCode. | ||
public static func skipIfXcodeBuilt() -> Self { | ||
disabled("Tests built by Xcode") { | ||
#if Xcode | ||
true | ||
#else | ||
false | ||
#endif | ||
} | ||
} | ||
|
||
/// Constructs a condition trait that causes a test to be disabled if the Foundation process spawning implementation | ||
/// is not using `posix_spawn_file_actions_addchdir`. | ||
public static var requireThreadSafeWorkingDirectory: Self { | ||
disabled("Thread-safe process working directory support is unavailable.") { | ||
// Amazon Linux 2 has glibc 2.26, and glibc 2.29 is needed for posix_spawn_file_actions_addchdir_np support | ||
FileManager.default.contents(atPath: "/etc/system-release") | ||
.map { String(decoding: $0, as: UTF8.self) == "Amazon Linux release 2 (Karoo)\n" } ?? false | ||
} | ||
} | ||
} |
This file contains hidden or 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
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given
Testing.ConditionTrait
conforms toTrait
, can't we simply write this instead?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This file was a direct copy from
IntegartionTests/Sources/IntegrationTests
. I want to avoid changing it drastically until #8223 is completed