Skip to content

Commit

Permalink
Merge pull request #8 from roman-dzieciol/test-summaries
Browse files Browse the repository at this point in the history
Add model and tests for test action result summaries
  • Loading branch information
roman-dzieciol authored Apr 12, 2019
2 parents 29e14ea + 9d13d13 commit a948c4f
Show file tree
Hide file tree
Showing 10 changed files with 1,623 additions and 1,235 deletions.
2,590 changes: 1,508 additions & 1,082 deletions SWXCResult.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,82 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "9999"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SWXCResult::SWXCResult"
BuildableName = "SWXCResult.framework"
BlueprintName = "SWXCResult"
ReferencedContainer = "container:SWXCResult.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
codeCoverageEnabled = "YES"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SWXCResult::SWXCResultTests"
BuildableName = "SWXCResultTests.xctest"
BlueprintName = "SWXCResultTests"
ReferencedContainer = "container:SWXCResult.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<MacroExpansion>
<BuildableReference
<Scheme LastUpgradeVersion = "9999" version = "1.3">
<BuildAction parallelizeBuildables = "YES" buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry buildForTesting = "YES" buildForRunning = "YES" buildForProfiling = "YES" buildForArchiving = "YES" buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BuildableName = "'lib$(TARGET_NAME)'"
BlueprintName = "SWXCResult"
ReferencedContainer = "container:SWXCResult.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
codeCoverageEnabled = "NO">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "SWXCResult::SWXCResult"
BuildableName = "SWXCResult.framework"
BlueprintName = "SWXCResult"
BuildableName = "'$(TARGET_NAME)'"
BlueprintName = "SWXCResultTests"
ReferencedContainer = "container:SWXCResult.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
</Scheme>
4 changes: 4 additions & 0 deletions Sources/SWXCResult/SchemeActionResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,8 @@ public final class SchemeActionResult: Codable {
self.WarningCount = WarningCount
self.WarningSummaries = WarningSummaries
}

public func urlForTestSummary(relativeTo baseURL: URL) -> URL? {
return TestSummaryPath.flatMap({ baseURL.appendingPathComponent($0) })
}
}
18 changes: 18 additions & 0 deletions Sources/SWXCResult/SchemeActionResultTestSummary.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

import Foundation

public final class SchemeActionResultTestSummary: Codable {

public let FormatVersion: String

public let RunDestination: SchemeActionRunDestinationRecord

public let TestableSummaries: [SchemeActionTestableSummary]


public static func from(contentsOf url: URL) throws -> SchemeActionResultTestSummary {
let inputData = try Data(contentsOf: url)
let decoder = PropertyListDecoder()
return try decoder.decode(SchemeActionResultTestSummary.self, from: inputData)
}
}
30 changes: 0 additions & 30 deletions Tests/SWXCResultTests/InfoPlistTests.swift

This file was deleted.

62 changes: 62 additions & 0 deletions Tests/SWXCResultTests/PlistTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import XCTest
@testable import SWXCResult


final class PlistTests: XCTestCase {

func testCodable() throws {
do {
let bundleDirURL = try generateResultBundles()
let inputURL = bundleDirURL.appendingPathComponent("CleanAnalyzeTest.result")

let xcresult = try XCResult(bundleURL: inputURL)
let infoPlist = xcresult.infoPlist
let infoOutputURL = urlForStoringInTempDir(url: xcresult.infoURL)

try write(asPlist: infoPlist, url: infoOutputURL)
XCTAssertTrue(try diff(url: xcresult.infoURL, with: infoOutputURL))

let testSummariesURL = try infoPlist.urlForTestSummary(relativeTo: inputURL)
let testSummariesPlist = try infoPlist.testSummary(relativeTo: inputURL)
let testSummariesOutputURL = urlForStoringInTempDir(url: testSummariesURL)

try write(asPlist: testSummariesPlist, url: testSummariesOutputURL)
XCTAssertTrue(try diff(url: testSummariesURL, with: testSummariesOutputURL))

try xcresult.infoPlist.Actions?.forEach { action in
try [action.ActionResult, action.BuildResult].compactMap{ $0 }.forEach { result in
if let url = result.urlForTestSummary(relativeTo: inputURL) {
let summaries = try SchemeActionResultTestSummary.from(contentsOf: url)
let outputURL = urlForStoringInTempDir(url: url)
try write(asPlist: summaries, url: outputURL)
XCTAssertTrue(try diff(url: url, with: outputURL))
}
}
}
} catch {
NSLog("error: \(error)")
throw error
}
}

func write<T>(asPlist object: T, url: URL) throws where T: Codable {
let plistEncoder = PropertyListEncoder()
plistEncoder.outputFormat = .xml
let outputData = try plistEncoder.encode(object)
try outputData.write(to: url)
}

func urlForStoringInTempDir(url: URL) -> URL {
let ext = url.pathExtension
let basename = url.deletingPathExtension().lastPathComponent
return FileManager.default
.temporaryDirectory
.appendingPathComponent(basename)
.appendingPathExtension(UUID().uuidString)
.appendingPathExtension(ext)
}

static var allTests = [
("testCodable", testCodable),
]
}
34 changes: 0 additions & 34 deletions Tests/SWXCResultTests/TestSummariesPlistTests.swift

This file was deleted.

2 changes: 1 addition & 1 deletion Tests/SWXCResultTests/XCTestCase+Resources.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public func urlForSourceRoot() -> URL {


public func urlForBundleDir() -> URL {
return Bundle.init(for: TestSummariesPlistTests.self).bundleURL.standardized.deletingLastPathComponent()
return Bundle.init(for: PlistTests.self).bundleURL.standardized.deletingLastPathComponent()
}

public func urlForResource(named name: String) -> URL {
Expand Down
3 changes: 1 addition & 2 deletions Tests/SWXCResultTests/XCTestManifests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import XCTest
#if !os(macOS)
public func allTests() -> [XCTestCaseEntry] {
return [
testCase(InfoPlistTests.allTests),
testCase(TestSummariesPlists.allTests),
testCase(PlistTests.allTests),
]
}
#endif

0 comments on commit a948c4f

Please sign in to comment.