Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-11926] Added test case.
  • Loading branch information
uhafner committed Jan 16, 2012
1 parent 3dae5bc commit e1f36eb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
@@ -1,13 +1,19 @@
package hudson.plugins.warnings.parser;

import static junit.framework.Assert.*;
import hudson.plugins.analysis.util.StringPluginLogger;
import hudson.plugins.analysis.util.model.FileAnnotation;

import java.io.File;
import java.io.IOException;
import java.util.Collection;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.junit.Test;

import com.google.common.collect.Lists;

/**
* Test the class {@link DynamicParser}.
*
Expand All @@ -34,11 +40,11 @@ protected WarningsParser createParser() {


/**
* Parses a file with one warning that are started by ant.
* Parses a file with 9 warnings of a custom parser.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-9926">Issue 9926</a>
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-12280">Issue 12280</a>
*/
@Test
public void issue12280() throws IOException {
Expand All @@ -54,6 +60,59 @@ public void issue12280() throws IOException {
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 9, warnings.size());
}

/**
* Parses a file with several warnings from a custom parser.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-11926">Issue 11926</a>
*/
@Test
public void issue11926() throws IOException {
Collection<FileAnnotation> warnings = createCustomParser().parse(openFile("issue11926.txt"));

assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 4, warnings.size());
}


private DynamicParser createCustomParser() {
return new DynamicParser("issue11926",
"FLMSG (\\S+)\\s+([0-9]+) ([^\\s,]+),([0-9]+) (\\S+)",
"import hudson.plugins.warnings.parser.Warning\n"
+ "String fileName = matcher.group(3)\n"
+ "String code = matcher.group(2)\n"
+ "String lineNumber = matcher.group(4)\n"
+ "String type = matcher.group(1)\n"
+ "String message = matcher.group(5)\n"
+ "return new Warning(fileName, Integer.parseInt(lineNumber), type, code, message);");
}

/**
* Parses a file with several warnings from a custom parser.
*
* @throws IOException
* if the file could not be read
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-11926">Issue 11926</a>
*/
@Test
public void issueReadFromFile() throws IOException {
File file = File.createTempFile("warnings", "test");
FileUtils.writeStringToFile(file, IOUtils.toString(openFile("issue11926.txt")), "UTF-8");

DynamicParser dynamicParser = createCustomParser();
ParserRegistry registry = new ParserRegistry(Lists.newArrayList(dynamicParser), "UTF-8", "", "");

file.deleteOnExit();

StringPluginLogger logger = new StringPluginLogger("warnings");
Collection<FileAnnotation> warnings = registry.parse(file, logger);

assertEquals("Wrong logging message", "[warnings] issue11926 : Found 4 warnings.\n", logger.toString());
assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1, warnings.size());
}



/** {@inheritDoc} */
@Override
protected String getWarningsFile() {
Expand Down
@@ -0,0 +1,4 @@
FLMSG Warning 451 /opt/server/jenkins/workspace/prova/src/component/include/myInclude.h,28 Header file '/opt/ti/xdctools_3_22_01_21/packages/xdc/runtime/Main.h' repeatedly included but does not have a standard include guard
FLMSG Warning 451 /opt/server/jenkins/workspace/prova/src/component/include/myInclude.h,28 Header file '/opt/ti/xdctools_3_22_01_21/packages/xdc/runtime/Main.h' repeatedly included but does not have a standard include guard
FLMSG Warning 451 /opt/server/jenkins/workspace/prova/src/component/include/myInclude.h,28 Header file '/opt/ti/xdctools_3_22_01_21/packages/xdc/runtime/Main.h' repeatedly included but does not have a standard include guard
FLMSG Warning 451 /opt/server/jenkins/workspace/prova/src/component/include/myInclude.h,28 Header file '/opt/ti/xdctools_3_22_01_21/packages/xdc/runtime/Main.h' repeatedly included but does not have a standard include guard

0 comments on commit e1f36eb

Please sign in to comment.