Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/Packages
/*.xcodeproj
Package.resolved
.swiftpm
23 changes: 12 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// swift-tools-version:5.10
// swift-tools-version:6.0

/*
This source file is part of the Swift.org open source project

Copyright 2015 – 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
//===----------------------------------------------------------------------===//
//
// This source file is part of the example package dealer open source project
//
// Copyright (c) 2015-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

import PackageDescription

Expand All @@ -27,7 +28,7 @@ let package = Package(
from: "3.0.0"),
.package(
url: "https://github.com/apple/swift-argument-parser.git",
from: "0.4.4"),
from: "1.6.0"),
],
targets: [
.executableTarget(
Expand Down
21 changes: 11 additions & 10 deletions Sources/dealer/Dealer.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
This source file is part of the Swift.org open source project

Copyright 2015 – 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
//===----------------------------------------------------------------------===//
//
// This source file is part of the example package dealer open source project
//
// Copyright (c) 2015-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

#if os(Linux)
import Glibc
Expand All @@ -30,7 +31,7 @@ struct Dealer: ParsableCommand {
}
}

static var configuration = CommandConfiguration(
static let configuration = CommandConfiguration(
abstract: "Shuffles a deck of playing cards and deals a number of cards.",
discussion: """
For each count argument, prints a line of tab-delimited cards to stdout,
Expand Down
73 changes: 42 additions & 31 deletions Tests/DealerTests/DealerTests.swift
Original file line number Diff line number Diff line change
@@ -1,54 +1,65 @@
/*
This source file is part of the Swift.org open source project

Copyright 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/

import XCTest
//===----------------------------------------------------------------------===//
//
// This source file is part of the example package dealer open source project
//
// Copyright (c) 2021-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//


import Testing
import Foundation
import class Foundation.Bundle

final class DealerTests: XCTestCase {
final class Marker {
}

struct DealerTests {
@Test
func testUsage() throws {
let (status, output, error) = try execute(with: ["--help"])
XCTAssertEqual(status, EXIT_SUCCESS)
XCTAssert(output?.starts(with: "OVERVIEW: Shuffles a deck of playing cards and deals a number of cards.") ?? false)
XCTAssertEqual(error, "")
#expect(status == EXIT_SUCCESS)
#expect(output?.starts(with: "OVERVIEW: Shuffles a deck of playing cards and deals a number of cards.") ?? false)
#expect(error == "")
}

@Test
func testDealOneCard() throws {
let (status, output, error) = try execute(with: ["1"])
XCTAssertEqual(status, EXIT_SUCCESS)
XCTAssertEqual(output?.filter(\.isPlayingCardSuit).count, 1)

XCTAssertEqual(error, "")
#expect(status == EXIT_SUCCESS)
#expect(output?.filter(\.isPlayingCardSuit).count == 1)
#expect(error == "")
}

@Test
func testDealTenCards() throws {
let (status, output, error) = try execute(with: ["10"])
XCTAssertEqual(status, EXIT_SUCCESS)
XCTAssertEqual(output?.filter(\.isPlayingCardSuit).count, 10)

XCTAssertEqual(error, "")
#expect(status == EXIT_SUCCESS)
#expect(output?.filter(\.isPlayingCardSuit).count == 10)
#expect(error == "")
}

@Test
func testDealThirteenCardsFourTimes() throws {
let (status, output, error) = try execute(with: ["13", "13", "13", "13"])
XCTAssertEqual(status, EXIT_SUCCESS)
XCTAssertEqual(output?.filter(\.isPlayingCardSuit).count, 52)
XCTAssertEqual(output?.filter(\.isNewline).count, 4)

XCTAssertEqual(error, "")
#expect(status == EXIT_SUCCESS)
#expect(output?.filter(\.isPlayingCardSuit).count == 52)
#expect(output?.filter(\.isNewline).count == 4)
#expect(error == "")
}

@Test
func testDealOneHundredCards() throws {
let (status, output, error) = try execute(with: ["100"])
XCTAssertNotEqual(status, EXIT_SUCCESS)
XCTAssertEqual(output, "")
XCTAssertEqual(error, "Error: Not enough cards\n")
#expect(status != EXIT_SUCCESS)
#expect(output == "")
#expect(error == "Error: Not enough cards\n")
}

/// Returns path to the built products directory.
Expand Down