Skip to content

Commit 1b54d8b

Browse files
committed
Add ability to fail if not test founds
1 parent 21e2aac commit 1b54d8b

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<groupId>org.scalatest</groupId>
1212
<artifactId>scalatest-maven-plugin</artifactId>
1313
<packaging>maven-plugin</packaging>
14-
<version>2.0.2</version>
14+
<version>2.0.3</version>
1515
<name>ScalaTest Maven Plugin</name>
1616
<description>Integrates ScalaTest into Maven</description>
1717

src/main/java/org/scalatest/tools/maven/AbstractScalaTestMojo.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,13 @@ abstract class AbstractScalaTestMojo extends AbstractMojo {
217217
*/
218218
boolean logForkedProcessCommand;
219219

220+
/**
221+
* Fail test of not test suite discovered.
222+
*
223+
* @parameter property="failIfNoTests" default-value="false"
224+
*/
225+
boolean failIfNoTests = false;
226+
220227
/**
221228
* Span scale factor.
222229
*
@@ -398,7 +405,7 @@ private List<String> testClasspathElements() {
398405
}
399406

400407
// This is the configuration parameters shared by all concrete Mojo subclasses
401-
List<String> sharedConfiguration() {
408+
List<String> sharedConfiguration() throws MojoFailureException {
402409
return unmodifiableList(
403410
new ArrayList<String>() {{
404411
addAll(runpath());
@@ -481,7 +488,7 @@ private List<String> parallel() {
481488
// a substring. A -t argument is used for tests preceded by an '@'
482489
// sign, and -z is used for others.
483490
//
484-
private List<String> suites() {
491+
private List<String> suites() throws MojoFailureException {
485492
List<String> list = new ArrayList<String>();
486493

487494
for (String suite: splitOnComma(suites)) {
@@ -496,6 +503,8 @@ private List<String> suites() {
496503
}
497504
}
498505
}
506+
if(failIfNoTests && list.isEmpty())
507+
throw new MojoFailureException( "No tests were executed! (Set -DfailIfNoTests=false to ignore this error.)");
499508
return unmodifiableList(list);
500509
}
501510

src/main/java/org/scalatest/tools/maven/ReporterMojo.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,8 @@ public void generate(Sink sink, Locale locale) throws MavenReportException {
8383
}
8484
}
8585

86-
private String[] configuration() {
87-
return concat(
88-
sharedConfiguration(),
89-
fileReporterConfig()
90-
);
86+
private String[] configuration() throws MojoFailureException {
87+
return concat(sharedConfiguration(), fileReporterConfig());
9188
}
9289

9390
private List<String> fileReporterConfig() {

src/main/java/org/scalatest/tools/maven/TestMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
111111
}
112112
}
113113

114-
String[] configuration() {
114+
String[] configuration() throws MojoFailureException {
115115
return concat(
116116
sharedConfiguration(),
117117
stdout(),

0 commit comments

Comments
 (0)