-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add better codecoverage
- Loading branch information
Showing
10 changed files
with
646 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/test/java/hudson/plugins/msbuild/MSBuildErrorNoteTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package hudson.plugins.msbuild; | ||
|
||
import hudson.MarkupText; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.regex.Matcher; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class MSBuildErrorNoteTest { | ||
|
||
@Test | ||
public void testPatternMatchesErrorMessage() { | ||
String errorMessage = "SomeFile.cs(123,45): error CS1234: Some error message"; | ||
Matcher matcher = MSBuildErrorNote.PATTERN.matcher(errorMessage); | ||
assertTrue(matcher.matches(), "Pattern should match the error message format"); | ||
|
||
assertEquals("SomeFile.cs(123,45):", matcher.group(1).trim(), "Filename and position should match"); | ||
assertEquals("CS1234", matcher.group(2), "Error code should match"); | ||
assertEquals("CS", matcher.group(3), "Error code prefix should match"); | ||
assertEquals("Some error message", matcher.group(4), "Error message should match"); | ||
} | ||
|
||
@Test | ||
public void testAnnotateAddsMarkup() { | ||
String errorMessage = "SomeFile.cs(123,45): error CS1234: Some error message"; | ||
MarkupText markupText = new MarkupText(errorMessage); | ||
MSBuildErrorNote note = new MSBuildErrorNote(); | ||
|
||
note.annotate(null, markupText, 0); | ||
|
||
assertEquals("<span class=error-inline>" + errorMessage + "</span>", | ||
markupText.toString(true), | ||
"The markup should be correctly applied"); | ||
} | ||
|
||
@Test | ||
public void testDescriptorDisplayName() { | ||
MSBuildErrorNote.DescriptorImpl descriptor = new MSBuildErrorNote.DescriptorImpl(); | ||
assertEquals("MSBuild error", descriptor.getDisplayName(), "Display name should be 'MSBuild error'"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/hudson/plugins/msbuild/MsBuildConsoleAnnotatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package hudson.plugins.msbuild; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.regex.Pattern; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class MsBuildConsoleAnnotatorTest { | ||
|
||
private ByteArrayOutputStream out; | ||
private MSBuildConsoleAnnotator annotator; | ||
|
||
@Before | ||
public void setUp() { | ||
out = new ByteArrayOutputStream(); | ||
annotator = new MSBuildConsoleAnnotator(out, StandardCharsets.UTF_8); | ||
} | ||
|
||
@Test | ||
public void testNumberOfWarnings() throws IOException { | ||
String warningMessage = "C:\\path\\to\\file(10,20): warning CS1234: This is a warning message"; | ||
MockMSBuildWarningNote.PATTERN = Pattern.compile(".*warning.*"); | ||
annotator.eol(warningMessage.getBytes(StandardCharsets.UTF_8), warningMessage.length()); | ||
|
||
assertEquals(1, annotator.getNumberOfWarnings()); | ||
assertEquals(0, annotator.getNumberOfErrors()); | ||
} | ||
|
||
@Test | ||
public void testNumberOfErrors() throws IOException { | ||
String errorMessage = "C:\\path\\to\\file(10,20): error CS1234: This is an error message"; | ||
MockMSBuildErrorNote.PATTERN = Pattern.compile(".*error.*"); | ||
annotator.eol(errorMessage.getBytes(StandardCharsets.UTF_8), errorMessage.length()); | ||
|
||
assertEquals(0, annotator.getNumberOfWarnings()); | ||
assertEquals(1, annotator.getNumberOfErrors()); | ||
} | ||
|
||
@Test | ||
public void testBothWarningsAndErrors() throws IOException { | ||
String warningMessage = "C:\\path\\to\\file(10,20): warning CS1234: This is a warning message"; | ||
String errorMessage = "C:\\path\\to\\file(10,20): error CS1234: This is an error message"; | ||
MockMSBuildWarningNote.PATTERN = Pattern.compile(".*warning.*"); | ||
MockMSBuildErrorNote.PATTERN = Pattern.compile(".*error.*"); | ||
|
||
annotator.eol(warningMessage.getBytes(StandardCharsets.UTF_8), warningMessage.length()); | ||
annotator.eol(errorMessage.getBytes(StandardCharsets.UTF_8), errorMessage.length()); | ||
|
||
assertEquals(1, annotator.getNumberOfWarnings()); | ||
assertEquals(1, annotator.getNumberOfErrors()); | ||
} | ||
|
||
@Test | ||
public void testMultipleCloseCalls() throws IOException { | ||
ByteArrayOutputStream mockOutputStream = new ByteArrayOutputStream(); | ||
MSBuildConsoleAnnotator annotator = new MSBuildConsoleAnnotator(mockOutputStream, StandardCharsets.UTF_8); | ||
|
||
annotator.close(); | ||
try { | ||
annotator.close(); // Trying to close again to see if it handles multiple closes gracefully | ||
} catch (IOException e) { | ||
fail("Should not throw an exception on multiple closes"); | ||
} | ||
} | ||
|
||
private static class MockMSBuildWarningNote extends MSBuildWarningNote { | ||
@SuppressWarnings("unused") | ||
static Pattern PATTERN = Pattern.compile(".*warning.*"); | ||
} | ||
|
||
private static class MockMSBuildErrorNote extends MSBuildErrorNote { | ||
@SuppressWarnings("unused") | ||
static Pattern PATTERN = Pattern.compile(".*error.*"); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/test/java/hudson/plugins/msbuild/MsBuildConsoleParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package hudson.plugins.msbuild; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.OutputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.Mockito.*; | ||
|
||
public class MsBuildConsoleParserTest { | ||
|
||
private OutputStream mockOutputStream; | ||
private MsBuildConsoleParser parser; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mockOutputStream = mock(OutputStream.class); | ||
parser = new MsBuildConsoleParser(mockOutputStream, StandardCharsets.UTF_8); | ||
} | ||
|
||
@Test | ||
public void testGetNumberOfWarnings() throws Exception { | ||
String line = " 1 Warning(s)"; | ||
parser.eol(line.getBytes(StandardCharsets.UTF_8), line.length()); | ||
|
||
assertEquals(1, parser.getNumberOfWarnings(), "Number of warnings should match"); | ||
} | ||
|
||
@Test | ||
public void testGetNumberOfErrors() throws Exception { | ||
String line = " 1 Error(s)"; | ||
parser.eol(line.getBytes(StandardCharsets.UTF_8), line.length()); | ||
|
||
assertEquals(1, parser.getNumberOfErrors(), "Number of errors should match"); | ||
} | ||
|
||
@Test | ||
public void testGetNumberOfWarningsAndErrors() throws Exception { | ||
String line1 = " 3 Warning(s)"; | ||
String line2 = " 5 Error(s)"; | ||
parser.eol(line1.getBytes(StandardCharsets.UTF_8), line1.length()); | ||
parser.eol(line2.getBytes(StandardCharsets.UTF_8), line2.length()); | ||
|
||
assertEquals(3, parser.getNumberOfWarnings(), "Number of warnings should match"); | ||
assertEquals(5, parser.getNumberOfErrors(), "Number of errors should match"); | ||
} | ||
|
||
@Test | ||
public void testInvalidWarningCount() throws Exception { | ||
String line = " Warnings: not a number"; | ||
parser.eol(line.getBytes(StandardCharsets.UTF_8), line.length()); | ||
|
||
assertEquals(-1, parser.getNumberOfWarnings(), "Number of warnings should be -1"); | ||
} | ||
|
||
@Test | ||
public void testInvalidErrorCount() throws Exception { | ||
String line = " Errors: not a number"; | ||
parser.eol(line.getBytes(StandardCharsets.UTF_8), line.length()); | ||
|
||
assertEquals(-1, parser.getNumberOfErrors(), "Number of errors should be -1"); | ||
} | ||
|
||
@Test | ||
public void testClose() throws Exception { | ||
parser.close(); | ||
verify(mockOutputStream, times(1)).close(); | ||
} | ||
} |
Oops, something went wrong.