Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure correct LaunchAction scheme order #686

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ensure correct LaunchAction scheme order
Adds logic and tests to ensure that the XML
ordering for `LaunchAction` matches what
xcode expects
  • Loading branch information
maxwellE committed Jun 2, 2022
commit 5a4ce5537db95403df7823886916aa879f7b724f
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 expecteBuildActionXml =
"""
<?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: expecteBuildActionXml.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: expecteBuildActionXml.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(expectedXML, result.cleaned, line: line)
maxwellE marked this conversation as resolved.
Show resolved Hide resolved
}
}