Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix plugin ITs: Update expected warnings #6948

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 22 additions & 2 deletions its/src/test/java/com/sonar/it/csharp/AnalysisWarningsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,18 @@ public 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");

if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The assertion of this warning is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(task.getWarningsList()).containsExactly(
"The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
"First message",
"Second message"
);
}
else {
assertThat(task.getWarningsList()).containsExactly("First message", "Second message");
}
}

@Test
Expand All @@ -65,6 +76,15 @@ public void analysisWarnings_OldRoslyn() throws IOException {

Ce.Task task = TestUtils.getAnalysisWarningsTask(ORCHESTRATOR, buildResult);
assertThat(task.getStatus()).isEqualTo(Ce.TaskStatus.SUCCESS);
assertThat(task.getWarningsList()).containsExactly("Analysis using MsBuild 14 and 15 build tools is deprecated. Please update your pipeline to MsBuild 16 or higher.");
if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The assertion of this warning is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(task.getWarningsList()).containsExactly(
"The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
"Analysis using MsBuild 14 and 15 build tools is deprecated. Please update your pipeline to MsBuild 16 or higher."
);
}
else {
assertThat(task.getWarningsList()).containsExactly("Analysis using MsBuild 14 and 15 build tools is deprecated. Please update your pipeline to MsBuild 16 or higher.");
}
}
}
18 changes: 16 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 @@ -21,6 +21,7 @@

import com.sonar.it.shared.TestUtils;
import com.sonar.orchestrator.build.BuildResult;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.BeforeClass;
Expand Down Expand Up @@ -66,7 +67,13 @@ public void logsContainInfoAndWarning() {
"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#");
if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The assertion of this warning is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(buildResult.getLogsLines(l -> l.contains("WARN"))).contains("WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.");
}
else {
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
}
}

@Test
Expand Down Expand Up @@ -108,6 +115,13 @@ public void with_html_and_csharp_code_explicitly_marked_as_test_should_not_popul
"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#");

if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The assertion of this warning is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(buildResult.getLogsLines(l -> l.contains("WARN"))).contains("WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.");
}
else {
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
}
}
}
73 changes: 51 additions & 22 deletions its/src/test/java/com/sonar/it/shared/ScannerCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import com.sonar.orchestrator.build.BuildResult;
import com.sonar.orchestrator.build.SonarScanner;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;

Expand Down Expand Up @@ -51,16 +54,16 @@ public void givenRazorPagesMainCode_whenScannerForCliIsUsed_logsCSharpWarning()
SonarScanner scanner = getSonarScanner(RAZOR_PAGES_PROJECT, "projects/" + RAZOR_PAGES_PROJECT);
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

assertThat(result.getLogsLines(l -> l.contains("WARN")))
.containsExactlyInAnyOrder(
"WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html",
"WARN: Your project contains VB.NET files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html",
INCREMENTAL_PR_ANALYSIS_WARNING,
INCREMENTAL_PR_ANALYSIS_WARNING
);
String[] warnings = {
INCREMENTAL_PR_ANALYSIS_WARNING,
INCREMENTAL_PR_ANALYSIS_WARNING,
"WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html",
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
};

// The HTML plugin works
assertThat(TestUtils.getMeasureAsInt(ORCHESTRATOR, RAZOR_PAGES_PROJECT, "violations")).isEqualTo(2);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
assertThat(result.getLogsLines(l -> l.contains("WARN"))).containsExactlyInAnyOrder(warnings);
}

@Test
Expand All @@ -70,14 +73,23 @@ public void givenMainHtmlCodeAndTestCSharpCode_whenScannerForCliIsUsed_logsCShar
.setTestDirs("test");
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

assertThat(result.getLogsLines(l -> l.contains("WARN")))
.containsExactlyInAnyOrder(
"WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html",
INCREMENTAL_PR_ANALYSIS_WARNING
);
String[] warnings = {
INCREMENTAL_PR_ANALYSIS_WARNING,
"WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html",
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
};

// The HTML plugin works
assertThat(TestUtils.getMeasureAsInt(ORCHESTRATOR, HTML_IN_MAIN_AND_CSHARP_IN_TEST_SUBFOLDERS, "violations")).isEqualTo(2);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);

if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The assertion of the warning regarding 'sonar.token' is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(result.getLogsLines(l -> l.contains("WARN"))).containsExactlyInAnyOrder(warnings);
}
else {
assertThat(result.getLogsLines(l -> l.contains("WARN"))).containsExactlyInAnyOrder(Arrays.copyOfRange(warnings, 0, 2));
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}
}

@Test
Expand All @@ -87,12 +99,20 @@ public void givenTestHtmlAndCSharpCode_whenScannerForCliIsUsed_logsCSharpWarning
.setTestDirs("main,test");
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

assertThat(result.getLogsLines(l -> l.contains("WARN")))
.containsExactlyInAnyOrder(
"WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html",
INCREMENTAL_PR_ANALYSIS_WARNING
);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
String[] warnings = {
INCREMENTAL_PR_ANALYSIS_WARNING,
"WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html",
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
};

if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The assertion of the warning regarding 'sonar.token' is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(result.getLogsLines(l -> l.contains("WARN"))).containsExactlyInAnyOrder(warnings);
}
else {
assertThat(result.getLogsLines(l -> l.contains("WARN"))).containsExactlyInAnyOrder(Arrays.copyOfRange(warnings, 0, 2));
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}
}

@Test
Expand All @@ -103,8 +123,17 @@ public void givenTestHtmlCode_whenScannerForCliIsUsed_doesNotLogCsharpWarning()
.setProperty("sonar.cs.file.suffixes=", ".no_extension");
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

assertThat(result.getLogsLines(l -> l.contains("WARN"))).isEmpty();
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);

if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The assertion of the warning regarding 'sonar.token' is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(result.getLogsLines(l -> l.contains("WARN"))).containsExactlyInAnyOrder(
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter."
);
}
else {
assertThat(result.getLogsLines(l -> l.contains("WARN"))).isEmpty();
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}
}

private SonarScanner getSonarScanner(String projectKey, String projectDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.ws.Ce;
import org.sonarqube.ws.Issues;

import static com.sonar.it.shared.Tests.ORCHESTRATOR;
Expand Down Expand Up @@ -72,7 +73,16 @@ 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);

if (orchestrator.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The below message is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(buildResult.getLogsLines(l -> l.contains("WARN"))).contains(
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter."
);
}
else {
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, buildResult);
}
}

@Test
Expand Down
12 changes: 11 additions & 1 deletion its/src/test/java/com/sonar/it/vbnet/TestProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.sonarqube.ws.Ce;

import static com.sonar.it.vbnet.Tests.ORCHESTRATOR;
import static com.sonar.it.vbnet.Tests.getMeasureAsInt;
Expand Down Expand Up @@ -58,7 +59,16 @@ public void with_vbnet_only_test_should_not_populate_metrics() throws Exception
"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 VB.NET project: 1 TEST project.");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "VB.NET");

if (ORCHESTRATOR.getServer().version().isGreaterThanOrEquals(10, 0)) {
// The below message is temporary, until the `sonar.token` parameter will be fully supported.
assertThat(buildResult.getLogsLines(l -> l.contains("WARN"))).contains(
"WARN: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter."
);
}
else {
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "VB.NET");
}
}

@Test
Expand Down