Skip to content

Support testing in release mode #252

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

Merged
merged 1 commit into from
Jul 31, 2025
Merged
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
6 changes: 4 additions & 2 deletions Tests/SystemTests/FileOperationsTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import CSystem

@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
final class FileOperationsTest: XCTestCase {
#if !os(WASI) // Would need to use _getConst funcs from CSystem
#if ENABLE_MOCKING && !os(WASI) // Would need to use _getConst funcs from CSystem
func testSyscalls() {
let fd = FileDescriptor(rawValue: 1)

Expand Down Expand Up @@ -91,7 +91,7 @@ final class FileOperationsTest: XCTestCase {

for test in syscallTestCases { test.runAllTests() }
}
#endif // !os(WASI)
#endif // ENABLE_MOCKING && !os(WASI)

func testWriteFromEmptyBuffer() throws {
#if os(Windows)
Expand Down Expand Up @@ -215,6 +215,7 @@ final class FileOperationsTest: XCTestCase {
}
}

#if ENABLE_MOCKING
func testGithubIssues() {
// https://github.com/apple/swift-system/issues/26
#if os(WASI)
Expand All @@ -233,6 +234,7 @@ final class FileOperationsTest: XCTestCase {
}
issue26.runAllTests()
}
#endif // ENABLE_MOCKING

func testResizeFile() throws {
try withTemporaryFilePath(basename: "testResizeFile") { path in
Expand Down
2 changes: 2 additions & 0 deletions Tests/SystemTests/FilePathTests/FilePathParsingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
See https://swift.org/LICENSE.txt for license information
*/

#if ENABLE_MOCKING
import XCTest

#if SYSTEM_PACKAGE
Expand Down Expand Up @@ -105,3 +106,4 @@ final class FilePathParsingTest: XCTestCase {
}
}
}
#endif // ENABLE_MOCKING
2 changes: 2 additions & 0 deletions Tests/SystemTests/FilePathTests/FilePathSyntaxTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
See https://swift.org/LICENSE.txt for license information
*/

#if ENABLE_MOCKING
import XCTest

#if SYSTEM_PACKAGE
Expand Down Expand Up @@ -1238,3 +1239,4 @@ final class FilePathSyntaxTest: XCTestCase {
}

}
#endif // ENABLE_MOCKING
2 changes: 2 additions & 0 deletions Tests/SystemTests/MockingTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
See https://swift.org/LICENSE.txt for license information
*/

#if ENABLE_MOCKING
import XCTest

#if SYSTEM_PACKAGE
Expand Down Expand Up @@ -48,3 +49,4 @@ final class MockingTest: XCTestCase {
XCTAssertFalse(mockingEnabled)
}
}
#endif // ENABLE_MOCKING
6 changes: 6 additions & 0 deletions Tests/SystemTests/TestingInfrastructure.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import XCTest

internal struct Wildcard: Hashable {}

#if ENABLE_MOCKING
extension Trace.Entry {
/// This implements `==` with wildcard matching.
/// (`Entry` cannot conform to `Equatable`/`Hashable` this way because
Expand All @@ -33,6 +34,7 @@ extension Trace.Entry {
return true
}
}
#endif // ENABLE_MOCKING

// To aid debugging, force failures to fatal error
internal var forceFatalFailures = false
Expand Down Expand Up @@ -81,6 +83,7 @@ extension TestCase {
fail(message)
}
}
#if ENABLE_MOCKING
func expectMatch(
_ expected: Trace.Entry?, _ actual: Trace.Entry?,
_ message: String? = nil
Expand All @@ -102,6 +105,7 @@ extension TestCase {
fail(message)
}
}
#endif // ENABLE_MOCKING
func expectNil<T>(
_ actual: T?,
_ message: String? = nil
Expand Down Expand Up @@ -142,6 +146,7 @@ extension TestCase {

}

#if ENABLE_MOCKING
internal struct MockTestCase: TestCase {
var file: StaticString
var line: UInt
Expand Down Expand Up @@ -241,6 +246,7 @@ internal struct MockTestCase: TestCase {
}
}
}
#endif // ENABLE_MOCKING

internal func withWindowsPaths(enabled: Bool, _ body: () -> ()) {
_withWindowsPaths(enabled: enabled, body)
Expand Down