Skip to content

Commit

Permalink
format files, add GH action
Browse files Browse the repository at this point in the history
  • Loading branch information
GErP83 committed Nov 5, 2024
1 parent ced1af6 commit 6de3d18
Show file tree
Hide file tree
Showing 20 changed files with 446 additions and 228 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Actions

on:
pull_request:
branches:
- main

jobs:

bb_checks:
name: BB Checks
uses: BinaryBirds/github-workflows/.github/workflows/extra_soundness.yml@main
with:
local_swift_dependencies_check_enabled : true

swiftlang_checks:
name: Swiftlang Checks
uses: swiftlang/github-workflows/.github/workflows/soundness.yml@main
with:
license_header_check_project_name: "Testify"
format_check_enabled : true
broken_symlink_check_enabled : true
unacceptable_language_check_enabled : true
api_breakage_check_enabled : false
docs_check_enabled : false
license_header_check_enabled : false
shell_check_enabled : false
yamllint_check_enabled : false
python_lint_check_enabled : false

swiftlang_tests:
name: Swiftlang Tests
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
with:
enable_windows_checks : false
linux_build_command: "swift test --parallel"
linux_exclude_swift_versions: "[{\"swift_version\": \"5.8\"}, {\"swift_version\": \"5.9\"}, {\"swift_version\": \"5.10\"}, {\"swift_version\": \"nightly\"}, {\"swift_version\": \"nightly-main\"}, {\"swift_version\": \"nightly-6.0\"}]"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/.build
/Packages
/*.xcodeproj
.vscode/launch.json
64 changes: 64 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"version": 1,
"lineLength": 80,
"maximumBlankLines": 1,
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"tabWidth": 4,
"indentation": {
"spaces": 4
},
"indentConditionalCompilationBlocks": false,
"indentSwitchCaseLabels": false,
"lineBreakAroundMultilineExpressionChainComponents": true,
"lineBreakBeforeControlFlowKeywords": true,
"lineBreakBeforeEachArgument": true,
"lineBreakBeforeEachGenericRequirement": true,
"prioritizeKeepingFunctionOutputTogether": false,
"respectsExistingLineBreaks": true,
"spacesAroundRangeFormationOperators": false,
"multiElementCollectionTrailingCommas": true,
"rules": {
"AllPublicDeclarationsHaveDocumentation": false,
"AlwaysUseLiteralForEmptyCollectionInit": true,
"AlwaysUseLowerCamelCase": true,
"AmbiguousTrailingClosureOverload": true,
"BeginDocumentationCommentWithOneLineSummary": true,
"DoNotUseSemicolons": true,
"DontRepeatTypeInStaticProperties": true,
"FileScopedDeclarationPrivacy": true,
"FullyIndirectEnum": true,
"GroupNumericLiterals": true,
"IdentifiersMustBeASCII": true,
"NeverForceUnwrap": false,
"NeverUseForceTry": true,
"NeverUseImplicitlyUnwrappedOptionals": true,
"NoAccessLevelOnExtensionDeclaration": true,
"NoAssignmentInExpressions": true,
"NoBlockComments": true,
"NoCasesWithOnlyFallthrough": true,
"NoEmptyTrailingClosureParentheses": true,
"NoLabelsInCasePatterns": true,
"NoLeadingUnderscores": true,
"NoParensAroundConditions": true,
"NoPlaygroundLiterals": true,
"NoVoidReturnOnFunctionSignature": true,
"OmitExplicitReturns": true,
"OneCasePerLine": true,
"OneVariableDeclarationPerLine": true,
"OnlyOneTrailingClosureArgument": true,
"OrderedImports": true,
"ReplaceForEachWithForLoop": true,
"ReturnVoidInsteadOfEmptyTuple": true,
"TypeNamesShouldBeCapitalized": true,
"UseEarlyExits": true,
"UseLetInEveryBoundCaseVariable": true,
"UseShorthandTypeNames": true,
"UseSingleLinePropertyGetter": true,
"UseSynthesizedInitializer": true,
"UseTripleSlashForDocumentationComments": true,
"UseWhereClausesInForLoops": true,
"ValidateDocumentationComments": true
}
}
2 changes: 2 additions & 0 deletions .swiftformatignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Package.swift
[email protected]
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
SHELL=/bin/bash

baseUrl = https://raw.githubusercontent.com/BinaryBirds/github-workflows/refs/heads/main/scripts

test:
swift test --parallel

lint:
curl -s $(baseUrl)/run-swift-format.sh | bash

format:
curl -s $(baseUrl)/run-swift-format.sh | bash -s -- --fix

release:
swift package update && swift build -c release

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ In your project folder run:
You can just use the [Swift Package Manager](https://theswiftdev.com/2017/11/09/swift-package-manager-tutorial/) as usual:

```swift
.package(url: "https://github.com/binarybirds/testify", from: "1.1.2"),
.package(url: "https://github.com/binarybirds/testify", from: "1.2.0"),
```

⚠️ Don't forget to add "Testify" to your target as a dependency!
Expand Down
192 changes: 104 additions & 88 deletions Sources/TestifySDK/Codable/RawTestResultDecoder.swift
Original file line number Diff line number Diff line change
@@ -1,52 +1,16 @@
//
// RawTestResultParser.swift
// RawTestResultDecoder.swift
// Testify
//
// Created by Tibor Bodecs on 2023. 02. 12..
//

import Foundation

private extension String {

func match(_ pattern: String) -> String? {
guard let regex = try? NSRegularExpression(pattern: pattern)
else { return nil }
let matches = regex.matches(
in: self,
range: .init(location: 0, length: count)
)
guard let match = matches.first,
let range = Range(match.range, in: self)
else { return nil }
return String(self[range])
}

var matchedTestName: String? {
guard let match = match("(\\'.+\\')") else {
return nil
}
return String(match.dropFirst().dropLast())
}

var matchedDate: String? {
match("(\\d{4}-\\d{2}-\\d{2}\\s\\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{3})")
}

var matchedSeconds: String? {
match("(\\d+\\.\\d+)")
}

var matchedUnexpected: String? {
guard let dropFirst = match("\\((\\d+)")?.dropFirst() else { return nil }
return String(dropFirst)
}
}

public struct RawTestResultDecoder {

private let dateFormatter: DateFormatter

public init() {
self.dateFormatter = .init()
self.dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
Expand All @@ -57,47 +21,32 @@ public struct RawTestResultDecoder {
var currentCaseName: String?
var testCaseOutput: String = ""
var gatherTestCaseOutput = false

let lines = input.split(separator: "\n").map({ String($0) })
for (index, line) in lines.enumerated() {
// start or end test suite
if line.contains("Test Suite") {
if line.contains("started") {
guard let name = line.matchedTestName else { continue }

guard let matchedDate = line.matchedDate,
let date = dateFormatter.date(from: matchedDate)
else { continue }

suites.append(
TestSuite(
name: name,
startDate: date,
endDate: date,
unexpected: 0,
outcome: .failure
)
)
continue;
}
else {
guard line.contains("started") else {
guard var suite = suites.last else { continue }
suites = Array(suites.dropLast())

suite.outcome = line.contains("passed") ? .success : .failure

suite.outcome =
line.contains("passed") ? .success : .failure
if let matchedDate = line.matchedDate,
let date = dateFormatter.date(from: matchedDate) {
let date = dateFormatter.date(from: matchedDate)
{
suite.endDate = date
}
if index+1 < lines.count {
let nextLine = lines[index+1]
if index + 1 < lines.count {
let nextLine = lines[index + 1]
if nextLine.contains("Executed"),
let matchedUnexpected = nextLine.matchedUnexpected,
let unexpected = UInt(matchedUnexpected) {
let matchedUnexpected = nextLine.matchedUnexpected,
let unexpected = UInt(matchedUnexpected)
{
suite.unexpected = unexpected
}
}

if suites.isEmpty {
suites.append(suite)
}
Expand All @@ -108,39 +57,64 @@ public struct RawTestResultDecoder {
suites.append(parentSuite)
}
}
continue;
continue
}
guard let name = line.matchedTestName else { continue }

guard let matchedDate = line.matchedDate,
let date = dateFormatter.date(from: matchedDate)
else { continue }

suites.append(
TestSuite(
name: name,
startDate: date,
endDate: date,
unexpected: 0,
outcome: .failure
)
)
continue
}
if line.contains("Test Case") {
if line.contains("started") {
testCaseOutput = ""
gatherTestCaseOutput = true
currentCaseName = line.matchedTestName
continue;
}
else {
guard line.contains("started") else {
gatherTestCaseOutput = false
guard var suite = suites.last else { continue }
suites = Array(suites.dropLast())
let outcome: Outcome = line.contains("passed") || line.contains("measured") ? .success : .failure

let outcome: Outcome =
line.contains("passed") || line.contains("measured")
? .success : .failure

var failureInfo: FailureInfo? = nil
if outcome == .failure, !testCaseOutput.isEmpty {
let outputSplit = testCaseOutput.split(separator: ":")
let file = String(outputSplit[0])
if outputSplit.count >= 2, let line = Int(outputSplit[1]) {
let reason = String(outputSplit.dropFirst(4)
.joined(separator: ":")
.trimmingCharacters(in: CharacterSet(charactersIn: "-").union(.whitespaces)))
failureInfo = FailureInfo(file: file, line: line, reason: reason)
if outputSplit.count >= 2,
let line = Int(outputSplit[1])
{
let reason = String(
outputSplit.dropFirst(4)
.joined(separator: ":")
.trimmingCharacters(
in: CharacterSet(charactersIn: "-")
.union(.whitespaces)
)
)
failureInfo = FailureInfo(
file: file,
line: line,
reason: reason
)
}
}
if let _currentCaseName = currentCaseName,

if let notNullcurrentCaseName = currentCaseName,
let matchedSeconds = line.matchedSeconds,
let duration = TimeInterval(matchedSeconds) {

let caseName = _currentCaseName.dropFirst(2).dropLast()
let duration = TimeInterval(matchedSeconds)
{

let caseName = notNullcurrentCaseName.dropFirst(2)
.dropLast()
let firstSplit = caseName.split(separator: ".")
let secondSplit = firstSplit[1].split(separator: " ")
let testCase = TestCase(
Expand All @@ -155,8 +129,12 @@ public struct RawTestResultDecoder {
}
suites.append(suite)
currentCaseName = nil
continue;
continue
}
testCaseOutput = ""
gatherTestCaseOutput = true
currentCaseName = line.matchedTestName
continue
}
if gatherTestCaseOutput {
testCaseOutput += line
Expand All @@ -165,3 +143,41 @@ public struct RawTestResultDecoder {
return suites.first
}
}

extension String {

fileprivate func match(_ pattern: String) -> String? {
guard let regex = try? NSRegularExpression(pattern: pattern)
else { return nil }
let matches = regex.matches(
in: self,
range: .init(location: 0, length: count)
)
guard let match = matches.first,
let range = Range(match.range, in: self)
else { return nil }
return String(self[range])
}

fileprivate var matchedTestName: String? {
guard let match = match("(\\'.+\\')") else {
return nil
}
return String(match.dropFirst().dropLast())
}

fileprivate var matchedDate: String? {
match("(\\d{4}-\\d{2}-\\d{2}\\s\\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{3})")
}

fileprivate var matchedSeconds: String? {
match("(\\d+\\.\\d+)")
}

fileprivate var matchedUnexpected: String? {
guard let dropFirst = match("\\((\\d+)")?.dropFirst() else {
return nil
}
return String(dropFirst)
}
}
Loading

0 comments on commit 6de3d18

Please sign in to comment.