Skip to content

Commit f01d1f2

Browse files
feat: add MockSwiftlyVersion Test Trait
1 parent 1787f10 commit f01d1f2

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

Tests/SwiftlyTests/SwiftlyTests.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,25 @@ extension Trait where Self == TestHomeTrait {
142142
static func testHome(_ name: String = "testHome") -> Self { Self(name) }
143143
}
144144

145+
// extension Trait for mockedSwiftlyVersion
146+
struct MockedSwiftlyVersionTrait: TestTrait, TestScoping {
147+
var name: String = "testHome"
148+
149+
init(_ name: String) { self.name = name }
150+
151+
func provideScope(for _: Test, testCase _: Test.Case?, performing function: @Sendable () async throws -> Void) async throws {
152+
try await SwiftlyTests.withMockedSwiftlyVersion(latestSwiftlyVersion: SwiftlyVersion(major: 1, minor: 0, patch: 0)) {
153+
print("Mocking swiftly version: \(SwiftlyVersion(major: 1, minor: 0, patch: 0)) at \(#file):\(#line)")
154+
155+
try await function()
156+
}
157+
}
158+
}
159+
160+
extension Trait where Self == MockedSwiftlyVersionTrait {
161+
static func mockedSwiftlyVersion(_ name: String = "testHome") -> Self { Self(name) }
162+
}
163+
145164
struct MockHomeToolchainsTrait: TestTrait, TestScoping {
146165
var name: String = "testHome"
147166
var toolchains: Set<ToolchainVersion> = .allToolchains()
@@ -337,7 +356,7 @@ public enum SwiftlyTests {
337356

338357
/// Operate with a mocked toolchain that has the provided list of executables in its bin directory.
339358
static func withMockedToolchain(executables: [String]? = nil, f: () async throws -> Void) async throws {
340-
let mockDownloader = MockToolchainDownloader(executables: executables)
359+
let mockDownloader = MockToolchainDownloader(executables: executables, latestSwiftlyVersion: SwiftlyVersion(major: 1, minor: 0, patch: 0))
341360

342361
let ctx = SwiftlyCoreContext(
343362
mockedHomeDir: SwiftlyTests.ctx.mockedHomeDir,

0 commit comments

Comments
 (0)