mirror of
https://github.com/yonaskolb/XcodeGen.git
synced 2026-03-18 20:02:25 +00:00
@@ -366,15 +366,31 @@ extension BuildType: JSONPrimitiveConvertible {
|
||||
|
||||
extension XCScheme.EnvironmentVariable: JSONObjectConvertible, Equatable {
|
||||
|
||||
static private func parseValue(_ value: Any ) -> String {
|
||||
if let bool = value as? Bool {
|
||||
return bool ? "YES" : "NO"
|
||||
} else {
|
||||
return String(describing: value)
|
||||
}
|
||||
}
|
||||
|
||||
public init(jsonDictionary: JSONDictionary) throws {
|
||||
|
||||
if let value = jsonDictionary["value"] {
|
||||
self.value = XCScheme.EnvironmentVariable.parseValue(value)
|
||||
} else {
|
||||
// will throw error
|
||||
value = try jsonDictionary.json(atKeyPath: "value")
|
||||
}
|
||||
variable = try jsonDictionary.json(atKeyPath: "variable")
|
||||
value = try jsonDictionary.json(atKeyPath: "value")
|
||||
enabled = (try? jsonDictionary.json(atKeyPath: "isEnabled")) ?? true
|
||||
}
|
||||
|
||||
static func parseAll(jsonDictionary: JSONDictionary) throws -> [XCScheme.EnvironmentVariable] {
|
||||
if let variablesDictionary: [String: String] = jsonDictionary.json(atKeyPath: "environmentVariables") {
|
||||
return variablesDictionary.map { XCScheme.EnvironmentVariable(variable: $0.key, value: $0.value, enabled: true) }
|
||||
if let variablesDictionary: [String: Any] = jsonDictionary.json(atKeyPath: "environmentVariables") {
|
||||
return variablesDictionary.mapValues(parseValue)
|
||||
.map { XCScheme.EnvironmentVariable(variable: $0.key, value: $0.value, enabled: true) }
|
||||
.sorted { $0.variable < $1.variable }
|
||||
} else if let variablesArray: [JSONDictionary] = jsonDictionary.json(atKeyPath: "environmentVariables") {
|
||||
return try variablesArray.map(XCScheme.EnvironmentVariable.init)
|
||||
} else {
|
||||
|
||||
@@ -246,13 +246,17 @@ func specLoadingTests() {
|
||||
],
|
||||
"run": [
|
||||
"environmentVariables": [
|
||||
["variable": "BOOL_TRUE", "value": true],
|
||||
["variable": "BOOL_YES", "value": "YES"],
|
||||
["variable": "ENVIRONMENT", "value": "VARIABLE"],
|
||||
["variable": "OTHER_ENV_VAR", "value": "VAL", "isEnabled": false],
|
||||
],
|
||||
],
|
||||
"test": [
|
||||
"environmentVariables": [
|
||||
"TEST": "VARIABLE"
|
||||
"BOOL_TRUE": true,
|
||||
"BOOL_YES": "YES",
|
||||
"TEST": "VARIABLE",
|
||||
]
|
||||
],
|
||||
"profile": [
|
||||
@@ -263,11 +267,17 @@ func specLoadingTests() {
|
||||
let scheme = try Scheme(name: "Scheme", jsonDictionary: schemeDictionary)
|
||||
|
||||
let expectedRunVariables = [
|
||||
XCScheme.EnvironmentVariable(variable: "BOOL_TRUE", value: "YES", enabled: true),
|
||||
XCScheme.EnvironmentVariable(variable: "BOOL_YES", value: "YES", enabled: true),
|
||||
XCScheme.EnvironmentVariable(variable: "ENVIRONMENT", value: "VARIABLE", enabled: true),
|
||||
XCScheme.EnvironmentVariable(variable: "OTHER_ENV_VAR", value: "VAL", enabled: false)
|
||||
]
|
||||
|
||||
let expectedTestVariables = [XCScheme.EnvironmentVariable(variable: "TEST", value: "VARIABLE", enabled: true)]
|
||||
let expectedTestVariables = [
|
||||
XCScheme.EnvironmentVariable(variable: "BOOL_TRUE", value: "YES", enabled: true),
|
||||
XCScheme.EnvironmentVariable(variable: "BOOL_YES", value: "YES", enabled: true),
|
||||
XCScheme.EnvironmentVariable(variable: "TEST", value: "VARIABLE", enabled: true),
|
||||
]
|
||||
|
||||
try expect(scheme.run?.environmentVariables) == expectedRunVariables
|
||||
try expect(scheme.test?.environmentVariables) == expectedTestVariables
|
||||
|
||||
Reference in New Issue
Block a user