Skip to content

Commit

Permalink
Merge pull request #36 from maiflai/verbosity
Browse files Browse the repository at this point in the history
Verbosity
  • Loading branch information
maiflai authored Jul 21, 2016
2 parents b73e5b1 + 72ecc23 commit 6a3aca0
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 54 deletions.
43 changes: 0 additions & 43 deletions ScalaTestAction.groovy

This file was deleted.

59 changes: 54 additions & 5 deletions src/main/groovy/com/github/maiflai/ScalaTestAction.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.gradle.api.GradleException
import org.gradle.api.internal.file.FileResolver
import org.gradle.api.reporting.DirectoryReport
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.api.tasks.util.PatternSet
import org.gradle.internal.UncheckedException
import org.gradle.process.internal.DefaultJavaExecAction
Expand Down Expand Up @@ -70,14 +72,61 @@ class ScalaTestAction implements Action<Test> {
return javaExecHandleBuilder
}

static Set<TestLogEvent> other(Set<TestLogEvent> required) {
def all = TestLogEvent.values() as Set
(required + all) - required.intersect(all)
}

static String drop(TestLogEvent event, int granularity) {
switch (event) {
case TestLogEvent.STARTED: 'NHP' // test and suite and scope
break;
case TestLogEvent.PASSED: 'CLQ' // test and suite and scope
break;
case TestLogEvent.SKIPPED: 'XER' // ignored and pending and scope
break;
case TestLogEvent.FAILED: ''
break;
case TestLogEvent.STANDARD_OUT:
case TestLogEvent.STANDARD_ERROR: 'OM' // infoprovided, markupprovided
break;
}
}

static String dropped(Test t) {
other(t.testLogging.events).collect { drop(it, t.testLogging.displayGranularity) }.join('')
}

static String color(Test t) {
if (!t.getProject().getGradle().getStartParameter().isColorOutput()) {
'W'
} else {
''
}
}

static String exceptions(Test t) {
if (t.testLogging.showExceptions) {
switch (t.testLogging.exceptionFormat) {
case TestExceptionFormat.FULL:
return 'F'
case TestExceptionFormat.SHORT:
return 'S'
}
}
return ''
}

static String durations = 'D'

static String reporting(Test t) {
'-o' + ((dropped(t) + color(t) + exceptions(t) + durations) as List).unique().sort().join('')
}

private static Iterable<String> getArgs(Test t) {
List<String> args = new ArrayList<String>()
// this represents similar behaviour to the existing JUnit test action
if (t.getProject().getGradle().getStartParameter().isColorOutput()) {
args.add('-oD')
} else {
args.add('-oDW')
}
args.add(reporting(t))
if (t.maxParallelForks == 0) {
args.add('-PS')
} else {
Expand Down
4 changes: 4 additions & 0 deletions src/main/groovy/com/github/maiflai/ScalaTestPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import org.gradle.api.Project
import org.gradle.api.plugins.JavaPlugin
import org.gradle.api.plugins.scala.ScalaPlugin
import org.gradle.api.tasks.testing.Test
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.api.tasks.util.PatternSet

/**
Expand All @@ -25,6 +27,7 @@ class ScalaTestPlugin implements Plugin<Project> {
new JacocoTestAction(),
new ScalaTestAction()
]
test.testLogging.exceptionFormat = TestExceptionFormat.SHORT
test.extensions.add(ScalaTestAction.TAGS, new PatternSet())
List<String> suites = []
test.extensions.add(ScalaTestAction.SUITES, suites)
Expand All @@ -37,6 +40,7 @@ class ScalaTestPlugin implements Plugin<Project> {
if (test.name != JavaPlugin.TEST_TASK_NAME) {
test.reports.html.destination = project.reporting.file(test.name)
}
test.testLogging.events = TestLogEvent.values() as Set
}
}
}
Expand Down
67 changes: 61 additions & 6 deletions src/test/groovy/com/github/maiflai/ScalaTestActionTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ package com.github.maiflai

import org.gradle.api.Project
import org.gradle.api.Task
import org.gradle.process.internal.JavaExecAction;
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
import org.gradle.process.internal.JavaExecAction
import org.gradle.testfixtures.ProjectBuilder
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
import org.junit.Test

import static org.hamcrest.CoreMatchers.equalTo
import static org.hamcrest.CoreMatchers.hasItem
import static org.hamcrest.CoreMatchers.not
import static com.github.maiflai.ScalaTestAction.other
import static org.hamcrest.CoreMatchers.*
import static org.hamcrest.core.CombinableMatcher.both
import static org.hamcrest.core.Is.is
import static org.junit.Assert.assertThat

class ScalaTestActionTest {
Expand All @@ -32,6 +34,21 @@ class ScalaTestActionTest {
action.getCommandLine()
}

private static Matcher<List<String>> hasOutput(String required) {
return new TypeSafeMatcher<List<String>>() {
@Override
protected boolean matchesSafely(List<String> strings) {
def output = strings.find { it.startsWith('-o') }
return output.contains(required)
}

@Override
void describeTo(Description description) {
description.appendText("a list containing -o[...$required...]")
}
}
}

private static Map<String, Object> environment(org.gradle.api.tasks.testing.Test task) {
JavaExecAction action = ScalaTestAction.makeAction(task)
action.getEnvironment()
Expand All @@ -56,14 +73,35 @@ class ScalaTestActionTest {
public void colorOutputIsDisabled() {
Task test = testTask()
test.getProject().getGradle().startParameter.setColorOutput(false)
assertThat(commandLine(test), hasItem("-oDW".toString()))
assertThat(commandLine(test), hasItem("-oDSW".toString()))
}

@Test
public void colorOutputIsEnabled() {
Task test = testTask()
test.getProject().getGradle().startParameter.setColorOutput(true)
assertThat(commandLine(test), hasItem("-oD".toString()))
assertThat(commandLine(test), hasItem("-oDS".toString()))
}

@Test
public void testDefaultLogging() throws Exception {
Task test = testTask()
assertThat(test.testLogging.events, is(TestLogEvent.values() as Set))
assertThat(commandLine(test), hasOutput('oD'))
}

@Test
public void fullStackTraces() throws Exception {
Task test = testTask()
test.testLogging.exceptionFormat = TestExceptionFormat.FULL
assertThat(commandLine(test), hasOutput('oDF'))
}

@Test
public void shortStackTraces() throws Exception {
Task test = testTask()
test.testLogging.exceptionFormat = TestExceptionFormat.SHORT
assertThat(commandLine(test), hasOutput('oDS'))
}

@Test
Expand Down Expand Up @@ -189,6 +227,23 @@ class ScalaTestActionTest {
assertThat(callsToS.size(), equalTo(1))
}

@Test
public void testKnockout() throws Exception {
assertThat(other([TestLogEvent.FAILED] as Set),
not(hasItem(TestLogEvent.FAILED)))

assertThat(other([TestLogEvent.PASSED, TestLogEvent.FAILED] as Set),
both(not(hasItem(TestLogEvent.PASSED))).and(not(hasItem(TestLogEvent.PASSED))))
}

@Test
public void failedOnlyReporting() throws Exception {
Task test = testTask()
test.testLogging.events = [TestLogEvent.FAILED]
assertThat(commandLine(test), hasOutput('oCDEHLMNOPQRSX'))

}

@Test
public void configString() throws Exception {
Task test = testTask()
Expand Down

0 comments on commit 6a3aca0

Please sign in to comment.