Skip to content

Commit

Permalink
[FIXED JENKINS-17960] [FIXED JENKINS-17781] Adding option to validate…
Browse files Browse the repository at this point in the history
… number of planned tests and number of tests executed
  • Loading branch information
kinow committed Jul 26, 2013
1 parent 02bd377 commit 2127053
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
23 changes: 22 additions & 1 deletion src/main/java/org/tap4j/plugin/TapParser.java
Expand Up @@ -60,6 +60,7 @@ public class TapParser {
private boolean parserErrors;
private boolean hasFailedTests;
private boolean includeCommentDiagnostics;
private boolean validateNumberOfTests;

/**
* @deprecated
Expand All @@ -74,6 +75,10 @@ public TapParser(Boolean outputTapToConsole, Boolean enableSubtests, Boolean tod
this.hasFailedTests = false;
}

/**
* @deprecated
*/
@Deprecated
public TapParser(Boolean outputTapToConsole, Boolean enableSubtests, Boolean todoIsFailure, Boolean includeCommentDiagnostics, PrintStream logger) {
this.outputTapToConsole = outputTapToConsole;
this.enableSubtests = enableSubtests;
Expand All @@ -82,6 +87,16 @@ public TapParser(Boolean outputTapToConsole, Boolean enableSubtests, Boolean tod
this.parserErrors = false;
this.includeCommentDiagnostics = includeCommentDiagnostics;
}

public TapParser(Boolean outputTapToConsole, Boolean enableSubtests, Boolean todoIsFailure, Boolean includeCommentDiagnostics, Boolean validateNumberOfTests, PrintStream logger) {
this.outputTapToConsole = outputTapToConsole;
this.enableSubtests = enableSubtests;
this.todoIsFailure = todoIsFailure;
this.logger = logger;
this.parserErrors = false;
this.includeCommentDiagnostics = includeCommentDiagnostics;
this.validateNumberOfTests = validateNumberOfTests;
}

public boolean hasParserErrors() {
return this.parserErrors;
Expand All @@ -90,7 +105,7 @@ public boolean hasParserErrors() {
public boolean hasFailedTests() {
return this.hasFailedTests;
}

public TapResult parse(FilePath[] results, AbstractBuild<?, ?> build) {
this.parserErrors = Boolean.FALSE;
this.hasFailedTests = Boolean.FALSE;
Expand All @@ -117,6 +132,12 @@ public TapResult parse(FilePath[] results, AbstractBuild<?, ?> build) {
parser = new Tap13Parser();
}
final TestSet testSet = parser.parseFile(tapFile);

if (this.validateNumberOfTests) {
if (testSet.getPlan().getLastTestNumber() != testSet.getNumberOfTestResults()) {
throw new ParserException("Number of tests results didn't go to plan");
}
}

if (testSet.containsNotOk() || testSet.containsBailOut()) {
this.hasFailedTests = Boolean.TRUE;
Expand Down
18 changes: 13 additions & 5 deletions src/main/java/org/tap4j/plugin/TapPublisher.java
Expand Up @@ -68,6 +68,7 @@ public class TapPublisher extends Recorder implements MatrixAggregatable {
private final Boolean discardOldReports;
private final Boolean todoIsFailure;
private final Boolean includeCommentDiagnostics;
private final Boolean validateNumberOfTests;

@DataBoundConstructor
public TapPublisher(String testResults,
Expand All @@ -77,7 +78,8 @@ public TapPublisher(String testResults,
Boolean enableSubtests,
Boolean discardOldReports,
Boolean todoIsFailure,
Boolean includeCommentDiagnostics) {
Boolean includeCommentDiagnostics,
Boolean validateNumberOfTests) {
this.testResults = testResults;
this.failIfNoResults = BooleanUtils.toBooleanDefaultIfNull(failIfNoResults, false);
this.failedTestsMarkBuildAsFailure = BooleanUtils.toBooleanDefaultIfNull(failedTestsMarkBuildAsFailure, false);
Expand All @@ -86,6 +88,7 @@ public TapPublisher(String testResults,
this.discardOldReports = BooleanUtils.toBooleanDefaultIfNull(discardOldReports, false);
this.todoIsFailure = BooleanUtils.toBooleanDefaultIfNull(todoIsFailure, true);
this.includeCommentDiagnostics = BooleanUtils.toBooleanDefaultIfNull(includeCommentDiagnostics, true);
this.validateNumberOfTests = BooleanUtils.toBooleanDefaultIfNull(validateNumberOfTests, false);
}

public Object readResolve() {
Expand All @@ -97,7 +100,8 @@ public Object readResolve() {
Boolean discardOldReports = BooleanUtils.toBooleanDefaultIfNull(this.getDiscardOldReports(), false);
Boolean todoIsFailure = BooleanUtils.toBooleanDefaultIfNull(this.getTodoIsFailure(), true);
Boolean includeCommentDiagnostics = BooleanUtils.toBooleanDefaultIfNull(this.getIncludeCommentDiagnostics(), true);
return new TapPublisher(testResults, failIfNoResults, failedTestsMarkBuildAsFailure, outputTapToConsole, enableSubtests, discardOldReports, todoIsFailure, includeCommentDiagnostics);
Boolean validateNumberOfTests = BooleanUtils.toBooleanDefaultIfNull(this.getValidateNumberOfTests(), false);
return new TapPublisher(testResults, failIfNoResults, failedTestsMarkBuildAsFailure, outputTapToConsole, enableSubtests, discardOldReports, todoIsFailure, includeCommentDiagnostics, validateNumberOfTests);
}

/**
Expand Down Expand Up @@ -152,6 +156,10 @@ public Boolean getTodoIsFailure() {
public Boolean getIncludeCommentDiagnostics() {
return includeCommentDiagnostics;
}

public Boolean getValidateNumberOfTests() {
return validateNumberOfTests;
}

/**
* Gets the directory where the plug-in saves its TAP streams before processing them and
Expand Down Expand Up @@ -234,7 +242,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,

build.getActions().add(new TapTestResultAction(build, testResult));

if (testResult.getTestSets().size() > 0) {
if (testResult.getTestSets().size() > 0 || testResult.getParseErrorTestSets().size() > 0) {
// create an individual report for all of the results and add it to
// the build
TapBuildAction action = new TapBuildAction(build, testResult);
Expand Down Expand Up @@ -269,14 +277,14 @@ private TapResult loadResults(AbstractBuild<?, ?> owner, PrintStream logger) {
try {
results = tapDir.list("**/*.*");

final TapParser parser = new TapParser(getOutputTapToConsole(), getEnableSubtests(), getTodoIsFailure(), getIncludeCommentDiagnostics(), logger);
final TapParser parser = new TapParser(getOutputTapToConsole(), getEnableSubtests(), getTodoIsFailure(), getIncludeCommentDiagnostics(), getValidateNumberOfTests(), logger);
final TapResult result = parser.parse(results, owner);
result.setOwner(owner);
return result;
} catch (Exception e) {
e.printStackTrace(logger);

tr = new TapResult("", owner, Collections.<TestSetMap>emptyList(), getTodoIsFailure());
tr = new TapResult("", owner, Collections.<TestSetMap>emptyList(), getTodoIsFailure(), getIncludeCommentDiagnostics());
tr.setOwner(owner);
return tr;
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/org/tap4j/plugin/TapPublisher/config.jelly
Expand Up @@ -25,5 +25,8 @@
<f:entry title="Include comment diagnostics (#) in the results table">
<f:checkbox name="TapPublisher.includeCommentDiagnostics" value="${instance.includeCommentDiagnostics}" checked="${instance.includeCommentDiagnostics}" />
</f:entry>
<f:entry title="Validate number of tests">
<f:checkbox name="TapPublisher.validateNumberOfTests" value="${instance.validateNumberOfTests}" checked="${instance.validateNumberOfTests}" />
</f:entry>
</f:advanced>
</j:jelly>

1 comment on commit 2127053

@buildhive
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jenkins » tap-plugin #59 FAILURE
Looks like this commit caused a build failure
(what's this?)

Please sign in to comment.