Skip to content

Commit

Permalink
Added test target to Verification Suite main script
Browse files Browse the repository at this point in the history
Reviewers: jerzy.kleszcz

Reviewed By: jerzy.kleszcz

Subscribers: jerzy.kleszcz

Differential Revision: https://phabricator.polidea.com/D2708
  • Loading branch information
siejkowski committed Dec 14, 2017
1 parent 07e313a commit e28ece4
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 52 deletions.
13 changes: 7 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import PackageDescription
let package = Package(
name: "VerificationSuite",
dependencies: [
// Dependencies declare other packages that this package depends on.
// .package(url: /* package url */, from: "1.0.0"),
.package(url: "https://github.com/JohnSundell/ShellOut.git", from: "2.0.0")
.package(url: "https://github.com/JohnSundell/ShellOut.git", from: "2.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 which this package depends on.
.target(
name: "VerificationSuite",
dependencies: ["ShellOut"]),
dependencies: ["ShellOut"]
),
.testTarget(
name: "VerificationSuiteTests",
dependencies: ["VerificationSuite"]
)
]
)
45 changes: 45 additions & 0 deletions Sources/VerificationSuite/VerificationSuite.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import Foundation
import ShellOut

func executableFromProjectBuild(xcodeproj: String, scheme: String, outputPath: String) -> String {

let buildSettingsDict: [String:String] =
xcodebuild(project: xcodeproj, scheme: scheme, outputBuildPath: outputPath)
.components(separatedBy: "\n")
.map { $0.trimmingCharacters(in: .whitespaces) }
.reduce(into: [:]) { dict, settingLine in
let pair = settingLine.components(separatedBy: " = ")
guard pair.count == 2 else {
return
}
dict[pair[0]] = pair[1]
}

guard let productsPathComponent = buildSettingsDict["BUILT_PRODUCTS_DIR"],
let executablePathComponent = buildSettingsDict["EXECUTABLE_PATH"] else {
print("Failed to extract executable path from built project")
exit(0)
}
let executablePath = productsPathComponent + "/" + executablePathComponent

return executablePath
}

func xcodebuild(project: String, scheme: String, outputBuildPath: String) -> String {
// build project
var arguments = [
"-project", project,
"-derivedDataPath", outputBuildPath,
"-scheme", scheme,
"-configuration", "Release",
]
try! shellOut(to: "xcodebuild", arguments: arguments)

// return build settings for the same build parameters
arguments.append("-showBuildSettings")
return try! shellOut(to: "xcodebuild", arguments: arguments)
}

func removeDirectory(_ path: String) {
try! shellOut(to: "rm", arguments: ["-rf", path])
}
46 changes: 0 additions & 46 deletions Sources/VerificationSuite/main.swift
Original file line number Diff line number Diff line change
@@ -1,49 +1,4 @@
import Foundation
import ShellOut

func executableFromProjectBuild(xcodeproj: String, scheme: String, outputPath: String) -> String {

let buildSettingsDict: [String:String] =
xcodebuild(project: xcodeproj, scheme: scheme, outputBuildPath: outputPath)
.components(separatedBy: "\n")
.map { $0.trimmingCharacters(in: .whitespaces) }
.reduce(into: [:]) { dict, settingLine in
let pair = settingLine.components(separatedBy: " = ")
guard pair.count == 2 else {
return
}
dict[pair[0]] = pair[1]
}

guard let productsPathComponent = buildSettingsDict["BUILT_PRODUCTS_DIR"],
let executablePathComponent = buildSettingsDict["EXECUTABLE_PATH"] else {
print("Failed to extract executable path from built project")
exit(0)
}
let executablePath = productsPathComponent + "/" + executablePathComponent

return executablePath
}

func xcodebuild(project: String, scheme: String, outputBuildPath: String) -> String {
// build project
var arguments = [
"-project", project,
"-derivedDataPath", outputBuildPath,
"-scheme", scheme,
"-configuration", "Release",
]
try! shellOut(to: "xcodebuild", arguments: arguments)

// return build settings for the same build parameters
arguments.append("-showBuildSettings")
return try! shellOut(to: "xcodebuild", arguments: arguments)
}

func removeDirectory(_ path: String) {
try! shellOut(to: "rm", arguments: ["-rf", path])
}


// check script arguments

Expand Down Expand Up @@ -77,4 +32,3 @@ let obfuscatedExecutablePath = executableFromProjectBuild(xcodeproj: xcodeprojAf

removeDirectory(buildPathBeforeObfuscation)
removeDirectory(buildPathAfterObfuscation)

11 changes: 11 additions & 0 deletions Tests/VerificationSuiteTests/VerificationSuiteTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import XCTest
@testable import VerificationSuite

class VerificationSuiteTests: XCTestCase {

func testAlwaysSucceeds() {
XCTAssertEqual(true, true, "The truth is out there")
}

}

0 comments on commit e28ece4

Please sign in to comment.