-
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.
Tasks derivated from Test now are able to generate code coverage. For it to happen, it is needed to set the extension property enableTestCodeCoverage to true. Coverage reports will be stored together with test reports. This is available only for Unity 2019.4 and older versions. Co-authored-by: Joaquim Neto <joaquim.neto@wooga.net>
- Loading branch information
1 parent
9c3bd81
commit 51f0b25
Showing
9 changed files
with
261 additions
and
21 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
76 changes: 76 additions & 0 deletions
76
src/integrationTest/groovy/wooga/gradle/unity/testutils/GradleRunResult.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,76 @@ | ||
package wooga.gradle.unity.testutils | ||
|
||
import org.gradle.internal.impldep.org.apache.commons.lang.StringUtils | ||
|
||
class GradleRunResult { | ||
private final ArrayList<String> args; | ||
private final Map<String, String> envs; | ||
|
||
GradleRunResult(String stdOutput) { | ||
this(null, stdOutput) | ||
} | ||
|
||
GradleRunResult(String task, String stdOutput) { | ||
if(task != null) { | ||
stdOutput = taskLog(task, stdOutput) | ||
} | ||
this.args = loadArgs(stdOutput) | ||
this.envs = loadEnvs(stdOutput) | ||
} | ||
|
||
ArrayList<String> getArgs() { | ||
return args | ||
} | ||
|
||
Map<String, String> getEnvs() { | ||
return envs | ||
} | ||
|
||
boolean argValueMatches(String key, Closure matcher) { | ||
def argIndex = args.indexOf(key) | ||
def value = args[argIndex+1] | ||
return matcher(value) | ||
} | ||
|
||
private static String taskLog(String task, String stdOutput) { | ||
String taskString = "> Task ${task}" | ||
int taskBeginIdx = stdOutput.indexOf(taskString) + taskString.length() | ||
String taskTail = stdOutput.substring(taskBeginIdx) | ||
int taskEndIdx = taskTail.indexOf("> Task") | ||
def logs = taskTail.substring(0, taskEndIdx) | ||
return logs | ||
} | ||
|
||
private static ArrayList<String> loadArgs(String stdOutput) { | ||
def argumentsStartToken = "[ARGUMENTS]:" | ||
def lastExecutionOffset = stdOutput.lastIndexOf(argumentsStartToken) | ||
if(lastExecutionOffset < 0) { | ||
System.out.println(stdOutput) | ||
throw new IllegalArgumentException("couldn't find arguments list in stdout") | ||
} | ||
def lastExecTailString = stdOutput.substring(lastExecutionOffset) | ||
def argsString = substringBetween(lastExecTailString, argumentsStartToken, "Mock Unity Started"). | ||
replace(argumentsStartToken, "") | ||
def parts = argsString.split(" "). | ||
findAll {!StringUtils.isEmpty(it) }.collect{ it.trim() } | ||
return parts | ||
} | ||
|
||
private static Map<String, String> loadEnvs(String stdOutput) { | ||
String environmentStartToken = "[ENVIRONMENT]:" | ||
def argsString = substringBetween(stdOutput, environmentStartToken, "[ARGUMENTS]"). | ||
replace(environmentStartToken, "") | ||
def parts = argsString.split(System.lineSeparator()). | ||
findAll {!StringUtils.isEmpty(it) }.collect{ it.trim() } | ||
return parts.collectEntries { | ||
return it.split("=", 2) | ||
} | ||
} | ||
private static String substringBetween(String base, String from, String to) { | ||
def customArgsIndex = base.indexOf(from) | ||
def tailString = base.substring(customArgsIndex) | ||
def endIndex = tailString.indexOf(to) | ||
return tailString.substring(0, endIndex) | ||
} | ||
} | ||
|
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
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
Oops, something went wrong.