-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
782 additions
and
120 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
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
71 changes: 71 additions & 0 deletions
71
buildSrc/src/main/kotlin/com/cmgapps/gradle/TestResultMapper.kt
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,71 @@ | ||
/* | ||
* Copyright (c) 2021. Christian Grach <christian.grach@cmgapps.com> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.cmgapps.gradle | ||
|
||
import org.gradle.api.logging.Logger | ||
import org.gradle.api.tasks.testing.TestDescriptor | ||
import org.gradle.api.tasks.testing.TestResult | ||
import org.gradle.api.tasks.testing.TestResult.ResultType | ||
|
||
const val CSI = "\u001B[" | ||
const val ANSI_RED = "31" | ||
const val ANSI_GREEN = "32" | ||
const val ANSI_YELLOW = "33" | ||
const val ANSI_BOLD = "1" | ||
|
||
fun Logger.logResults(desc: TestDescriptor, result: TestResult) { | ||
val message = "{} > {} {}" + if (result.exception != null) "\n>\t{}\n" else "\n" | ||
|
||
@OptIn(ExperimentalStdlibApi::class) | ||
val params = buildList<String> { | ||
add(desc.className?.substringAfterLast('.') ?: "") | ||
add(desc.displayName) | ||
add(getFormattedResult(result)) | ||
result.exception?.let { | ||
add(it.message?.replace("\n", "\n>\t") ?: "") | ||
} | ||
}.toTypedArray() | ||
|
||
if (result.resultType == ResultType.FAILURE) { | ||
this.error(message, *params) | ||
} else { | ||
this.lifecycle(message, *params) | ||
} | ||
} | ||
|
||
private fun getFormattedResult(result: TestResult): String { | ||
return buildString { | ||
val isAnsiColorTerm = System.getenv("TERM")?.toLowerCase()?.contains("color") ?: false | ||
val (color, text) = when (result.resultType) { | ||
ResultType.SUCCESS -> ANSI_GREEN to "PASSED" | ||
ResultType.FAILURE -> ANSI_RED to "FAILED" | ||
ResultType.SKIPPED -> ANSI_YELLOW to "SKIPPED" | ||
null -> ANSI_YELLOW to "NO RESULT" | ||
} | ||
if (isAnsiColorTerm) { | ||
append(CSI) | ||
append(color) | ||
append(";${ANSI_BOLD}m") | ||
} | ||
append(text) | ||
|
||
if (isAnsiColorTerm) { | ||
append(CSI) | ||
append("0m") | ||
} | ||
} | ||
} |
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.