From c8aef74a93439ebbdfd23316772f53f8925997ca Mon Sep 17 00:00:00 2001 From: Tom Quist Date: Mon, 17 Jun 2019 00:01:33 +0200 Subject: [PATCH] Fix review suggestions --- Sources/ProjectSpec/SpecFile.swift | 4 ++-- Sources/XcodeGenCLI/GenerateCommand.swift | 2 +- Sources/XcodeGenKit/SpecLoader.swift | 4 ++-- Tests/PerformanceTests/PerformanceTests.swift | 2 +- Tests/XcodeGenKitTests/SpecLoadingTests.swift | 10 +++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Sources/ProjectSpec/SpecFile.swift b/Sources/ProjectSpec/SpecFile.swift index 12891915..2cfa55cf 100644 --- a/Sources/ProjectSpec/SpecFile.swift +++ b/Sources/ProjectSpec/SpecFile.swift @@ -82,9 +82,9 @@ public struct SpecFile { } } - public func resolvedDictionary(environmentVariables: [String: String] = ProcessInfo.processInfo.environment) -> JSONDictionary { + public func resolvedDictionary(variables: [String: String] = [:]) -> JSONDictionary { var resolvedSpec = resolvingPaths().mergedDictionary() - for (key, value) in environmentVariables { + for (key, value) in variables { resolvedSpec = resolvedSpec.replaceString("${\(key)}", with: value) } return resolvedSpec diff --git a/Sources/XcodeGenCLI/GenerateCommand.swift b/Sources/XcodeGenCLI/GenerateCommand.swift index 0c51bf29..e5fd61c9 100644 --- a/Sources/XcodeGenCLI/GenerateCommand.swift +++ b/Sources/XcodeGenCLI/GenerateCommand.swift @@ -58,7 +58,7 @@ class GenerateCommand: Command { // load project spec do { - project = try specLoader.loadProject(path: projectSpecPath) + project = try specLoader.loadProject(path: projectSpecPath, variables: ProcessInfo.processInfo.environment) info("Loaded project:\n \(project.debugDescription.replacingOccurrences(of: "\n", with: "\n "))") } catch { throw GenerationError.projectSpecParsingError(error) diff --git a/Sources/XcodeGenKit/SpecLoader.swift b/Sources/XcodeGenKit/SpecLoader.swift index ff66acb3..eaf5757c 100644 --- a/Sources/XcodeGenKit/SpecLoader.swift +++ b/Sources/XcodeGenKit/SpecLoader.swift @@ -15,9 +15,9 @@ public class SpecLoader { self.version = version } - public func loadProject(path: Path, environmentVariables: [String: String] = ProcessInfo.processInfo.environment) throws -> Project { + public func loadProject(path: Path, variables: [String: String] = [:]) throws -> Project { let spec = try SpecFile(path: path) - let resolvedDictionary = spec.resolvedDictionary(environmentVariables: environmentVariables) + let resolvedDictionary = spec.resolvedDictionary(variables: variables) let project = try Project(basePath: spec.basePath, jsonDictionary: resolvedDictionary) self.project = project diff --git a/Tests/PerformanceTests/PerformanceTests.swift b/Tests/PerformanceTests/PerformanceTests.swift index bdc62d0d..931aa2be 100644 --- a/Tests/PerformanceTests/PerformanceTests.swift +++ b/Tests/PerformanceTests/PerformanceTests.swift @@ -42,7 +42,7 @@ class FixturePerformanceTests: XCTestCase { func testCacheFileGeneration() throws { let specLoader = SpecLoader(version: "1.2") - _ = try specLoader.loadProject(path: specPath, environmentVariables: [:]) + _ = try specLoader.loadProject(path: specPath) measure { _ = try! specLoader.generateCacheFile() diff --git a/Tests/XcodeGenKitTests/SpecLoadingTests.swift b/Tests/XcodeGenKitTests/SpecLoadingTests.swift index 202ada9b..cb62451d 100644 --- a/Tests/XcodeGenKitTests/SpecLoadingTests.swift +++ b/Tests/XcodeGenKitTests/SpecLoadingTests.swift @@ -189,7 +189,7 @@ class SpecLoadingTests: XCTestCase { $0.it("expands environment variables") { let path = fixturePath + "env_test.yml" - let project = try loadSpec(path: path, environmentVariables: ["SETTING1": "ENV VALUE1", "SETTING4": "ENV VALUE4"]) + let project = try loadSpec(path: path, variables: ["SETTING1": "ENV VALUE1", "SETTING4": "ENV VALUE4"]) try expect(project.name) == "NewName" try expect(project.settingGroups) == [ @@ -250,7 +250,7 @@ class SpecLoadingTests: XCTestCase { try? Yams.dump(object: dictionary).write(toFile: path.string, atomically: true, encoding: .utf8) let specLoader = SpecLoader(version: "1.1.0") do { - _ = try specLoader.loadProject(path: path, environmentVariables: [:]) + _ = try specLoader.loadProject(path: path) } catch { throw failure("\(error)") } @@ -280,7 +280,7 @@ class SpecLoadingTests: XCTestCase { try? Yams.dump(object: dictionary).write(toFile: path.string, atomically: true, encoding: .utf8) let specLoader = SpecLoader(version: "1.1.0") do { - _ = try specLoader.loadProject(path: path, environmentVariables: [:]) + _ = try specLoader.loadProject(path: path) } catch { throw failure("\(error)") } @@ -965,10 +965,10 @@ fileprivate func getProjectSpec(_ project: [String: Any], file: String = #file, } } -fileprivate func loadSpec(path: Path, environmentVariables: [String: String] = [:], file: String = #file, line: Int = #line) throws -> Project { +fileprivate func loadSpec(path: Path, variables: [String: String] = [:], file: String = #file, line: Int = #line) throws -> Project { do { let specLoader = SpecLoader(version: "1.1.0") - return try specLoader.loadProject(path: path, environmentVariables: environmentVariables) + return try specLoader.loadProject(path: path, variables: variables) } catch { throw failure("\(error)", file: file, line: line) }