Skip to content

Commit

Permalink
Target is executable
Browse files Browse the repository at this point in the history
  • Loading branch information
AllDmeat committed Dec 20, 2023
1 parent 633fdd3 commit 40b928e
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 37 deletions.
14 changes: 14 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"pins" : [
{
"identity" : "swift-argument-parser",
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser.git",
"state" : {
"revision" : "c8ed701b513cf5177118a175d85fbbbcd707ab41",
"version" : "1.3.0"
}
}
],
"version" : 2
}
29 changes: 13 additions & 16 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version:5.3
// swift-tools-version:5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -12,26 +12,23 @@ let package = Package(
platforms: [
.macOS(.v10_15)
],
products: [
// Products define the executables and libraries a package produces, and make them visible to other packages.
.library(
name: packageName,
targets: [packageName]
),
.library(
name: packageTestHelpersName,
targets: [packageTestHelpersName]
),
],
dependencies: [

.package(
url: "https://github.com/apple/swift-argument-parser.git",
.upToNextMajor(from: "1.0.0")
),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages this package depends on.
.target(
.executableTarget(
name: packageName,
dependencies: []
dependencies: [
.product(
name: "ArgumentParser",
package: "swift-argument-parser"
)
]
),
.target(
name: packageTestHelpersName,
Expand All @@ -46,7 +43,7 @@ let package = Package(
.init(stringLiteral: packageTestHelpersName)
],
resources: [
.process("Resources/DBXCResultParser.xcresult")
.copy("Resources/DBXCResultParser.xcresult")
]
),
]
Expand Down
50 changes: 34 additions & 16 deletions Sources/DBXCResultParser/Formatters/DBXCTextFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,39 @@
//

import Foundation
import ArgumentParser

extension DBXCTextFormatter {
/// Output format options
public enum Format {
public enum Format: String, Decodable {
case list // Outputs detailed list of test results
case count // // Outputs a summary count of test results
}
}

public class DBXCTextFormatter {
/// The format style to use for output
public let format: Format
@main
public class DBXCTextFormatter: ParsableCommand {
public required init() { }

@Option(help: "Path to .xcresult")
public var xcresultPath: String

@Option(help: "Result format")
public var format: Format = .list

/// /// The locale to use for formatting numbers and measurements
public let locale: Locale?
@Option(help: "Locale to use for numbers and measurements formatting (default: system)")
public var locale: Locale?

/// Initializes a new text formatter with the specified format and locale.
///
/// - Parameters:
/// - format: The output format to use.
/// - locale: The locale for number and measurement formatting. Defaults to `nil`.
public init(
format: Format,
locale: Locale? = nil
) {
self.format = format
self.locale = locale
@Option(help: "Test statutes to include in report, comma separated")
public var include: String = DBXCReportModel.Module.File.RepeatableTest.Test.Status.allCases.map { $0.rawValue }.joined(separator: ",")

public func run() throws {
let xcresultPath = URL(fileURLWithPath: xcresultPath)
let report = try DBXCReportModel(xcresultPath: xcresultPath)
let includeTestResults = include.split(separator: ",").compactMap { DBXCReportModel.Module.File.RepeatableTest.Test.Status(rawValue: String($0)) }
let result = format(report, testResults: includeTestResults)
print(result)
}

/// Formats the test report data into a string based on the specified format.
Expand Down Expand Up @@ -138,3 +144,15 @@ extension NumberFormatter {
return formatter
}
}

extension Locale: ExpressibleByArgument {
public init?(argument: String) {
self.init(identifier: argument)
}
}

extension DBXCTextFormatter.Format: ExpressibleByArgument {
public init?(argument: String) {
self.init(rawValue: argument)
}
}
2 changes: 1 addition & 1 deletion Sources/DBXCResultParser/Models/DBXCReportModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ extension DBXCReportModel.Module.File.RepeatableTest {
}

extension DBXCReportModel.Module.File.RepeatableTest.Test {
public enum Status: Equatable, CaseIterable {
public enum Status: String, Equatable, CaseIterable {
case success
case failure
case expectedFailure
Expand Down
16 changes: 12 additions & 4 deletions Tests/DBXCResultParserTests/DBXCTextFormatterTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ final class DBXCTextFormatterTests: XCTestCase {
}

func test_testResult_any_list() {
let formatter = DBXCTextFormatter(format: .list, locale: locale)
let formatter = DBXCTextFormatter()
formatter.format = .list
formatter.locale = locale
let result = formatter.format(.genericReport)

XCTAssertEqual(result,
Expand All @@ -38,7 +40,9 @@ NotificationsSetupServiceTests
}

func test_testResult_success_list() {
let formatter = DBXCTextFormatter(format: .list, locale: locale)
let formatter = DBXCTextFormatter()
formatter.format = .list
formatter.locale = locale
let result = formatter.format(.genericReport, testResults: [.success])

XCTAssertEqual(result,
Expand All @@ -52,14 +56,18 @@ NetworkSpec
}

func test_testResult_any_count() {
let formatter = DBXCTextFormatter(format: .count, locale: locale)
let formatter = DBXCTextFormatter()
formatter.format = .count
formatter.locale = locale
let result = formatter.format(.genericReport)

XCTAssertEqual(result, "7 (0 sec)")
}

func test_testResult_failure_count() {
let formatter = DBXCTextFormatter(format: .count, locale: locale)
let formatter = DBXCTextFormatter()
formatter.format = .count
formatter.locale = locale
let result = formatter.format(.genericReport, testResults: [.failure])

XCTAssertEqual(result, "3 (0 sec)")
Expand Down

0 comments on commit 40b928e

Please sign in to comment.