This repository has been archived by the owner on Feb 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a virtual method for customizing the exception message for unity …
…task (#200) ## Description Add a method that can be overridden in the `UnityTask` for customizing the exception message. ## Changes * ![ADD] `UnityTask.composeExceptionMessage,` virtual method for customizing the exception message when the task fails. [NEW]: https://resources.atlas.wooga.com/icons/icon_new.svg "New" [ADD]: https://resources.atlas.wooga.com/icons/icon_add.svg "Add" [IMPROVE]: https://resources.atlas.wooga.com/icons/icon_improve.svg "Improve" [CHANGE]: https://resources.atlas.wooga.com/icons/icon_change.svg "Change" [FIX]: https://resources.atlas.wooga.com/icons/icon_fix.svg "Fix" [UPDATE]: https://resources.atlas.wooga.com/icons/icon_update.svg "Update" [BREAK]: https://resources.atlas.wooga.com/icons/icon_break.svg "Remove" [REMOVE]: https://resources.atlas.wooga.com/icons/icon_remove.svg "Remove" [IOS]: https://resources.atlas.wooga.com/icons/icon_iOS.svg "iOS" [ANDROID]: https://resources.atlas.wooga.com/icons/icon_android.svg "Android" [WEBGL]: https://resources.atlas.wooga.com/icons/icon_webGL.svg "WebGL" [GRADLE]: https://resources.atlas.wooga.com/icons/icon_gradle.svg "GRADLE" [UNITY]: https://resources.atlas.wooga.com/icons/icon_unity.svg "Unity" [LINUX]: https://resources.atlas.wooga.com/icons/icon_linux.svg "Linux" [WIN]: https://resources.atlas.wooga.com/icons/icon_windows.svg "Windows" [MACOS]: https://resources.atlas.wooga.com/icons/icon_iOS.svg "macOS"
- Loading branch information
Showing
7 changed files
with
116 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/integrationTest/groovy/wooga/gradle/unity/tasks/FailTaskIntegrationSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package wooga.gradle.unity.tasks | ||
|
||
|
||
import com.wooga.spock.extensions.unity.UnityPluginTestOptions | ||
import groovy.json.StringEscapeUtils | ||
import wooga.gradle.unity.UnityTaskIntegrationSpec | ||
|
||
import java.util.regex.Matcher | ||
import java.util.regex.Pattern | ||
|
||
class FailingTask extends Unity { | ||
|
||
static Pattern pattern = Pattern.compile("<BUILD ERRORS>(?<summary>(.*\\s*)*)</BUILD ERRORS>") | ||
|
||
// Escape for ^<, ^> | ||
public static String expectedErrorMessage = """[BuildEngine] Collected errors during build process: | ||
<BUILD ERRORS> | ||
[Error] FOO Wooga.UnifiedBuildSystem.Tests.Editor.BuildEngineTest+FailingBuildSteps:FailInElaborateWays (at Packages/com.wooga.unified-build-system/Tests/Editor/BuildEngine/BuildRequestOutputTest.cs:32) | ||
[Error] BAR Wooga.UnifiedBuildSystem.Tests.Editor.BuildEngineTest+FailingBuildSteps:FailInElaborateWays (at Packages/com.wooga.unified-build-system/Tests/Editor/BuildEngine/BuildRequestOutputTest.cs:32) | ||
[Exception] Exception: Boom! Wooga.UnifiedBuildSystem.Editor.BuildTask`1[[Wooga.UnifiedBuildSystem.Editor.BuildTaskArguments, Wooga.Build.Editor, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null]]:Execute (at Packages/com.wooga.build/Editor/Tasks/BuildTask.cs:73) | ||
[Error] Failed to execute task 'FailInElaborateWays' Wooga.UnifiedBuildSystem.Editor.BuildEngine+State:SetBuildFailure (at Packages/com.wooga.unified-build-system/Editor/BuildEngine/BuildEngine.cs:89) | ||
</BUILD ERRORS>""".stripIndent() | ||
|
||
static String buildErrorStartMarker = "<BUILD ERRORS>" | ||
static String buildErrorEndMarker = "</BUILD ERRORS>" | ||
|
||
@Override | ||
protected String composeExceptionMessage(String stdout, String stderr) { | ||
Matcher matcher = pattern.matcher(stderr) | ||
if (matcher.find()){ | ||
var summary = matcher.group(0) | ||
return summary | ||
} | ||
return "" | ||
} | ||
} | ||
|
||
class FailTaskIntegrationSpec extends UnityTaskIntegrationSpec<FailingTask>{ | ||
|
||
static String echoError(String message) { | ||
"""echo "${StringEscapeUtils.escapeJava(message).replace("`", "\\`") }" 1>&2 """ | ||
} | ||
|
||
@UnityPluginTestOptions(writeMockExecutable = false) | ||
def "throws composited exception message"() { | ||
|
||
given: | ||
writeMockExecutable({ | ||
it.text += "\n${FailingTask.expectedErrorMessage.readLines().collect{echoError(it) }.join("\n")}" | ||
it.printEnvironment = false | ||
it.exitValue = 666 | ||
}) | ||
|
||
when: | ||
def result = runTasksWithFailure(subjectUnderTestName) | ||
|
||
then: | ||
result.wasExecuted(subjectUnderTestName) | ||
result.standardError.contains(FailingTask.buildErrorStartMarker) | ||
result.standardError.contains(FailingTask.buildErrorEndMarker) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters