Run swift-format on TulsiEndToEndTests.
PiperOrigin-RevId: 267417036
diff --git a/src/TulsiEndToEndTests/ButtonsEndToEndTest.swift b/src/TulsiEndToEndTests/ButtonsEndToEndTest.swift
index b4cf3f4..1e0f351 100644
--- a/src/TulsiEndToEndTests/ButtonsEndToEndTest.swift
+++ b/src/TulsiEndToEndTests/ButtonsEndToEndTest.swift
@@ -1,4 +1,3 @@
-
// Copyright 2016 The Tulsi Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,36 +13,41 @@
// limitations under the License.
import XCTest
+
@testable import BazelIntegrationTestCase
@testable import TulsiEndToEndTestBase
-
// End to end test that generates the Buttons project and runs its unit tests.
class ButtonsEndToEndTest: TulsiEndToEndTest {
- fileprivate let buttonsProjectPath = "src/TulsiEndToEndTests/Resources/Buttons.tulsiproj"
+ fileprivate let buttonsProjectPath
+ = "src/TulsiEndToEndTests/Resources/Buttons.tulsiproj"
override func setUp() {
super.setUp()
- if (!copyDataToFakeWorkspace("src/TulsiEndToEndTests/Resources")) {
+ if !copyDataToFakeWorkspace("src/TulsiEndToEndTests/Resources") {
XCTFail("Failed to copy Buttons files to fake execroot.")
}
}
func testButtons() throws {
- let xcodeProjectURL = generateXcodeProject(tulsiProject: buttonsProjectPath,
- config: "Buttons")
- XCTAssert(fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
+ let xcodeProjectURL = generateXcodeProject(
+ tulsiProject: buttonsProjectPath,
+ config: "Buttons")
+ XCTAssert(
+ fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
testXcodeProject(xcodeProjectURL, scheme: "ButtonsTests")
}
/// Verifies that all of the _idx_ targets in the project build.
func testIndexingTargetsBuild() throws {
- let xcodeProjectURL = generateXcodeProject(tulsiProject: buttonsProjectPath,
- config: "Buttons")
- XCTAssert(fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
+ let xcodeProjectURL = generateXcodeProject(
+ tulsiProject: buttonsProjectPath,
+ config: "Buttons")
+ XCTAssert(
+ fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
let targets = targetsOfXcodeProject(xcodeProjectURL)
- let indexTargets = targets.filter{ $0.hasPrefix("_idx_") }
+ let indexTargets = targets.filter { $0.hasPrefix("_idx_") }
XCTAssertEqual(indexTargets.count, 8)
for target in indexTargets {
buildXcodeTarget(xcodeProjectURL, target: target)
@@ -51,9 +55,11 @@
}
func testInvalidConfig() throws {
- let xcodeProjectURL = generateXcodeProject(tulsiProject: buttonsProjectPath,
- config: "InvalidConfig")
- XCTAssertFalse(fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was generated despite invalid config.")
+ let xcodeProjectURL = generateXcodeProject(
+ tulsiProject: buttonsProjectPath,
+ config: "InvalidConfig")
+ XCTAssertFalse(
+ fileManager.fileExists(atPath: xcodeProjectURL.path),
+ "Xcode project was generated despite invalid config.")
}
}
-
diff --git a/src/TulsiEndToEndTests/CanaryButtonsEndToEndTest.swift b/src/TulsiEndToEndTests/CanaryButtonsEndToEndTest.swift
index 19d0878..56826f6 100644
--- a/src/TulsiEndToEndTests/CanaryButtonsEndToEndTest.swift
+++ b/src/TulsiEndToEndTests/CanaryButtonsEndToEndTest.swift
@@ -1,4 +1,3 @@
-
// Copyright 2016 The Tulsi Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,6 +13,7 @@
// limitations under the License.
import XCTest
+
@testable import BazelIntegrationTestCase
@testable import TulsiEndToEndTestBase
@testable import TulsiGenerator
@@ -21,7 +21,8 @@
// End to end test that generates the Buttons project and runs its unit tests. This variation of the
// test uses the canary Bazel binary.
class ButtonsEndToEndTest: TulsiEndToEndTest {
- fileprivate let buttonsProjectPath = "third_party/tulsi/src/TulsiEndToEndTests/Resources/Buttons.tulsiproj"
+ fileprivate let buttonsProjectPath
+ = "third_party/tulsi/src/TulsiEndToEndTests/Resources/Buttons.tulsiproj"
override func setUp() {
super.setUp()
@@ -29,7 +30,8 @@
XCTFail("Expected Bazel canary URL.")
return
}
- XCTAssert(fileManager.fileExists(atPath: canaryBazelURL.path), "Bazel canary binary is missing.")
+ XCTAssert(
+ fileManager.fileExists(atPath: canaryBazelURL.path), "Bazel canary binary is missing.")
bazelURL = canaryBazelURL
let completionInfo = ProcessRunner.launchProcessSync(bazelURL.path, arguments: ["version"])
@@ -37,16 +39,17 @@
print(versionOutput)
}
- if (!copyDataToFakeWorkspace("third_party/tulsi/src/TulsiEndToEndTests/Resources")) {
+ if !copyDataToFakeWorkspace("third_party/tulsi/src/TulsiEndToEndTests/Resources") {
XCTFail("Failed to copy Buttons files to fake execroot.")
}
}
func testButtonsWithCanaryBazel() throws {
- let xcodeProjectURL = generateXcodeProject(tulsiProject: buttonsProjectPath,
- config: "Buttons")
- XCTAssert(fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
+ let xcodeProjectURL = generateXcodeProject(
+ tulsiProject: buttonsProjectPath,
+ config: "Buttons")
+ XCTAssert(
+ fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
testXcodeProject(xcodeProjectURL, scheme: "ButtonsLogicTests")
}
}
-
diff --git a/src/TulsiEndToEndTests/NightlyButtonsEndToEndTest.swift b/src/TulsiEndToEndTests/NightlyButtonsEndToEndTest.swift
index 0db6988..7029f1a 100644
--- a/src/TulsiEndToEndTests/NightlyButtonsEndToEndTest.swift
+++ b/src/TulsiEndToEndTests/NightlyButtonsEndToEndTest.swift
@@ -1,4 +1,3 @@
-
// Copyright 2016 The Tulsi Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,15 +13,16 @@
// limitations under the License.
import XCTest
+
@testable import BazelIntegrationTestCase
@testable import TulsiEndToEndTestBase
@testable import TulsiGenerator
-
// End to end test that generates the Buttons project and runs its unit tests. This variation of the
// test uses the nightly Bazel binary.
class ButtonsNightlyEndToEndTest: TulsiEndToEndTest {
- fileprivate let buttonsProjectPath = "third_party/tulsi/src/TulsiEndToEndTests/Resources/Buttons.tulsiproj"
+ fileprivate let buttonsProjectPath
+ = "third_party/tulsi/src/TulsiEndToEndTests/Resources/Buttons.tulsiproj"
override func setUp() {
super.setUp()
@@ -30,7 +30,8 @@
XCTFail("Expected Bazel nightly URL.")
return
}
- XCTAssert(fileManager.fileExists(atPath: nightlyBazelURL.path), "Bazel nightly binary is missing.")
+ XCTAssert(
+ fileManager.fileExists(atPath: nightlyBazelURL.path), "Bazel nightly binary is missing.")
bazelURL = nightlyBazelURL
let completionInfo = ProcessRunner.launchProcessSync(bazelURL.path, arguments: ["version"])
@@ -38,15 +39,17 @@
print(versionOutput)
}
- if (!copyDataToFakeWorkspace("third_party/tulsi/src/TulsiEndToEndTests/Resources")) {
+ if !copyDataToFakeWorkspace("third_party/tulsi/src/TulsiEndToEndTests/Resources") {
XCTFail("Failed to copy Buttons files to fake execroot.")
}
}
func testButtonsWithNightlyBazel() throws {
- let xcodeProjectURL = generateXcodeProject(tulsiProject: buttonsProjectPath,
- config: "Buttons")
- XCTAssert(fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
+ let xcodeProjectURL = generateXcodeProject(
+ tulsiProject: buttonsProjectPath,
+ config: "Buttons")
+ XCTAssert(
+ fileManager.fileExists(atPath: xcodeProjectURL.path), "Xcode project was not generated.")
testXcodeProject(xcodeProjectURL, scheme: "ButtonsLogicTests")
}
}
diff --git a/src/TulsiEndToEndTests/TulsiEndToEndTest.swift b/src/TulsiEndToEndTests/TulsiEndToEndTest.swift
index cf86f9a..512c58b 100644
--- a/src/TulsiEndToEndTests/TulsiEndToEndTest.swift
+++ b/src/TulsiEndToEndTests/TulsiEndToEndTest.swift
@@ -1,4 +1,3 @@
-
// Copyright 2016 The Tulsi Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,10 +13,10 @@
// limitations under the License.
import XCTest
+
@testable import BazelIntegrationTestCase
@testable import TulsiGenerator
-
// Parent class for end to end tests that generate an xcodeproj with the Tulsi binary and verify the
// generated xcodeproj by running the projects unit tests.
class TulsiEndToEndTest: BazelIntegrationTestCase {
@@ -42,18 +41,24 @@
let deviceVersion = TulsiEndToEndTest.targetVersion.replacingOccurrences(of: ".", with: "-")
let typeId = "com.apple.CoreSimulator.SimDeviceType.\(deviceName)"
let runtimeId = "com.apple.CoreSimulator.SimRuntime.iOS-\(deviceVersion)"
- let completionInfo = ProcessRunner.launchProcessSync("/usr/bin/xcrun",
- arguments: ["simctl",
- "create",
- TulsiEndToEndTest.simulatorName,
- typeId,
- runtimeId])
+ let completionInfo = ProcessRunner.launchProcessSync(
+ "/usr/bin/xcrun",
+ arguments: [
+ "simctl",
+ "create",
+ TulsiEndToEndTest.simulatorName,
+ typeId,
+ runtimeId
+ ])
if completionInfo.terminationStatus != 0 {
if let stderr = String(data: completionInfo.stderr, encoding: .utf8), !stderr.isEmpty {
- TulsiEndToEndTest.setUpFailure("\(completionInfo.commandlineString) failed with error: \(stderr)")
+ TulsiEndToEndTest.setUpFailure(
+ "\(completionInfo.commandlineString) failed with error: \(stderr)")
} else {
- TulsiEndToEndTest.setUpFailure("\(completionInfo.commandlineString) encountered an error. Exit code \(completionInfo.terminationStatus).")
+ TulsiEndToEndTest.setUpFailure(
+ "\(completionInfo.commandlineString) encountered an error. Exit code \(completionInfo.terminationStatus)."
+ )
}
}
@@ -67,16 +72,21 @@
override class func tearDown() {
super.tearDown()
- let completionInfo = ProcessRunner.launchProcessSync("/usr/bin/xcrun",
- arguments: ["simctl",
- "delete",
- TulsiEndToEndTest.simulatorName])
+ let completionInfo = ProcessRunner.launchProcessSync(
+ "/usr/bin/xcrun",
+ arguments: [
+ "simctl",
+ "delete",
+ TulsiEndToEndTest.simulatorName
+ ])
if let error = String(data: completionInfo.stderr, encoding: .utf8), !error.isEmpty {
- print("""
+ print(
+ """
\(completionInfo.commandlineString) failed with exit code: \(completionInfo.terminationStatus)
Error: \(error)
- """)
+ """
+ )
}
}
@@ -93,11 +103,15 @@
if !fileManager.fileExists(atPath: workspaceRootURL.appendingPathComponent("Tulsi.app").path) {
// Unzip the Tulsi.app bundle to the temp space.
let tulsiZipPath = "tulsi.zip"
- let tulsiZipURL = runfilesWorkspaceURL.appendingPathComponent(tulsiZipPath, isDirectory: false)
- let completionInfo = ProcessRunner.launchProcessSync("/usr/bin/unzip",
- arguments: [tulsiZipURL.path,
- "-d",
- workspaceRootURL.path])
+ let tulsiZipURL = runfilesWorkspaceURL.appendingPathComponent(
+ tulsiZipPath, isDirectory: false)
+ let completionInfo = ProcessRunner.launchProcessSync(
+ "/usr/bin/unzip",
+ arguments: [
+ tulsiZipURL.path,
+ "-d",
+ workspaceRootURL.path
+ ])
if let error = String(data: completionInfo.stderr, encoding: .utf8), !error.isEmpty {
TulsiEndToEndTest.setUpFailure(error)
@@ -120,7 +134,7 @@
let sourceURL = runfilesWorkspaceURL.appendingPathComponent(path, isDirectory: false)
let destURL = workspaceRootURL.appendingPathComponent(path, isDirectory: false)
do {
- if(!fileManager.fileExists(atPath: sourceURL.path)) {
+ if !fileManager.fileExists(atPath: sourceURL.path) {
XCTFail("Source file \(sourceURL.path) does not exist.")
}
if fileManager.fileExists(atPath: destURL.path) {
@@ -137,8 +151,9 @@
}
// Runs the Tulsi binary with the given Tulsi project and config to generate an Xcode project.
- func generateXcodeProject(tulsiProject path: String, config: String) -> URL{
- let tulsiBinURL = workspaceRootURL.appendingPathComponent("Tulsi.app/Contents/MacOS/Tulsi", isDirectory: false)
+ func generateXcodeProject(tulsiProject path: String, config: String) -> URL {
+ let tulsiBinURL = workspaceRootURL.appendingPathComponent(
+ "Tulsi.app/Contents/MacOS/Tulsi", isDirectory: false)
XCTAssert(fileManager.fileExists(atPath: tulsiBinURL.path), "Tulsi binary is missing.")
let projectURL = workspaceRootURL.appendingPathComponent(path, isDirectory: true)
@@ -146,15 +161,18 @@
let configPath = projectURL.path + ":" + config
// Generate Xcode project with Tulsi.
- let completionInfo = ProcessRunner.launchProcessSync(tulsiBinURL.path,
- arguments: ["--",
- "--genconfig",
- configPath,
- "--outputfolder",
- workspaceRootURL.path,
- "--bazel",
- bazelURL.path,
- "--no-open-xcode"])
+ let completionInfo = ProcessRunner.launchProcessSync(
+ tulsiBinURL.path,
+ arguments: [
+ "--",
+ "--genconfig",
+ configPath,
+ "--outputfolder",
+ workspaceRootURL.path,
+ "--bazel",
+ bazelURL.path,
+ "--no-open-xcode"
+ ])
if let stdoutput = String(data: completionInfo.stdout, encoding: .utf8) {
print(stdoutput)
@@ -174,7 +192,7 @@
XCTAssertFalse(self.fileManager.fileExists(atPath: xcodeProjectURL.path))
}
} catch {
- XCTFail("Error while deleting generated Xcode project: \(error)")
+ XCTFail("Error while deleting generated Xcode project: \(error)")
}
}
@@ -188,13 +206,17 @@
/// - Returns
/// - Dictionary of string to json style objects.
fileprivate func xcodeProjectDictionary(_ xcodeProjectURL: URL) -> [String: Any]? {
- let completionInfo = ProcessRunner.launchProcessSync("/usr/bin/xcodebuild",
- arguments: ["-list",
- "-json",
- "-project",
- xcodeProjectURL.path])
+ let completionInfo = ProcessRunner.launchProcessSync(
+ "/usr/bin/xcodebuild",
+ arguments: [
+ "-list",
+ "-json",
+ "-project",
+ xcodeProjectURL.path
+ ])
guard let stdoutput = String(data: completionInfo.stdout, encoding: .utf8),
- !stdoutput.isEmpty else {
+ !stdoutput.isEmpty
+ else {
if let error = String(data: completionInfo.stderr, encoding: .utf8), !error.isEmpty {
XCTFail(error)
} else {
@@ -202,7 +224,10 @@
}
return nil
}
- guard let jsonDeserialized = try? JSONSerialization.jsonObject(with: completionInfo.stdout, options: []) else {
+ guard
+ let jsonDeserialized = try? JSONSerialization.jsonObject(
+ with: completionInfo.stdout, options: [])
+ else {
XCTFail("Unable to decode from json: \(stdoutput)")
return nil
}
@@ -235,30 +260,36 @@
return targets
}
-
/// Builds an Xcode Target
///
/// - Parameters:
/// - xcodeProjectURL: URL of project.
/// - target: target name
func buildXcodeTarget(_ xcodeProjectURL: URL, target: String) {
- let destination = "platform=iOS Simulator,name=\(TulsiEndToEndTest.simulatorName),OS=\(TulsiEndToEndTest.targetVersion)"
- let completionInfo = ProcessRunner.launchProcessSync("/usr/bin/xcodebuild",
- arguments: ["build",
- "-project",
- xcodeProjectURL.path,
- "-target",
- target,
- "-destination",
- destination,
- "SYMROOT=xcodeBuild"])
+ let destination
+ = "platform=iOS Simulator,name=\(TulsiEndToEndTest.simulatorName),OS=\(TulsiEndToEndTest.targetVersion)"
+ let completionInfo = ProcessRunner.launchProcessSync(
+ "/usr/bin/xcodebuild",
+ arguments: [
+ "build",
+ "-project",
+ xcodeProjectURL.path,
+ "-target",
+ target,
+ "-destination",
+ destination,
+ "SYMROOT=xcodeBuild"
+ ])
if let stdoutput = String(data: completionInfo.stdout, encoding: .utf8),
- !stdoutput.isEmpty,
- let result = stdoutput.split(separator: "\n").last {
+ !stdoutput.isEmpty,
+ let result = stdoutput.split(separator: "\n").last
+ {
if (String(result) != "** BUILD SUCCEEDED **") {
print(stdoutput)
- XCTFail("\(completionInfo.commandlineString) did not return build success. Exit code: \(completionInfo.terminationStatus)")
+ XCTFail(
+ "\(completionInfo.commandlineString) did not return build success. Exit code: \(completionInfo.terminationStatus)"
+ )
}
} else if let error = String(data: completionInfo.stderr, encoding: .utf8), !error.isEmpty {
XCTFail(error)
@@ -270,23 +301,30 @@
// Runs Xcode tests on the given Xcode project and scheme. This verifies that
// the test passes and that rsync behavior is used to copy files.
func testXcodeProject(_ xcodeProjectURL: URL, scheme: String) {
- let destination = "platform=iOS Simulator,name=\(TulsiEndToEndTest.simulatorName),OS=\(TulsiEndToEndTest.targetVersion)"
- let completionInfo = ProcessRunner.launchProcessSync("/usr/bin/xcodebuild",
- arguments: ["test",
- "-project",
- xcodeProjectURL.path,
- "-scheme",
- scheme,
- "-destination",
- destination])
+ let destination
+ = "platform=iOS Simulator,name=\(TulsiEndToEndTest.simulatorName),OS=\(TulsiEndToEndTest.targetVersion)"
+ let completionInfo = ProcessRunner.launchProcessSync(
+ "/usr/bin/xcodebuild",
+ arguments: [
+ "test",
+ "-project",
+ xcodeProjectURL.path,
+ "-scheme",
+ scheme,
+ "-destination",
+ destination
+ ])
if let stdoutput = String(data: completionInfo.stdout, encoding: .utf8),
- !stdoutput.isEmpty,
- let result = stdoutput.split(separator: "\n").last {
+ !stdoutput.isEmpty,
+ let result = stdoutput.split(separator: "\n").last
+ {
XCTAssert(stdoutput.contains("Rsyncing"), "Failed to find 'Rsyncing' in:\n\(stdoutput)")
if (String(result) != "** TEST SUCCEEDED **") {
print(stdoutput)
- XCTFail("\(completionInfo.commandlineString) did not return test success. Exit code: \(completionInfo.terminationStatus)")
+ XCTFail(
+ "\(completionInfo.commandlineString) did not return test success. Exit code: \(completionInfo.terminationStatus)"
+ )
}
} else if let error = String(data: completionInfo.stderr, encoding: .utf8), !error.isEmpty {
XCTFail(error)
@@ -298,16 +336,21 @@
// Runs 'simctl' in a subprocess with whatever command (i.e. boot, shutdown, delete, etc) and
// target simulator specified.
fileprivate func runSimctlCommand(_ command: String, onSimulator target: String) {
- let completionInfo = ProcessRunner.launchProcessSync("/usr/bin/xcrun",
- arguments: ["simctl",
- command,
- target])
+ let completionInfo = ProcessRunner.launchProcessSync(
+ "/usr/bin/xcrun",
+ arguments: [
+ "simctl",
+ command,
+ target
+ ])
if let error = String(data: completionInfo.stderr, encoding: .utf8), !error.isEmpty {
- print("""
+ print(
+ """
\(completionInfo.commandlineString) failed with exit code: \(completionInfo.terminationStatus)
Error: \(error)
- """)
+ """
+ )
}
}
}
@@ -316,10 +359,13 @@
// Performs a deep copy of the item at sourceURL, resolving any symlinks along the way.
func deepCopyItem(at sourceURL: URL, to destURL: URL) throws {
do {
- try self.createDirectory(atPath: destURL.deletingLastPathComponent().path, withIntermediateDirectories: true)
+ try self.createDirectory(
+ atPath: destURL.deletingLastPathComponent().path, withIntermediateDirectories: true)
let rootPath = sourceURL.path
if let rootAttributes = try? self.attributesOfItem(atPath: rootPath) {
- if rootAttributes[FileAttributeKey.type] as? FileAttributeType == FileAttributeType.typeSymbolicLink {
+ if rootAttributes[FileAttributeKey.type] as? FileAttributeType == FileAttributeType
+ .typeSymbolicLink
+ {
let resolvedRootPath = try self.destinationOfSymbolicLink(atPath: rootPath)
try self.copyItem(atPath: resolvedRootPath, toPath: destURL.path)
} else {
@@ -334,7 +380,9 @@
if let attributes = try? self.attributesOfItem(atPath: fullSubpath) {
// If a file is a symbolic link, find the original file, remove the symlink, and copy
// over the original file.
- if attributes[FileAttributeKey.type] as? FileAttributeType == FileAttributeType.typeSymbolicLink {
+ if attributes[FileAttributeKey.type] as? FileAttributeType == FileAttributeType
+ .typeSymbolicLink
+ {
let resolvedPath = try self.destinationOfSymbolicLink(atPath: fullSubpath)
try self.removeItem(atPath: fullSubpath)
try self.copyItem(atPath: resolvedPath, toPath: fullSubpath)
@@ -345,4 +393,3 @@
}
}
}
-