Skip to content

Commit

Permalink
Merge pull request #686 from maxwellE/ensure_correct_scheme_attribute…
Browse files Browse the repository at this point in the history
…_order
  • Loading branch information
danieleformichelli committed Jun 11, 2022
2 parents 65ca255 + 49d4820 commit 651cbda
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 14 deletions.
1 change: 1 addition & 0 deletions Sources/XcodeProj/Extensions/AEXML+XcodeFormat.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ let attributesOrder: [String: [String]] = [
"buildConfiguration",
"selectedDebuggerIdentifier",
"selectedLauncherIdentifier",
"customLLDBInitFile",
"language",
"region",
"launchStyle",
Expand Down
81 changes: 67 additions & 14 deletions Tests/XcodeProjTests/Extensions/AEXML+XcodeFormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extension String {
}

class AEXML_XcodeFormatTests: XCTestCase {
private let expectedXml =
private let expectedBuildActionXml =
"""
<?xml version="1.0" encoding="UTF-8"?>
<BuildAction
Expand All @@ -20,27 +20,80 @@ class AEXML_XcodeFormatTests: XCTestCase {
</BuildAction>
"""

private let expectedLaunchActionXml =
"""
<?xml version="1.0" encoding="UTF-8"?>
<LaunchAction
buildConfiguration = "Debug"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
customLLDBInitFile = "$(BAZEL_LLDB_INIT)"
launchStyle = "0"
allowLocationSimulation = "YES">
</LaunchAction>
"""

func test_BuildAction_attributes_sorted_when_original_sorted() {
validateAttributes(attributes: [
"parallelizeBuildables": "YES",
"runPostActionsOnFailure": "YES",
"buildImplicitDependencies": "NO",
])
validateAttributes(
expectedXML: expectedBuildActionXml.cleaned,
childName: "BuildAction",
attributes: [
"parallelizeBuildables": "YES",
"runPostActionsOnFailure": "YES",
"buildImplicitDependencies": "NO",
]
)
}

func test_BuildAction_attributes_sorted_when_original_unsorted() {
validateAttributes(attributes: [
"buildImplicitDependencies": "NO",
"parallelizeBuildables": "YES",
"runPostActionsOnFailure": "YES",
])
validateAttributes(
expectedXML: expectedBuildActionXml.cleaned,
childName: "BuildAction",
attributes: [
"buildImplicitDependencies": "NO",
"parallelizeBuildables": "YES",
"runPostActionsOnFailure": "YES",
]
)
}

func test_LaunchAction_attributes_sorted_when_original_sorted() {
validateAttributes(
expectedXML: expectedLaunchActionXml.cleaned,
childName: "LaunchAction",
attributes: [
"buildConfiguration": "Debug",
"selectedLauncherIdentifier": "Xcode.DebuggerFoundation.Launcher.LLDB",
"customLLDBInitFile": "$(BAZEL_LLDB_INIT)",
"launchStyle": "0",
"allowLocationSimulation": "YES"
]
)
}

func test_LaunchAction_attributes_sorted_when_original_unsorted() {
validateAttributes(
expectedXML: expectedLaunchActionXml.cleaned,
childName: "LaunchAction",
attributes: [
"customLLDBInitFile": "$(BAZEL_LLDB_INIT)",
"allowLocationSimulation": "YES",
"buildConfiguration": "Debug",
"selectedLauncherIdentifier": "Xcode.DebuggerFoundation.Launcher.LLDB",
"launchStyle": "0",
]
)
}

func validateAttributes(attributes: [String: String], line: UInt = #line) {
func validateAttributes(
expectedXML: String,
childName: String,
attributes: [String: String],
line: UInt = #line
) {
let document = AEXMLDocument()
let child = document.addChild(name: "BuildAction")
let child = document.addChild(name: childName)
child.attributes = attributes
let result = document.xmlXcodeFormat
XCTAssertEqual(expectedXml.cleaned, result.cleaned, line: line)
XCTAssertEqual(result.cleaned, expectedXML, line: line)
}
}

0 comments on commit 651cbda

Please sign in to comment.