package hudson.plugins.warnings.parser; import static junit.framework.Assert.*; import hudson.plugins.warnings.util.model.FileAnnotation; import hudson.plugins.warnings.util.model.Priority; import java.io.IOException; import java.util.Collection; import java.util.Iterator; import org.junit.Test; /** * Tests the class {@link GccParser}. */ public class GccParserTest extends ParserTester { /** Error message. */ private static final String WRONG_NUMBER_OF_WARNINGS_DETECTED = "Wrong number of warnings detected."; /** An error. */ private static final String GCC_ERROR = "GCC error"; /** A warning. */ private static final String GCC_WARNING = "GCC warning"; /** * Creates a new instance of {@link GccParserTest}. */ public GccParserTest() { super(GccParser.class); } /** * Parses a file with two GCC warnings. * * @throws IOException * if the file could not be read */ @Test public void testWarningsParser() throws IOException { Collection warnings = new GccParser().parse(openFile()); assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 8, warnings.size()); Iterator iterator = warnings.iterator(); FileAnnotation annotation = iterator.next(); checkWarning(annotation, 451, "`void yyunput(int, char*)' defined but not used", "testhist.l", GccParser.WARNING_TYPE, GCC_WARNING, Priority.NORMAL); annotation = iterator.next(); checkWarning(annotation, 73, "implicit typename is deprecated, please see the documentation for details", "/u1/drjohn/bfdist/packages/RegrTest/V00-03-01/RgtAddressLineScan.cc", GccParser.WARNING_TYPE, GCC_ERROR, Priority.HIGH); annotation = iterator.next(); checkWarning(annotation, 4, "foo.h: No such file or directory", "foo.cc", GccParser.WARNING_TYPE, GCC_ERROR, Priority.HIGH); annotation = iterator.next(); checkWarning(annotation, 0, "undefined reference to 'missing_symbol'", "foo.so", GccParser.WARNING_TYPE, GCC_ERROR, Priority.HIGH); annotation = iterator.next(); checkWarning(annotation, 678, "missing initializer for member sigaltstack::ss_sp", "../../lib/linux-i686/include/boost/test/impl/execution_monitor.ipp", GccParser.WARNING_TYPE, GCC_WARNING, Priority.NORMAL); annotation = iterator.next(); checkWarning(annotation, 678, "missing initializer for member sigaltstack::ss_flags", "../../lib/linux-i686/include/boost/test/impl/execution_monitor.ipp", GccParser.WARNING_TYPE, GCC_WARNING, Priority.NORMAL); annotation = iterator.next(); checkWarning(annotation, 678, "missing initializer for member sigaltstack::ss_size", "../../lib/linux-i686/include/boost/test/impl/execution_monitor.ipp", GccParser.WARNING_TYPE, GCC_WARNING, Priority.NORMAL); annotation = iterator.next(); checkWarning(annotation, 52, "large integer implicitly truncated to unsigned type", "src/test_simple_sgs_message.cxx", GccParser.WARNING_TYPE, GCC_WARNING, Priority.NORMAL); } /** * Parses a warning log with 2 new GCC warnings. * * @throws IOException * if the file could not be read * @see Issue 3897 */ @Test public void issue3897and3898() throws IOException { Collection warnings = new GccParser().parse(openFile("issue3897.txt")); assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 3, warnings.size()); Iterator iterator = warnings.iterator(); checkWarning(iterator.next(), 12, "file.h: No such file or directory", "/dir1/dir2/file.c", GccParser.WARNING_TYPE, "GCC error", Priority.HIGH); checkWarning(iterator.next(), 233, "undefined reference to `MyInterface::getValue() const'", "/dir1/dir3/file.cpp", GccParser.WARNING_TYPE, "GCC error", Priority.HIGH); checkWarning(iterator.next(), 20, "invalid preprocessing directive #incldue", "/dir1/dir2/file.cpp", GccParser.WARNING_TYPE, "GCC error", Priority.HIGH); } /** * Parses a warning log with 6 new objective C warnings. * * @throws IOException * if the file could not be read * @see Issue 4274 */ @Test public void issue4274() throws IOException { Collection warnings = new GccParser().parse(openFile("issue4274.txt")); assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 4, warnings.size()); Iterator iterator = warnings.iterator(); checkWarning(iterator.next(), 638, "local declaration of \"command\" hides instance variable", "folder1/file1.m", GccParser.WARNING_TYPE, "GCC warning", Priority.NORMAL); checkWarning(iterator.next(), 640, "instance variable \"command\" accessed in class method", "folder1/file1.m", GccParser.WARNING_TYPE, "GCC warning", Priority.NORMAL); checkWarning(iterator.next(), 47, "\"oldGeb\" might be used uninitialized in this function", "file1.m", GccParser.WARNING_TYPE, "GCC warning", Priority.NORMAL); checkWarning(iterator.next(), 640, "local declaration of \"command\" hides instance variable", "file1.m", GccParser.WARNING_TYPE, "GCC warning", Priority.NORMAL); } /** * Parses a file with one warning and matching warning that will be excluded afterwards. * * @throws IOException * if the file could not be read * @see Issue 4260 */ @Test public void issue4260() throws IOException { Collection warnings = new GccParser().parse(openFile("issue4260.txt")); assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 1, warnings.size()); } @Test public void issue4382() throws IOException { Collection warnings = new GccParser().parse(openFile("issue4382.txt")); assertEquals(WRONG_NUMBER_OF_WARNINGS_DETECTED, 2, warnings.size()); } /** {@inheritDoc} */ @Override protected String getWarningsFile() { return "gcc.txt"; } }