From 8078674ac2946100586fd6b281887b1466bbe5ad Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Sat, 10 Aug 2024 16:13:17 -0600 Subject: [PATCH 1/2] switch to swift-testing bump platform add swift-testing to test targets install swift-testing formatting Package.swift --- Package.resolved | 20 ++++++- Package.swift | 85 +++++++++++++++++++++--------- Tests/CgetargvTests/Test.swift | 39 ++++++-------- Tests/SwiftGetargvTests/Test.swift | 44 ++++++---------- 4 files changed, 112 insertions(+), 76 deletions(-) diff --git a/Package.resolved b/Package.resolved index b845206..3f27b42 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,5 +1,5 @@ { - "originHash" : "962efd74b56b59bb8cdeb4ecfc2c8b4570ec41f2408fd1ffbb8a6c271e5c3e90", + "originHash" : "b1e697511022260581e726112f485afd54217c065d6e3a59d58cab2ce29762fc", "pins" : [ { "identity" : "swift-argument-parser", @@ -27,6 +27,24 @@ "revision" : "b45d1f2ed151d057b54504d653e0da5552844e34", "version" : "1.0.0" } + }, + { + "identity" : "swift-syntax", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swiftlang/swift-syntax.git", + "state" : { + "revision" : "06b5cdc432e93b60e3bdf53aff2857c6b312991a", + "version" : "600.0.0-prerelease-2024-07-30" + } + }, + { + "identity" : "swift-testing", + "kind" : "remoteSourceControl", + "location" : "https://github.com/swiftlang/swift-testing", + "state" : { + "revision" : "6155e83dbaa2696d13bcd0079665b6a6daaf6dc8", + "version" : "0.11.0" + } } ], "version" : 3 diff --git a/Package.swift b/Package.swift index 5ee8d32..b638eea 100644 --- a/Package.swift +++ b/Package.swift @@ -4,29 +4,64 @@ import PackageDescription let package = Package( - name: "Cgetargv", - platforms: [.macOS(.v10_13)], - products: [ - .library(name: "SwiftGetargv", targets: ["SwiftGetargv"]), - .library(name: "Cgetargv", targets: ["Cgetargv"]) - ], - dependencies: [ - .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), - .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"), - ], - targets: [ - .executableTarget(name: "getargv2", dependencies: [ "SwiftGetargv", .product( - name: "ArgumentParser", - package: "swift-argument-parser" - )]), - .executableTarget(name: "getargv", dependencies: [ "Cgetargv", .product( - name: "ArgumentParser", - package: "swift-argument-parser" - )]), - .target(name: "SwiftGetargv", dependencies: [ "Cgetargv" ]), - .systemLibrary(name: "Cgetargv", pkgConfig: "getargv", providers: [ .brew(["libgetagv"]) ]), - .testTarget(name: "SwiftGetargvTests", dependencies: [ "SwiftGetargv" ]), - .testTarget(name: "CgetargvTests", dependencies: [ "Cgetargv" ]) - ], - cLanguageStandard: .c99 // https://developer.apple.com/documentation/packagedescription/clanguagestandard + name: "Cgetargv", + platforms: [.macOS(.v10_15)], + products: [ + .library(name: "SwiftGetargv", targets: ["SwiftGetargv"]), + .library(name: "Cgetargv", targets: ["Cgetargv"]) + ], + dependencies: [ + .package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"), + .package(url: "https://github.com/apple/swift-docc-plugin", from: "1.3.0"), + .package(url: "https://github.com/swiftlang/swift-testing", from: "0.11.0"), + ], + targets: [ + .executableTarget( + name: "getargv2", + dependencies: [ + "SwiftGetargv", + .product( + name: "ArgumentParser", + package: "swift-argument-parser" + ) + ] + ), + .executableTarget( + name: "getargv", + dependencies: [ + "Cgetargv", + .product( + name: "ArgumentParser", + package: "swift-argument-parser" + ) + ] + ), + .target(name: "SwiftGetargv", dependencies: [ "Cgetargv" ]), + .systemLibrary( + name: "Cgetargv", + pkgConfig: "getargv", + providers: [ .brew(["libgetagv"]) ] + ), + .testTarget( + name: "SwiftGetargvTests", + dependencies: [ + "SwiftGetargv", + .product( + name: "Testing", + package: "swift-testing" + ) + ] + ), + .testTarget( + name: "CgetargvTests", + dependencies: [ + "Cgetargv", + .product( + name: "Testing", + package: "swift-testing" + ) + ] + ) + ], + cLanguageStandard: .c99 // https://developer.apple.com/documentation/packagedescription/clanguagestandard ) diff --git a/Tests/CgetargvTests/Test.swift b/Tests/CgetargvTests/Test.swift index 109f03c..bbc58d6 100644 --- a/Tests/CgetargvTests/Test.swift +++ b/Tests/CgetargvTests/Test.swift @@ -1,42 +1,37 @@ import Foundation -import XCTest +import Testing @testable import Cgetargv -final class CgetargvTests: XCTestCase { - func testGetArgvOfPid() { - let options = GetArgvOptions(skip: 0, pid: getpid(), nuls: true) - var res = ArgvResult() - XCTAssert(withUnsafePointer(to: options, { get_argv_of_pid($0, &res) })) - - let expectedOutput = ProcessInfo.processInfo.arguments.joined(separator: " ") - let actualOutput = String(cString: res.start_pointer) - - XCTAssertEqual(actualOutput, expectedOutput, "The Args are not correct.") - } +@Suite() +struct CgetargvTests { - func testGetArgvOfPidWithNuls() { - let options = GetArgvOptions(skip: 0, pid: getpid(), nuls: false) + @Test("test getArgvOfPid NUL replacement", arguments: zip([true, false], [" ", "\0"])) + func GetArgvOfPidNuls(nuls: Bool, separator: String) throws { + let options = GetArgvOptions(skip: 0, pid: getpid(), nuls: nuls) var res = ArgvResult() - XCTAssert(withUnsafePointer(to: options, { get_argv_of_pid($0, &res) })) + try #require(withUnsafePointer(to: options, { get_argv_of_pid($0, &res) })) - let expectedOutput = ProcessInfo.processInfo.arguments.flatMap { $0.utf8CString } - let actualOutput = Array( - UnsafeBufferPointer(start: res.start_pointer!, count: res.end_pointer - res.start_pointer + 1)) + let expectedOutput = try #require(ProcessInfo.processInfo.arguments.joined(separator: separator).data(using: .nonLossyASCII)) + + let actualOutput = Data( + buffer: UnsafeBufferPointer(start: res.start_pointer!, count: res.end_pointer - res.start_pointer + 1) + ) - XCTAssertEqual(actualOutput, expectedOutput, "The Args are not correct.") + #expect(actualOutput == expectedOutput) } - func testGetArgvAndArgcOfPid() { + @Test("test getArgvAndArgcOfPid") + func testGetArgvAndArgcOfPid() throws { let pid = getpid() var res = ArgvArgcResult() - XCTAssert(get_argv_and_argc_of_pid(pid, &res)) + try #require(get_argv_and_argc_of_pid(pid, &res)) let expectedOutput = ProcessInfo.processInfo.arguments let actualOutput = Array( UnsafeBufferPointer?>(start: res.argv, count: Int(res.argc)) ).map { String(cString: $0!) } - XCTAssertEqual(actualOutput, expectedOutput, "The Args are not correct.") + #expect(actualOutput == expectedOutput) } } diff --git a/Tests/SwiftGetargvTests/Test.swift b/Tests/SwiftGetargvTests/Test.swift index 21b9fb9..ef09fb7 100644 --- a/Tests/SwiftGetargvTests/Test.swift +++ b/Tests/SwiftGetargvTests/Test.swift @@ -1,39 +1,27 @@ import Foundation -import XCTest +import Testing @testable import SwiftGetargv -final class SwiftGetargvTests: XCTestCase { - func testGetArgvOfPid() { - let expectedOutput = CommandLine.arguments.joined(separator: " ").utf8CString +@Suite() +struct SwiftGetargvTests { - switch getArgvOfPid(pid: getpid(), nuls: true) { - case .success(let actualOutput): - XCTAssertEqual(actualOutput.array, Array(expectedOutput), "The Args are not correct.") - case .failure(let error): - XCTFail("getArgvOfPid failed with \(error)") - } - } - - func testGetArgvOfPidWithNuls() { - let expectedOutput = CommandLine.arguments.flatMap { $0.utf8CString } + @available(macOS 11.0, *) + @Test("test getArgvOfPid NUL replacement", arguments: zip([true, false], [" ", "\0"])) + func GetArgvOfPidNuls(nuls: Bool, separator: String) throws { + let expectedOutput = CommandLine.arguments.joined(separator: separator).utf8CString + //let expectedOutput = CommandLine.arguments.flatMap { $0.utf8CString } - switch getArgvOfPid(pid: getpid()) { - case .success(let actualOutput): - XCTAssertEqual(actualOutput.array, expectedOutput, "The Args are not correct.") - case .failure(let error): - XCTFail("getArgvOfPid failed with \(error)") + let actualOutput = try #require(try getArgvOfPid(pid: getpid(), nuls: nuls).get()) + #expect(actualOutput.array == Array(expectedOutput)) } - } - func testGetArgvAndArgcOfPid() { - let expectedOutput = CommandLine.arguments + @available(macOS 11.0, *) + @Test("test getArgvAndArgcOfPid") + func testGetArgvAndArgcOfPid() throws { + let expectedOutput = CommandLine.arguments - switch getArgvAndArgcOfPid(pid: getpid(), encoding: String.Encoding.nonLossyASCII) { - case .success(let actualOutput): - XCTAssertEqual(actualOutput, expectedOutput, "The Args are not correct.") - case .failure(let error): - XCTFail("getArgvAndArgcOfPid failed with \(error)") + let actualOutput = try #require(try getArgvAndArgcOfPid(pid: getpid(), encoding: String.Encoding.nonLossyASCII).get()) + #expect(actualOutput == expectedOutput) } - } } From 760bddf75c12e5034fb237e09242783646df5f1f Mon Sep 17 00:00:00 2001 From: Camden Narzt Date: Sun, 11 Aug 2024 14:03:54 -0600 Subject: [PATCH 2/2] bump to swift 6 --- .github/workflows/swift.yml | 3 ++- .spi.yml | 2 +- Package.swift | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/swift.yml b/.github/workflows/swift.yml index 9dc6ecf..0f4929c 100644 --- a/.github/workflows/swift.yml +++ b/.github/workflows/swift.yml @@ -33,7 +33,8 @@ jobs: fetch-depth: 0 # until https://github.com/actions/checkout/issues/1471 fixed - uses: swift-actions/setup-swift@v2 with: - swift-version: '5.10' + swift-version: '6.0' + # https://www.swift.org/download/ - name: Build run: swift build -v working-directory: getargv-swift diff --git a/.spi.yml b/.spi.yml index fa52136..639b551 100644 --- a/.spi.yml +++ b/.spi.yml @@ -3,4 +3,4 @@ builder: configs: - documentation_targets: [ SwiftGetargv, Cgetargv ] platform: macosSpm - swift_version: '5.10' + swift_version: '6.0' diff --git a/Package.swift b/Package.swift index b638eea..dd9d047 100644 --- a/Package.swift +++ b/Package.swift @@ -1,4 +1,4 @@ -// swift-tools-version:5.10 +// swift-tools-version:6.0 // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription