Skip to content

Commit 063da6d

Browse files
committed
Tests: Augment Command Tests
Augment Commands Tests to run against the Native and Swift Build build systems. - BuildCommandTests - TestCommandTests - RunCommandTests - APIDiffTests - PackageCommandTests Also, - Add a new BuildCommandTest and RunCommandTest test case that ensures a package with target conditionals builds and runs successfully - update BuildSystemProvider.Kind to define a "useXcodeBuildSystemPath" variable instead of sprinkling the `buildSystem == .xcode` all over the place - Augment the Swift Build integration test to run `swift test` TODO: - Instead of marking test failures as "Skipped", See if we can mark them as "expected fail" so we are forced to update the test once the production code has been update to support the "feature".
1 parent 844a6b3 commit 063da6d

File tree

21 files changed

+707
-143
lines changed

21 files changed

+707
-143
lines changed
Lines changed: 8 additions & 0 deletions
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
Lines changed: 56 additions & 0 deletions
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+
}
Lines changed: 2 additions & 0 deletions
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)")
Lines changed: 11 additions & 0 deletions
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+
}
Lines changed: 8 additions & 0 deletions
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+
}

IntegrationTests/Tests/IntegrationTests/SwiftPMTests.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,9 @@ final class SwiftPMTests: XCTestCase {
6060
try withTemporaryDirectory { tmpDir in
6161
let packagePath = tmpDir.appending(component: "foo")
6262
try localFileSystem.createDirectory(packagePath)
63-
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "executable")
63+
try sh(swiftPackage, "--package-path", packagePath, "init", "--type", "library")
6464
try sh(swiftBuild, "--package-path", packagePath, "--build-system", "swiftbuild")
65+
try sh(swiftTest, "--package-path", packagePath, "--build-system", "swiftbuild")
6566
}
6667
}
6768

0 commit comments

Comments
 (0)