Skip to content

Commit

Permalink
[JENKINS-11225] Added a test case that verifies the current behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Feb 10, 2015
1 parent 0a2472b commit 704943e
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 21 deletions.
93 changes: 72 additions & 21 deletions src/test/java/plugins/WarningsPluginTest.java
@@ -1,5 +1,8 @@
package plugins;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.jenkinsci.test.acceptance.junit.Bug;
import org.jenkinsci.test.acceptance.junit.SmokeTest;
Expand All @@ -12,6 +15,7 @@
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.Job;
import org.jenkinsci.test.acceptance.po.ListView;
import org.jenkinsci.test.acceptance.po.MatrixConfiguration;
import org.jenkinsci.test.acceptance.po.MatrixProject;
import org.junit.Test;
import org.junit.experimental.categories.Category;
Expand All @@ -35,10 +39,55 @@ public class WarningsPluginTest extends AbstractAnalysisTest {
private static final String SEVERAL_PARSERS_FILE_FULL_PATH = "/warnings_plugin/" + SEVERAL_PARSERS_FILE_NAME;

/**
* Checks that the plug-in sends a mail after a build has been failed. The content of the mail
* contains several tokens that should be expanded in the mail with the correct vaules.
* Build a matrix job with three configurations. For each configuration a different set of warnings will be parsed
* with the same parser (GCC). After the successful build the total number of warnings at the root level should be
* set to 12 (sum of all three configurations). Moreover, for each configuration the total number of warnings is
* also verified (4, 6, and 2 warnings).
*/
// TODO: run the job twice and check for the graphs
@Test @Bug("11225")
public void should_report_warnings_per_axis() {
String file = "matrix-warnings.txt";
MatrixProject job = setupJob("/warnings_plugin/" + file, MatrixProject.class,
WarningsBuildSettings.class, new AnalysisConfigurator<WarningsBuildSettings>() {
@Override
public void configure(WarningsBuildSettings settings) {
settings.addConsoleScanner("GNU C Compiler 4 (gcc)");
}
});

job.configure();
job.addUserAxis("user_axis", "one two three");
job.addShellStep("cat " + file + "| grep $user_axis");
job.save();

Build build = buildJobAndWait(job).shouldSucceed();

String title = "GNU C Compiler Warnings";
assertThatActionExists(job, build, title);
build.open();
assertThat(driver, hasContent(title + ": 12"));

Map<String, Integer> warningsPerAxis = new HashMap<>();
warningsPerAxis.put("user_axis=one", 4);
warningsPerAxis.put("user_axis=two", 6);
warningsPerAxis.put("user_axis=three", 2);
for (MatrixConfiguration axis : job.getConfigurations()) {
Build axisBuild = axis.getLastBuild();
assertThat(axisBuild, hasAction(title));
assertThat(driver, hasContent(title + ": " + warningsPerAxis.get(axis.name)));
}

}

/**
* Checks that the plug-in sends a mail after a build has been failed. The content of the mail contains several
* tokens that should be expanded in the mail with the correct vaules.
*/
@Test @Bug("25501") @Category(SmokeTest.class) @WithPlugins("email-ext")
@Test
@Bug("25501")
@Category(SmokeTest.class)
@WithPlugins("email-ext")
public void should_send_mail_with_expanded_tokens() {
setUpMailer();

Expand Down Expand Up @@ -127,7 +176,8 @@ public void build_a_freestyle_job_and_check_if_dashboard_list_view_shows_correct
/**
* Build a job and check set up a dashboard list-view. Check, if the dashboard view shows correct warning count.
*/
@Test @Bug("23446")
@Test
@Bug("23446")
public void build_a_matrix_project_and_check_if_dashboard_list_view_shows_correct_warnings() {
MatrixProject job = setupJob(SEVERAL_PARSERS_FILE_FULL_PATH, MatrixProject.class,
WarningsBuildSettings.class, create3ParserConfiguration());
Expand All @@ -151,8 +201,8 @@ private void verifyWarningsColumn(final Job job) {
}

/**
* Checks that warning results are correctly created for a matrix job with the parsers
* "Java", "JavaDoc" and "MSBuild" if the console log contains multiple warnings of these types.
* Checks that warning results are correctly created for a matrix job with the parsers "Java", "JavaDoc" and
* "MSBuild" if the console log contains multiple warnings of these types.
*/
@Test
public void detect_warnings_of_multiple_compilers_in_console_matrix() {
Expand All @@ -171,7 +221,8 @@ public void detect_warnings_of_multiple_compilers_in_console_matrix() {
/**
* Runs a job with warning threshold configured once and validates that build is marked as unstable.
*/
@Test @Bug("19614")
@Test
@Bug("19614")
public void should_set_build_to_unstable_if_total_warnings_threshold_set() {
AnalysisConfigurator<WarningsBuildSettings> buildConfiguration = new AnalysisConfigurator<WarningsBuildSettings>() {
@Override
Expand All @@ -192,8 +243,8 @@ public void configure(WarningsBuildSettings settings) {
}

/**
* Checks that warning results are correctly created for a freestyle project with the parsers
* "Java", "JavaDoc" and "MSBuild" if the console log contains multiple warnings of these types.
* Checks that warning results are correctly created for a freestyle project with the parsers "Java", "JavaDoc" and
* "MSBuild" if the console log contains multiple warnings of these types.
*/
@Test
public void detect_warnings_of_multiple_compilers_in_console_freestyle() {
Expand All @@ -213,18 +264,18 @@ private void catWarningsToConsole(final Job job) {

private AnalysisConfigurator<WarningsBuildSettings> create3ParserConfiguration() {
return new AnalysisConfigurator<WarningsBuildSettings>() {
@Override
public void configure(WarningsBuildSettings settings) {
settings.addConsoleScanner("Java Compiler (javac)");
settings.addConsoleScanner("JavaDoc Tool");
settings.addConsoleScanner("MSBuild");
}
};
@Override
public void configure(WarningsBuildSettings settings) {
settings.addConsoleScanner("Java Compiler (javac)");
settings.addConsoleScanner("JavaDoc Tool");
settings.addConsoleScanner("MSBuild");
}
};
}

/**
* Checks that warning results are correctly created for the workspace parsers
* "Java", "JavaDoc" and "MSBuild" if a file with multiple warnings of these types is copied to the workspace.
* Checks that warning results are correctly created for the workspace parsers "Java", "JavaDoc" and "MSBuild" if a
* file with multiple warnings of these types is copied to the workspace.
*/
@Test
public void detect_warnings_of_multiple_compilers_in_workspace() {
Expand Down Expand Up @@ -346,9 +397,9 @@ private void assertThatActionExists(final Job job, final Build build, final Stri
}

/**
* Checks whether the warnings plugin picks only specific warnings. The warnings to exclude are given by three exclude
* patterns {".*ignore1.*, .*ignore2.*, .*default.*"}. The result should be a build with 4 Java Warnings (from a file that
* contains 9 warnings).
* Checks whether the warnings plugin picks only specific warnings. The warnings to exclude are given by three
* exclude patterns {".*ignore1.*, .*ignore2.*, .*default.*"}. The result should be a build with 4 Java Warnings
* (from a file that contains 9 warnings).
*/
@Test
public void skip_warnings_in_ignored_parts() {
Expand Down
15 changes: 15 additions & 0 deletions src/test/resources/warnings_plugin/matrix-warnings.txt
@@ -0,0 +1,15 @@
/axis/one/FileOne.c:1: error: implicit typename is deprecated, please see the documentation for details
/axis/one/FileOne.c:2: warning: 'void yyunput(int, char*)' defined but not used
/axis/one/FileOne.c:3: error: implicit typename is deprecated, please see the documentation for details
/axis/one/FileOne.c:4: warning: 'void yyunput(int, char*)' defined but not used

/axis/two/FileTwo.c:1: error: implicit typename is deprecated, please see the documentation for details
/axis/two/FileTwo.c:2: warning: 'void yyunput(int, char*)' defined but not used
/axis/two/FileTwo.c:3: error: implicit typename is deprecated, please see the documentation for details
/axis/two/FileTwo.c:4: warning: 'void yyunput(int, char*)' defined but not used
/axis/two/FileTwo.c:5: error: implicit typename is deprecated, please see the documentation for details
/axis/two/FileTwo.c:6: warning: 'void yyunput(int, char*)' defined but not used

/axis/three/FileThree.c:1: error: implicit typename is deprecated, please see the documentation for details
/axis/three/FileThree.c:2: warning: 'void yyunput(int, char*)' defined but not used

0 comments on commit 704943e

Please sign in to comment.