Skip to content
This repository was archived by the owner on Oct 28, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 19 additions & 4 deletions src/test/groovy/PreCommitToJunitStepTests.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PreCommitToJunitStepTests extends ApmBasePipelineTest {
@Test
void testSuccessWithSimpleCommitStages() throws Exception {
def file = 'simple.xml'
script.call(input: 'simple.txt', output: file)
script.call(input: 'simple.txt', output: file, reportSkipped: true)
printCallStack()
assertTrue("The files differ!", FileUtils.contentEqualsIgnoreEOL(
new File("${compareWith}/${file}"),
Expand All @@ -62,7 +62,7 @@ class PreCommitToJunitStepTests extends ApmBasePipelineTest {
@Test
void testSuccessWithAllPreCommitStages() throws Exception {
def file = 'pre-commit.xml'
script.call(input: 'pre-commit.txt', output: file)
script.call(input: 'pre-commit.txt', output: file, reportSkipped: true)
printCallStack()
assertJobStatusSuccess()
assertTrue("The files differ!", FileUtils.contentEqualsIgnoreEOL(
Expand All @@ -74,7 +74,7 @@ class PreCommitToJunitStepTests extends ApmBasePipelineTest {
@Test
void testSuccessWithSkippedPreCommitStages() throws Exception {
def file = 'skipped.xml'
script.call(input: 'skipped.txt', output: file)
script.call(input: 'skipped.txt', output: file, reportSkipped: true)
printCallStack()
assertTrue("The files differ!", FileUtils.contentEqualsIgnoreEOL(
new File("${compareWith}/${file}"),
Expand All @@ -85,7 +85,7 @@ class PreCommitToJunitStepTests extends ApmBasePipelineTest {
@Test
void testSuccessWithGherkinDefects() throws Exception {
def file = 'gherkin.xml'
script.call(input: 'gherkin.txt', output: file)
script.call(input: 'gherkin.txt', output: file, reportSkipped: true)
printCallStack()
assertTrue("The files differ!", FileUtils.contentEqualsIgnoreEOL(
new File("${compareWith}/${file}"),
Expand All @@ -99,4 +99,19 @@ class PreCommitToJunitStepTests extends ApmBasePipelineTest {
printCallStack()
assertTrue(ret.contains('name="foo" />'))
}

@Test
void test_reportSkipped_enabled() throws Exception {
def ret = script.toJunit('foo', 'skipped', 'isortno files to check', true)
printCallStack()
assertTrue(ret.contains('<testcase classname="pre_commit.lint" name="foo"><skipped message="skipped"/><system-out>'))
}

@Test
void test_reportSkipped_disabled() throws Exception {
def ret = script.toJunit('foo', 'skipped', 'isortno files to check', false)
printCallStack()
println ret
assertTrue(ret.equals('<testcase classname="pre_commit.lint" name="foo" />'))
}
}
4 changes: 4 additions & 0 deletions vars/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,10 @@ Parse the pre-commit log file and generates a junit report
preCommitToJunit(input: 'pre-commit.log', output: 'pre-commit-junit.xml')
```

* input: the pre-commit output. Mandatory
* output: the junit output. Mandatory
* enableSkipped: whether to report skipped linting stages. Optional. Default false

## publishToCDN
Publish to the [CDN](https://cloud.google.com/cdn) the given set of source files to the target bucket
with the given headers.
Expand Down
15 changes: 11 additions & 4 deletions vars/preCommitToJunit.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,16 @@

preCommitToJunit(input: 'pre-commit.log', output: 'pre-commit-junit.xml')
*/
<<<<<<< HEAD
def call(Map params = [:]) {
def input = params.containsKey('input') ? params.input : error('preCommitToJunit: input parameter is required.')
def output = params.containsKey('output') ? params.output : error('preCommitToJunit: output parameter is required.')
=======
def call(Map args = [:]) {
def input = args.containsKey('input') ? args.input : error('preCommitToJunit: input parameter is required.')
def output = args.containsKey('output') ? args.output : error('preCommitToJunit: output parameter is required.')
def reportSkipped = args.get('reportSkipped', false)
>>>>>>> ef76384d... Disable/Enable pre-commit skipped tests in the report (#977)

def content = readFile(file: input)
def id, status, message = '', inprogress = false
Expand All @@ -31,7 +38,7 @@ def call(Map params = [:]) {
def matcher = line =~ '(.+)(\\.Passed|\\)Skipped|\\.Skipped|\\.Failed)$'
if (matcher.find()) {
if (id) {
data += toJunit(id, status, message)
data += toJunit(id, status, message, reportSkipped)
}
id = matcher.group(1).replaceAll(/[\W_&&[^\s]]/, '').replaceAll('\\.\\.\\.','').trim()
status = matcher.group(2)
Expand All @@ -42,16 +49,16 @@ def call(Map params = [:]) {
}
}
if (inprogress) {
data += toJunit(id, status, message)
data += toJunit(id, status, message, reportSkipped)
}
data += '</testsuite>'

writeFile file: output, text: data, encoding: 'UTF-8'
}

def toJunit(String name, String status, String message) {
def toJunit(String name, String status, String message, reportSkipped=false) {
String output = "<testcase classname=\"pre_commit.lint\" name=\"${name}\""
if (status?.toLowerCase()?.contains('skipped')) {
if (status?.toLowerCase()?.contains('skipped') && reportSkipped) {
output += "><skipped message=\"skipped\"/><system-out><![CDATA[${normalise(message)}]]></system-out></testcase>"
} else if (status?.toLowerCase()?.contains('failed')) {
output += "><error message=\"error\"/><system-out><![CDATA[${normalise(message)}]]></system-out></testcase>"
Expand Down
4 changes: 4 additions & 0 deletions vars/preCommitToJunit.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ Parse the pre-commit log file and generates a junit report
```
preCommitToJunit(input: 'pre-commit.log', output: 'pre-commit-junit.xml')
```

* input: the pre-commit output. Mandatory
* output: the junit output. Mandatory
* enableSkipped: whether to report skipped linting stages. Optional. Default false