Skip to content

Commit

Permalink
Tests: augment command tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bkhouri committed Feb 4, 2025
1 parent 844a6b3 commit 925baa5
Show file tree
Hide file tree
Showing 13 changed files with 347 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// swift-tools-version: 6.1
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "ExecutableTargetWhen",
products: [
.executable(
name: "test",
targets: ["ExecutableTargetWhen"]
)
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "ExecutableTargetWhen",
dependencies: [
.target(name:"LinuxOnly", condition: .when(platforms:[.linux])),
.target(name:"MacOSOnly", condition: .when(platforms:[.macOS])),
.target(name:"WindowsOnly", condition: .when(platforms:[.windows])),
.target(name:"AllPlatforms")
]
),
.target(
name: "AllPlatforms"
),
.target(
name: "LinuxOnly",
dependencies: [
"CLibArchive",
"AllPlatforms"
]
),
.target(
name: "MacOSOnly",
dependencies: [
"AllPlatforms"
]
),
.target(
name: "WindowsOnly",
dependencies: [
"AllPlatforms"
]
),
.systemLibrary(
name: "CLibArchive",
pkgConfig: "libarchive",
providers: [
.apt(["libarchive-dev"]),
]
),
]
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
public func getPlatform() throws -> String {
#if os(Windows)
return "Windows"
#else
#if os(macOS)
return "macOS"
#else
#if os(linux)
return "Linux"
#else
return "Unknown platform"
#endif
#endif
#endif
}


public protocol MyProtocol {
static var name: String { get }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module CLibArchive [system] {
header "shim.h"
link "archive"
export *
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "archive.h"
#include "archive_entry.h"
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// The Swift Programming Language
// https://docs.swift.org/swift-book

import AllPlatforms

#if os(Windows)
import WindowsOnly
#else
#if os(macOS)
import MacOSOnly
#else
#if os(linux)
import LinuxOnly
#endif
#endif
#endif

let platform = try getPlatform()
print("Hello, world on \(platform)! OSplatform: \(OSPlatform.name)")
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import CLibArchive

import AllPlatforms

public struct OSPlatform: MyProtocol {

public static var name: String {
return "Linux"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import AllPlatforms
public struct OSPlatform: MyProtocol {

public static var name: String {
return "macOS"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import AllPlatforms

public struct OSPlatform: MyProtocol {

public static var name: String {
return "Windows"
}

}
4 changes: 4 additions & 0 deletions Sources/_InternalTestSupport/misc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ public func testWithTemporaryDirectory<Result>(
}
}

public enum TestError: Error {
case platformNotSupported
}

@discardableResult public func fixture<T>(
name: String,
createGitRepo: Bool = true,
Expand Down
Loading

0 comments on commit 925baa5

Please sign in to comment.