Skip to content

Commit

Permalink
Fix Java ITs (#9635)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastien-marichal committed Aug 12, 2024
1 parent 32d4351 commit 5dd20a0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
13 changes: 10 additions & 3 deletions its/src/test/java/com/sonar/it/csharp/AnalysisWarningsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,29 @@ void analysisWarningsImport() throws IOException {

Ce.Task task = TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult);
assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(task.getWarningsList()).containsExactly("First message", "Second message");
assertThat(task.getWarningsList()).containsExactly(
"First message",
"Second message",
"Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
}

@Test
void analysisWarnings_MSBuild14() throws IOException {
BuildResult buildResult = Tests.analyzeProject(temp, "Roslyn.1.3.2");
Ce.Task task = TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult);
assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(task.getWarningsList()).containsExactly("The analysis using MsBuild 14 is no longer supported and the analysis with MsBuild 15 is deprecated. Please update your pipeline to MsBuild 16 or higher.");
assertThat(task.getWarningsList()).containsExactly(
"The analysis using MsBuild 14 is no longer supported and the analysis with MsBuild 15 is deprecated. Please update your pipeline to MsBuild 16 or higher.",
"Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
}

@Test
void analysisWarnings_MSBuild15() throws IOException {
BuildResult buildResult = Tests.analyzeProject(temp, "Roslyn.2.4.0");
Ce.Task task = TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult);
assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(task.getWarningsList()).containsExactly("The analysis using MsBuild 15 is deprecated. Please update your pipeline to MsBuild 16 or higher.");
assertThat(task.getWarningsList()).containsExactly(
"The analysis using MsBuild 15 is deprecated. Please update your pipeline to MsBuild 16 or higher.",
"Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
}
}
4 changes: 2 additions & 2 deletions its/src/test/java/com/sonar/it/csharp/TestProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void logsContainInfoAndWarning() {
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. " +
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects",
"Found 1 MSBuild C# project: 1 TEST project.");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#", "Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
}

@Test
Expand Down Expand Up @@ -110,6 +110,6 @@ void with_html_and_csharp_code_explicitly_marked_as_test_should_not_populate_met
"Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. " +
"Read more about how the SonarScanner for .NET detects test projects: https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects");
assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild C# project: 1 TEST project.");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#", "Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
}
}
12 changes: 10 additions & 2 deletions its/src/test/java/com/sonar/it/shared/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,23 @@ public static void verifyNoGuiWarnings(Orchestrator orchestrator, BuildResult bu
assertThat(task.getWarningsList()).isEmpty();
}

public static void verifyGuiTestOnlyProjectAnalysisWarning(Orchestrator orchestrator, BuildResult buildResult, String language)
{
verifyGuiTestOnlyProjectAnalysisWarning(orchestrator, buildResult, language, new String[0]);
}

// Verify an AnalysisWarning is raised inside the SQ GUI (on the project dashboard)
public static void verifyGuiTestOnlyProjectAnalysisWarning(Orchestrator orchestrator, BuildResult buildResult, String language) {
public static void verifyGuiTestOnlyProjectAnalysisWarning(Orchestrator orchestrator, BuildResult buildResult, String language, String... additionalWarnings) {
Ce.Task task = TestUtils.getAnalysisWarningsTask(orchestrator, buildResult);
assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(task.getWarningsList()).containsExactly("Your project contains only TEST-code for language " + language
List<String> expectedWarnings = new ArrayList<>();
expectedWarnings.add("Your project contains only TEST-code for language " + language
+ " and no MAIN-code for any language, so only TEST-code related results are imported. "
+ "Many of our rules (e.g. vulnerabilities) are raised only on MAIN-code. "
+ "Read more about how the SonarScanner for .NET detects test projects: "
+ "https://github.com/SonarSource/sonar-scanner-msbuild/wiki/Analysis-of-product-projects-vs.-test-projects");
Collections.addAll(expectedWarnings, additionalWarnings);
assertThat(task.getWarningsList()).containsExactlyElementsOf(expectedWarnings);
}

public static Ce.Task getAnalysisWarningsTask(Orchestrator orchestrator, BuildResult buildResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ public void logsContainInfo() {
assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains(
"INFO: Found 1 MSBuild VB.NET project: 1 MAIN project.",
"INFO: Found 1 MSBuild C# project: 1 TEST project.");
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, buildResult);
assertThat(TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult).getWarningsList()).containsExactly(
"Multi-Language analysis is enabled. If this was not intended, please set \"/d:sonar.scanner.scanAll=false\" in the begin step.");
}

@Test
Expand Down

0 comments on commit 5dd20a0

Please sign in to comment.