Skip to content

Commit 1fb1ed9

Browse files
committed
Tests: Augment Command Tests
Augment Commands Tests to run against the Native and Swift Build build systems. - BuildCommandTests - TestCommandTests - RunCommandTests Mark any failures as "Skipped". Ideally, we will mark them as "expected fail" so we can remove the expected failure when the issue has been fixed. Also, - update BuildSystemProvider.Kind to define a "useXcodeBuildSystemPath" variable instead of sprinkling the `buildSystem == .xcode` all over the place
1 parent 844a6b3 commit 1fb1ed9

File tree

17 files changed

+492
-48
lines changed

17 files changed

+492
-48
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+
}

Sources/CoreCommands/SwiftCommandState.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ public final class SwiftCommandState {
441441
self.observabilityHandler.progress,
442442
self.observabilityHandler.prompt
443443
)
444-
let isXcodeBuildSystemEnabled = self.options.build.buildSystem == .xcode
444+
let isXcodeBuildSystemEnabled = self.options.build.buildSystem.useXcodeBuildSystemPath
445445
let workspace = try Workspace(
446446
fileSystem: self.fileSystem,
447447
location: .init(
@@ -459,7 +459,7 @@ public final class SwiftCommandState {
459459
configuration: .init(
460460
skipDependenciesUpdates: options.resolver.skipDependencyUpdate,
461461
prefetchBasedOnResolvedFile: options.resolver.shouldEnableResolverPrefetching,
462-
shouldCreateMultipleTestProducts: toolWorkspaceConfiguration.wantsMultipleTestProducts || options.build.buildSystem == .xcode,
462+
shouldCreateMultipleTestProducts: toolWorkspaceConfiguration.wantsMultipleTestProducts || self.options.build.buildSystem.useXcodeBuildSystemPath,
463463
createREPLProduct: toolWorkspaceConfiguration.wantsREPLProduct,
464464
additionalFileRules: isXcodeBuildSystemEnabled ? FileRuleDescription.xcbuildFileTypes : FileRuleDescription.swiftpmFileTypes,
465465
sharedDependenciesCacheEnabled: self.options.caching.useDependenciesCache,
@@ -795,7 +795,7 @@ public final class SwiftCommandState {
795795
workers: options.build.jobs ?? UInt32(ProcessInfo.processInfo.activeProcessorCount),
796796
sanitizers: options.build.enabledSanitizers,
797797
indexStoreMode: options.build.indexStoreMode.buildParameter,
798-
isXcodeBuildSystemEnabled: options.build.buildSystem == .xcode,
798+
isXcodeBuildSystemEnabled: self.options.build.buildSystem.useXcodeBuildSystemPath,
799799
prepareForIndexing: prepareForIndexingMode,
800800
debuggingParameters: .init(
801801
debugInfoFormat: options.build.debugInfoFormat.buildParameter,

0 commit comments

Comments
 (0)