Skip to content

Commit

Permalink
Merge pull request #9 from roman-dzieciol/relative-url
Browse files Browse the repository at this point in the history
Use URLs relative to xcresult dir
  • Loading branch information
roman-dzieciol authored Apr 13, 2019
2 parents a948c4f + b11c07c commit b614127
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 310 deletions.
501 changes: 245 additions & 256 deletions SWXCResult.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -1,33 +1,82 @@
<?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"
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
<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
BuildableIdentifier = "primary"
BuildableName = "'$(TARGET_NAME)'"
BlueprintName = "SWXCResultTests"
BlueprintIdentifier = "SWXCResult::SWXCResult"
BuildableName = "SWXCResult.framework"
BlueprintName = "SWXCResult"
ReferencedContainer = "container:SWXCResult.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
</TestAction>
</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>
</Scheme>
48 changes: 47 additions & 1 deletion Sources/SWXCResult/SchemeActionResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,52 @@ public final class SchemeActionResult: Codable {
}

public func urlForTestSummary(relativeTo baseURL: URL) -> URL? {
return TestSummaryPath.flatMap({ baseURL.appendingPathComponent($0) })
return TestSummaryPath.flatMap {
URL(fileURLWithPath: $0, isDirectory: false, relativeTo: baseURL)
}
}

public func urlForLogPath(relativeTo baseURL: URL) -> URL? {
return LogPath.flatMap {
URL(fileURLWithPath: $0, isDirectory: false, relativeTo: baseURL)
}
}

public func urlForCodeCoveragePath(relativeTo baseURL: URL) -> URL? {
return CodeCoveragePath.flatMap {
URL(fileURLWithPath: $0, isDirectory: false, relativeTo: baseURL)
} ?? urlForFallbackCodeCoveragePath(relativeTo: baseURL)
}

public func urlForCodeCoverageArchivePath(relativeTo baseURL: URL) -> URL? {
return CodeCoverageArchivePath.flatMap {
URL(fileURLWithPath: $0, isDirectory: true, relativeTo: baseURL)
} ?? urlForFallbackCodeCoverageArchivePath(relativeTo: baseURL)
}
}

