Skip to content

Commit

Permalink
chore: update SwiftArgumentParser lib to 0.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
leandrof-ciandt authored and lnfnunes committed Jul 20, 2021
1 parent a795138 commit b6c9de4
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 77 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ bindir = $(prefix)/bin
libdir = $(prefix)/lib

build:
# disabling the sandbox is necessary for installation with Homebrew
swift build -c release --disable-sandbox

install: build
install ".build/release/cowsay" "$(bindir)"

test:
swift test

uninstall:
rm -rf "$(bindir)/cowsay"

clean:
rm -rf .build

.PHONY: build install uninstall clean
.PHONY: build install test uninstall clean
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
"repositoryURL": "https://github.com/apple/swift-argument-parser",
"state": {
"branch": null,
"revision": "3d79b2b5a2e5af52c14e462044702ea7728f5770",
"version": "0.1.0"
"revision": "986d191f94cec88f6350056da59c2e59e83d1229",
"version": "0.4.3"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
.executable(name: "cowsay", targets: ["cowsay"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", .upToNextMinor(from: "0.1.0"))
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.4.3")
],
targets: [
.target(name: "cowsay", dependencies: ["ArgumentParser"]),
Expand Down
25 changes: 11 additions & 14 deletions Sources/cowsay/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,26 @@ import Foundation

struct Cli: ParsableCommand {

static let configuration = CommandConfiguration(abstract: "Cowsay muuhhhh")
static let configuration = CommandConfiguration(
abstract: "Cowsay muuhhhh",
version: "0.0.2"
)

// MARK: - Arguments

@Argument(help: "The cow should say something")
var message: [String]
var message: [String] = ["muuhhhh"]

// MARK: - Options

@Option(name: .shortAndLong,
default: "oo",
help: "Change cow's eyes")
var eyes: String
@Option(name: .shortAndLong, help: "Change cow's eyes")
var eyes: String = "oo"

@Option(name: .shortAndLong,
default: " ",
help: "Change cow's tongue")
var tongue: String
@Option(name: .shortAndLong, help: "Change cow's tongue")
var tongue: String = " "

@Option(name: .long,
default: Example(name: CowNames.example.rawValue).name,
help: "Select, by name, one of cows included in the package")
var name: String
@Option(name: .long, help: "Select, by name, one of cows included in the package")
var name: String = Example(name: CowNames.example.rawValue).name

// MARK: - Init

Expand Down
5 changes: 0 additions & 5 deletions Tests/LinuxMain.swift

This file was deleted.

9 changes: 0 additions & 9 deletions Tests/cowsay/XCTestManifests.swift

This file was deleted.

69 changes: 24 additions & 45 deletions Tests/cowsay/cowsayTests.swift
Original file line number Diff line number Diff line change
@@ -1,36 +1,14 @@
import XCTest

import class Foundation.Bundle

@available(macOS 10.13, *)
final class cowsayTests: XCTestCase {
func testExample() throws {
// This is an example of a functional test case.
// Use XCTAssert and related functions to verify your tests produce the correct
// results.

// Some of the APIs that we use below are available in macOS 10.13 and above.
guard #available(macOS 10.13, *) else {
return
}

let fooBinary = productsDirectory.appendingPathComponent("cowsay")

let process = Process()
process.executableURL = fooBinary

let pipe = Pipe()
process.standardOutput = pipe

try process.run()
process.waitUntilExit()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let result = String(data: data, encoding: .utf8)

let expected = """
__
< >
--
func test_ShouldSayDefault_WhenMessageParamIsOmitted() throws {
let result = try runCommand()
let expected = """
_________
< muuhhhh >
---------
\\ ^__^
\\ (oo\\________
(__)\\ )\\/\\
Expand All @@ -39,22 +17,23 @@ final class cowsayTests: XCTestCase {
\n
"""

XCTAssertEqual(result, expected)
}
XCTAssertEqual(result, expected)
}

/// Returns path to the built products directory.
var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
}
func test_ShouldSayCobaia_WhenMessageParamIsCobaia() throws {
let result = try runCommand(with: ["cobaia"])
let expected = """
________
< cobaia >
--------
\\ ^__^
\\ (oo\\________
(__)\\ )\\/\\
||----w |
|| ||
\n
"""

static var allTests = [
("testExample", testExample),
]
XCTAssertEqual(result, expected)
}
}
42 changes: 42 additions & 0 deletions Tests/helpers/TestHelpers.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// File.swift
//
//
// Created by Leandro Nunes Fantinatto on 20/07/21.
//

import XCTest
import class Foundation.Bundle

extension XCTest {

func runCommand(with arguments: [String]? = []) throws -> String {
let fooBinary = productsDirectory.appendingPathComponent("cowsay")

let process = Process()
process.executableURL = fooBinary
process.arguments = arguments

let pipe = Pipe()
process.standardOutput = pipe

try process.run()
process.waitUntilExit()

let data = pipe.fileHandleForReading.readDataToEndOfFile()
let result = try XCTUnwrap(String(data: data, encoding: .utf8))
return result
}

/// Returns path to the built products directory.
var productsDirectory: URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
}
fatalError("couldn't find the products directory")
#else
return Bundle.main.bundleURL
#endif
}
}

0 comments on commit b6c9de4

Please sign in to comment.