Skip to content

Commit

Permalink
[FIXED JENKINS-14859] Unformatted TAP output in TapResult getContents…
Browse files Browse the repository at this point in the history
… method
  • Loading branch information
kinow committed Sep 10, 2012
1 parent a636973 commit ea70040
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 10 deletions.
24 changes: 15 additions & 9 deletions src/main/java/org/tap4j/plugin/TapResult.java
Expand Up @@ -23,15 +23,17 @@
*/
package org.tap4j.plugin;

import hudson.FilePath;
import hudson.model.ModelObject;
import hudson.model.AbstractBuild;

import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.export.Exported;
import org.tap4j.model.BailOut;
import org.tap4j.model.Directive;
Expand All @@ -40,7 +42,6 @@
import org.tap4j.plugin.model.ParseErrorTestSetMap;
import org.tap4j.plugin.model.TestSetMap;
import org.tap4j.plugin.util.DiagnosticUtil;
import org.tap4j.producer.TapProducerFactory;
import org.tap4j.util.DirectiveValues;
import org.tap4j.util.StatusValues;

Expand Down Expand Up @@ -234,13 +235,18 @@ public String getDisplayName() {
return getName();
}

public String getContents(StaplerRequest request) {
String contents = null;
String fileName = request.getParameter("f");
for(TestSetMap tsm : this.testSets) {
if(tsm.getFileName().equals(fileName)) {
TestSet ts = tsm.getTestSet();
contents = TapProducerFactory.makeTap13Producer().dump(ts);
public String getContents(String fileName) {
String contents = "";
if(fileName != null) {
FilePath tapDir = new FilePath(new FilePath(new File(build.getRootDir(), "tap")), fileName);
try {
if(tapDir.exists()) {
contents = tapDir.readToString();
}
} catch (IOException e) {
contents = e.getMessage();
} catch (InterruptedException e) {
contents = e.getMessage();
}
}
return contents;
Expand Down
Expand Up @@ -7,5 +7,5 @@
xmlns:f="/lib/form"
xmlns:i="jelly:fmt"
xmlns:tap="/org/tap4j/plugin/tags">
${it.getContents(request)}
<pre>${it.getContents(request.getParameter("f"))}</pre>
</j:jelly>
67 changes: 67 additions & 0 deletions src/test/java/org/tap4j/plugin/TestTapResultContents.java
@@ -0,0 +1,67 @@
/*
* The MIT License
*
* Copyright (c) <2012> <Bruno P. Kinoshita>
*
* 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.model.FreeStyleBuild;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.junit.Test;
import org.jvnet.hudson.test.Bug;
import org.jvnet.hudson.test.HudsonTestCase;
import org.tap4j.model.TestSet;
import org.tap4j.parser.Tap13Parser;
import org.tap4j.plugin.model.TestSetMap;

/**
*
* @author Bruno P. Kinoshita - http://www.kinoshita.eti.br
* @since 0.1
*/
@Bug(14859)
public class TestTapResultContents extends HudsonTestCase {

@Test
public void testContents() throws IOException, InterruptedException {
Tap13Parser parser = new Tap13Parser();
TestSet ts = parser.parseFile(new File(TestTapResultContents.class.getResource("/org/tap4j/plugin/tap/sample.tap").getFile()));
TestSetMap tsm = new TestSetMap("sample.tap", ts);
List<TestSetMap> tss = new ArrayList<TestSetMap>();
tss.add(tsm);
FreeStyleBuild a = new FreeStyleBuild(createFreeStyleProject()) {
@Override
public File getRootDir() {
return new File(TestTapResultContents.class.getResource("/org/tap4j/plugin/").getFile());
}
};
TapResult result = new TapResult("name", a, tss);
String contents = result.getContents("sample.tap");
String expected = "1..3\nok 1\nnot ok 2\n # some IO error\n # and more text here\nok 3 # SKIP error in test 2";
assertEquals(expected, contents);
}

}
6 changes: 6 additions & 0 deletions src/test/resources/org/tap4j/plugin/tap/sample.tap
@@ -0,0 +1,6 @@
1..3
ok 1
not ok 2
# some IO error
# and more text here
ok 3 # SKIP error in test 2

0 comments on commit ea70040

Please sign in to comment.