From b7fb74570a721112c49df56889e013460182d6a6 Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Tue, 25 Feb 2025 12:14:37 +0100 Subject: [PATCH 1/2] Fix showOnlyFailures for merged results --- src/main/java/org/tap4j/plugin/TapResult.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/tap4j/plugin/TapResult.java b/src/main/java/org/tap4j/plugin/TapResult.java index a622c74..1fe5a46 100644 --- a/src/main/java/org/tap4j/plugin/TapResult.java +++ b/src/main/java/org/tap4j/plugin/TapResult.java @@ -105,8 +105,11 @@ public TapResult copyWithExtraTestSets(List testSets) { List mergedTestSets = new ArrayList<>(getTestSets()); mergedTestSets.addAll(testSets); - return new TapResult(this.getName(), this.getOwner(), mergedTestSets, this.getTodoIsFailure(), - this.getIncludeCommentDiagnostics(), this.getValidateNumberOfTests()); + TapResult tapResult = new TapResult(this.getName(), this.getOwner(), mergedTestSets, this.getTodoIsFailure(), + this.getIncludeCommentDiagnostics(), this.getValidateNumberOfTests()); + + tapResult.setShowOnlyFailures(getShowOnlyFailures()); + return tapResult; } public Boolean getShowOnlyFailures() { From 844284cdadfa5e401062b189d42a3a43d22730fe Mon Sep 17 00:00:00 2001 From: d2weber <29163905+d2weber@users.noreply.github.com> Date: Sun, 2 Mar 2025 10:29:08 +0100 Subject: [PATCH 2/2] Add PublisherKeepsPropertiesTest --- .../plugin/PublisherKeepsPropertiesTest.java | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/test/java/org/tap4j/plugin/PublisherKeepsPropertiesTest.java diff --git a/src/test/java/org/tap4j/plugin/PublisherKeepsPropertiesTest.java b/src/test/java/org/tap4j/plugin/PublisherKeepsPropertiesTest.java new file mode 100644 index 0000000..8f7964f --- /dev/null +++ b/src/test/java/org/tap4j/plugin/PublisherKeepsPropertiesTest.java @@ -0,0 +1,97 @@ +/* + * The MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +package org.tap4j.plugin; + +import hudson.Launcher; +import hudson.model.AbstractBuild; +import hudson.model.BuildListener; +import hudson.model.FreeStyleBuild; +import hudson.model.FreeStyleProject; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.TestBuilder; +import org.jvnet.hudson.test.TouchBuilder; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; + +import static org.junit.Assert.assertTrue; + + +public class PublisherKeepsPropertiesTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + private FreeStyleProject project; + + @Before + public void setUp() throws Exception { + project = j.createFreeStyleProject("tap"); + + final String tap = "1..2\n" + + "ok 1 sample First ok\n" + + "not ok 2 sample Second failed\n"; + + project.getBuildersList().add(new TestBuilder() { + @Override + public boolean perform(AbstractBuild build, Launcher arg1, + BuildListener arg2) throws InterruptedException, IOException { + build.getWorkspace().child("sample.tap").write(tap,"UTF-8"); + return true; + } + }); + + project.getBuildersList().add(new TouchBuilder()); + } + + @Test + public void showOnlyFailures() throws Exception { + project.getPublishersList().add(sampleTapPublisher(true)); + project.getPublishersList().add(sampleTapPublisher(true)); + FreeStyleBuild build = project.scheduleBuild2(0).get(1000, TimeUnit.SECONDS); + TapTestResultAction testResultAction = build.getAction(TapTestResultAction.class); + assertTrue(testResultAction.getTapResult().getShowOnlyFailures()); + } + + TapPublisher sampleTapPublisher(boolean showOnlyFailures) { + return new TapPublisher( + "sample.tap", + true, + true, + false, + true, + true, + false, + true, + true, + true, + false, + showOnlyFailures, + false, + false, + false, + false + ); + } +}