Skip to content

Commit 925baa5

Browse files
committed
Tests: augment command tests
1 parent 844a6b3 commit 925baa5

File tree

13 files changed

+347
-9
lines changed

13 files changed

+347
-9
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
/.build
3+
/Packages
4+
xcuserdata/
5+
DerivedData/
6+
.swiftpm/configuration/registries.json
7+
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
8+
.netrc
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// swift-tools-version: 6.1
2+
// The swift-tools-version declares the minimum version of Swift required to build this package.
3+
4+
import PackageDescription
5+
6+
let package = Package(
7+
name: "ExecutableTargetWhen",
8+
products: [
9+
.executable(
10+
name: "test",
11+
targets: ["ExecutableTargetWhen"]
12+
)
13+
],
14+
targets: [
15+
// Targets are the basic building blocks of a package, defining a module or a test suite.
16+
// Targets can depend on other targets in this package and products from dependencies.
17+
.executableTarget(
18+
name: "ExecutableTargetWhen",
19+
dependencies: [
20+
.target(name:"LinuxOnly", condition: .when(platforms:[.linux])),
21+
.target(name:"MacOSOnly", condition: .when(platforms:[.macOS])),
22+
.target(name:"WindowsOnly", condition: .when(platforms:[.windows])),
23+
.target(name:"AllPlatforms")
24+
]
25+
),
26+
.target(
27+
name: "AllPlatforms"
28+
),
29+
.target(
30+
name: "LinuxOnly",
31+
dependencies: [
32+
"CLibArchive",
33+
"AllPlatforms"
34+
]
35+
),
36+
.target(
37+
name: "MacOSOnly",
38+
dependencies: [
39+
"AllPlatforms"
40+
]
41+
),
42+
.target(
43+
name: "WindowsOnly",
44+
dependencies: [
45+
"AllPlatforms"
46+
]
47+
),
48+
.systemLibrary(
49+
name: "CLibArchive",
50+
pkgConfig: "libarchive",
51+
providers: [
52+
.apt(["libarchive-dev"]),
53+
]
54+
),
55+
]
56+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public func getPlatform() throws -> String {
2+
#if os(Windows)
3+
return "Windows"
4+
#else
5+
#if os(macOS)
6+
return "macOS"
7+
#else
8+
#if os(linux)
9+
return "Linux"
10+
#else
11+
return "Unknown platform"
12+
#endif
13+
#endif
14+
#endif
15+
}
16+
17+
18+
public protocol MyProtocol {
19+
static var name: String { get }
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module CLibArchive [system] {
2+
header "shim.h"
3+
link "archive"
4+
export *
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#include "archive.h"
2+
#include "archive_entry.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// The Swift Programming Language
2+
// https://docs.swift.org/swift-book
3+
4+
import AllPlatforms
5+
6+
#if os(Windows)
7+
import WindowsOnly
8+
#else
9+
#if os(macOS)
10+
import MacOSOnly
11+
#else
12+
#if os(linux)
13+
import LinuxOnly
14+
#endif
15+
#endif
16+
#endif
17+
18+
let platform = try getPlatform()
19+
print("Hello, world on \(platform)! OSplatform: \(OSPlatform.name)")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import CLibArchive
2+
3+
import AllPlatforms
4+
5+
public struct OSPlatform: MyProtocol {
6+
7+
public static var name: String {
8+
return "Linux"
9+
}
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import AllPlatforms
2+
public struct OSPlatform: MyProtocol {
3+
4+
public static var name: String {
5+
return "macOS"
6+
}
7+
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import AllPlatforms
2+
3+
public struct OSPlatform: MyProtocol {
4+
5+
public static var name: String {
6+
return "Windows"
7+
}
8+
9+
}

Sources/_InternalTestSupport/misc.swift

+4
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ public func testWithTemporaryDirectory<Result>(
117117
}
118118
}
119119

120+
public enum TestError: Error {
121+
case platformNotSupported
122+
}
123+
120124
@discardableResult public func fixture<T>(
121125
name: String,
122126
createGitRepo: Bool = true,

0 commit comments

Comments
 (0)