CountLinesExampleTests.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // This source file is part of the Swift Argument Parser open source project
  4. //
  5. // Copyright (c) 2020 Apple Inc. and the Swift project authors
  6. // Licensed under Apache License v2.0 with Runtime Library Exception
  7. //
  8. // See https://swift.org/LICENSE.txt for license information
  9. //
  10. //===----------------------------------------------------------------------===//
  11. #if os(macOS)
  12. import XCTest
  13. import ArgumentParserTestHelpers
  14. @testable import ArgumentParser
  15. final class CountLinesExampleTests: XCTestCase {
  16. override func setUp() {
  17. Platform.Environment[.columns] = nil
  18. }
  19. func testCountLines() throws {
  20. guard #available(macOS 12, *) else { return }
  21. let testFile = try XCTUnwrap(
  22. Bundle.module.url(forResource: "CountLinesTest", withExtension: "txt"))
  23. try AssertExecuteCommand(
  24. command: "count-lines \(testFile.path)", expected: "20\n")
  25. try AssertExecuteCommand(
  26. command: "count-lines \(testFile.path) --prefix al", expected: "4\n")
  27. }
  28. func testCountLinesHelp() throws {
  29. guard #available(macOS 12, *) else { return }
  30. let helpText = """
  31. USAGE: count-lines [<input-file>] [--prefix <prefix>] [--verbose]
  32. ARGUMENTS:
  33. <input-file> A file to count lines in. If omitted, counts the
  34. lines of stdin.
  35. OPTIONS:
  36. --prefix <prefix> Only count lines with this prefix.
  37. --verbose Include extra information in the output.
  38. -h, --help Show help information.
  39. """
  40. try AssertExecuteCommand(command: "count-lines -h", expected: helpText)
  41. }
  42. }
  43. #endif