extension SchemeActionResult {

public func urlForResultDir(relativeTo baseURL: URL) -> URL? {
return urlForLogPath(relativeTo: baseURL)?.deletingLastPathComponent() ??
urlForTestSummary(relativeTo: baseURL)?.deletingLastPathComponent()
}

public func urlForFallbackCodeCoverageArchivePath(relativeTo baseURL: URL) -> URL? {
if HasCodeCoverage, let resultDirURL = urlForResultDir(relativeTo: baseURL) {
return URL(fileURLWithPath: resultDirURL.relativePath,
isDirectory: true,
relativeTo: baseURL).appendingPathComponent("action.xccovarchive")
}
return nil
}

public func urlForFallbackCodeCoveragePath(relativeTo baseURL: URL) -> URL? {
if HasCodeCoverage, let resultDirURL = urlForResultDir(relativeTo: baseURL) {
return URL(fileURLWithPath: resultDirURL.relativePath,
isDirectory: false,
relativeTo: baseURL).appendingPathComponent("action.xccovreport")
}
return nil
}
}
1 change: 0 additions & 1 deletion Sources/SWXCResult/SchemeActionResultTestSummary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ public final class SchemeActionResultTestSummary: Codable {

public let TestableSummaries: [SchemeActionTestableSummary]


public static func from(contentsOf url: URL) throws -> SchemeActionResultTestSummary {
let inputData = try Data(contentsOf: url)
let decoder = PropertyListDecoder()
Expand Down
16 changes: 8 additions & 8 deletions Sources/SWXCResult/SchemeActionsInvocationRecord.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ public final class SchemeActionsInvocationRecord: Codable {
self.archiveGUID = archiveGUID
}

public func urlForTestSummary(relativeTo baseURL: URL) throws -> URL {
guard let TestSummaryPath = TestSummaryPath else {
throw XCResultError.testSummaryPathMissing
public func urlForTestSummary(relativeTo baseURL: URL) -> URL? {
return TestSummaryPath.flatMap {
let originalURL = URL(fileURLWithPath: $0, isDirectory: false)
return URL(fileURLWithPath: originalURL.lastPathComponent, isDirectory: false, relativeTo: baseURL)
}
let url = URL(fileURLWithPath: TestSummaryPath)
return baseURL.appendingPathComponent(url.lastPathComponent)
}

public func testSummary(relativeTo baseURL: URL) throws -> TestSummariesPlist {
let url = try urlForTestSummary(relativeTo: baseURL)
return try TestSummariesPlist.from(contentsOf: url)
public func testSummary(relativeTo baseURL: URL) throws -> TestSummariesPlist? {
return try urlForTestSummary(relativeTo: baseURL).flatMap {
return try TestSummariesPlist.from(contentsOf: $0)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/SWXCResult/XCResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public final class XCResult {

public init(bundleURL: URL) throws {
self.bundleURL = bundleURL
infoURL = bundleURL.appendingPathComponent("Info.plist")
infoURL = URL(fileURLWithPath: "Info.plist", isDirectory: false, relativeTo: bundleURL)

let inputData = try Data(contentsOf: infoURL)
let decoder = PropertyListDecoder()
Expand Down
12 changes: 0 additions & 12 deletions Sources/SWXCResult/XCResultError.swift

This file was deleted.

17 changes: 16 additions & 1 deletion Tests/SWXCResultTests/PlistTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ final class PlistTests: XCTestCase {

let xcresult = try XCResult(bundleURL: inputURL)
let infoPlist = xcresult.infoPlist
XCTAssertNotNil(xcresult.infoURL.baseURL)
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 testSummariesURL = infoPlist.urlForTestSummary(relativeTo: inputURL)!
XCTAssertNotNil(testSummariesURL.baseURL)
let testSummariesPlist = try infoPlist.testSummary(relativeTo: inputURL)
let testSummariesOutputURL = urlForStoringInTempDir(url: testSummariesURL)

Expand All @@ -26,10 +28,23 @@ final class PlistTests: XCTestCase {
try xcresult.infoPlist.Actions?.forEach { action in
try [action.ActionResult, action.BuildResult].compactMap{ $0 }.forEach { result in
if let url = result.urlForTestSummary(relativeTo: inputURL) {
XCTAssertNotNil(url.baseURL)
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))

if let logURL = result.urlForLogPath(relativeTo: bundleDirURL) {
XCTAssertNotNil(logURL.baseURL)
}

if let codeCoverageURL = result.urlForCodeCoveragePath(relativeTo: bundleDirURL) {
XCTAssertNotNil(codeCoverageURL.baseURL)
}

if let codeCoverageArchiveURL = result.urlForCodeCoverageArchivePath(relativeTo: bundleDirURL) {
XCTAssertNotNil(codeCoverageArchiveURL.baseURL)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion iOSResultBundleApp/generateResultBundles.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ RESULT_BUNDLE_DIR=$1

if [[ ! -d "${RESULT_BUNDLE_DIR}/CleanAnalyzeTest.result" ]]; then
echo "Generating CleanAnalyzeTest.result"
xcodebuild -destination 'platform=iOS Simulator,name=iPhone Xʀ,OS=12.2' -quiet -workspace iOSResultBundleApp.xcworkspace -scheme iOSResultBundleApp clean analyze test -resultBundlePath "${RESULT_BUNDLE_DIR}/CleanAnalyzeTest.result"
xcodebuild -destination 'platform=iOS Simulator,name=iPhone Xʀ,OS=12.2' -quiet -workspace iOSResultBundleApp.xcworkspace -scheme iOSResultBundleApp -enableCodeCoverage YES clean analyze test -resultBundlePath "${RESULT_BUNDLE_DIR}/CleanAnalyzeTest.result"
fi

0 comments on commit b614127

Please sign in to comment.