Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optionally configure ignore old tests #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
25 changes: 19 additions & 6 deletions src/main/java/hudson/tasks/junit/JUnitParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public class JUnitParser extends TestResultParser {

private final boolean keepLongStdio;
private final boolean allowEmptyResults;
private final boolean allowOldResults;

/** TODO TestResultParser.all does not seem to ever be called so why must this be an Extension? */
@Deprecated
Expand All @@ -59,8 +60,7 @@ public JUnitParser() {
*/
@Deprecated
public JUnitParser(boolean keepLongStdio) {
this.keepLongStdio = keepLongStdio;
this.allowEmptyResults = false;
this(keepLongStdio, false, false);
}

/**
Expand All @@ -69,8 +69,19 @@ public JUnitParser(boolean keepLongStdio) {
* @since 1.10
*/
public JUnitParser(boolean keepLongStdio, boolean allowEmptyResults) {
this.keepLongStdio = keepLongStdio;
this.allowEmptyResults = allowEmptyResults;
this(keepLongStdio, allowEmptyResults, false);
}

/**
* @param keepLongStdio if true, retain a suite's complete stdout/stderr even if this is huge and the suite passed
* @param allowEmptyResults if true, empty results are allowed
* @param allowOldResults
* @since 1.16
*/
public JUnitParser(boolean keepLongStdio, boolean allowEmptyResults, boolean allowOldResults) {
this.keepLongStdio = keepLongStdio;
this.allowEmptyResults = allowEmptyResults;
this.allowOldResults = allowEmptyResults;
}

@Override
Expand Down Expand Up @@ -101,7 +112,7 @@ public TestResult parseResult(String testResultLocations,
// also get code that deals with testDataPublishers from JUnitResultArchiver.perform

return workspace.act(new ParseResultCallable(testResultLocations, buildTime,
timeOnMaster, keepLongStdio, allowEmptyResults));
timeOnMaster, keepLongStdio, allowEmptyResults, allowOldResults));
}

private static final class ParseResultCallable extends MasterToSlaveFileCallable<TestResult> {
Expand All @@ -110,14 +121,16 @@ private static final class ParseResultCallable extends MasterToSlaveFileCallable
private final long nowMaster;
private final boolean keepLongStdio;
private final boolean allowEmptyResults;
private final boolean allowOldResults;

private ParseResultCallable(String testResults, long buildTime, long nowMaster,
boolean keepLongStdio, boolean allowEmptyResults) {
boolean keepLongStdio, boolean allowEmptyResults, boolean allowOldResults) {
this.buildTime = buildTime;
this.testResults = testResults;
this.nowMaster = nowMaster;
this.keepLongStdio = keepLongStdio;
this.allowEmptyResults = allowEmptyResults;
this.allowOldResults = allowOldResults;
}

public TestResult invoke(File ws, VirtualChannel channel) throws IOException {
Expand Down
15 changes: 13 additions & 2 deletions src/main/java/hudson/tasks/junit/TestResult.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public final class TestResult extends MetaTabulatedResult {
private transient List<CaseResult> failedTests;

private final boolean keepLongStdio;
private final boolean allowOldResults;

/**
* Creates an empty result.
Expand All @@ -108,6 +109,15 @@ public TestResult() {
*/
public TestResult(boolean keepLongStdio) {
this.keepLongStdio = keepLongStdio;
this.allowOldResults = false;
}

/**
* @since 1.6
*/
public TestResult(boolean keepLongStdio, boolean allowOldResults) {
this.keepLongStdio = keepLongStdio;
this.allowOldResults = allowOldResults;
}

@Deprecated
Expand All @@ -123,6 +133,7 @@ public TestResult(long buildTime, DirectoryScanner results) throws IOException {
*/
public TestResult(long buildTime, DirectoryScanner results, boolean keepLongStdio) throws IOException {
this.keepLongStdio = keepLongStdio;
this.allowOldResults = false;
parse(buildTime, results);
}

Expand Down Expand Up @@ -170,8 +181,8 @@ public void parse(long buildTime, File baseDir, String[] reportFiles) throws IOE

for (String value : reportFiles) {
File reportFile = new File(baseDir, value);
// only count files that were actually updated during this build
if (buildTime-3000/*error margin*/ <= reportFile.lastModified()) {
// only count files that were actually updated during this build, unless configured to include all
if (buildTime-3000/*error margin*/ <= reportFile.lastModified() || allowOldResults) {
parsePossiblyEmpty(reportFile);
parsed = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ THE SOFTWARE.
<f:entry title="${%Allow empty results}" field="allowEmptyResults">
<f:checkbox default="false" title="${%Do not fail the build on empty test results}"/>
</f:entry>
<f:entry title="${%Allow old results}" field="allowOldResults">
<f:checkbox default="false" title="${%Do not fail the build on old test results}"/>
</f:entry>
</f:advanced>
</j:jelly>