Skip to content

Commit

Permalink
Revert mitigation for SQ regression on our ITs (#6718)
Browse files Browse the repository at this point in the history
* Revert "Relax Java ITs WARN log checks because of SQ regression (#6715)"

This reverts commit ae8b656.

* Improve comments.
  • Loading branch information
andrei-epure-sonarsource committed Feb 6, 2023
1 parent 6d979a0 commit a783fbe
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions its/src/test/java/com/sonar/it/shared/ScannerCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public class ScannerCliTest {
private static final String RAZOR_PAGES_PROJECT = "WebApplication";
private static final String HTML_IN_MAIN_AND_CSHARP_IN_TEST_SUBFOLDERS = "ScannerCli";

// Note: setting the `sonar.projectBaseDir` only enables Incremental PR Analysis when used with the Scanner for .NET.
private static final String INCREMENTAL_PR_ANALYSIS_WARNING = "WARN: Incremental PR analysis: Could not determine common base path, cache will not be computed. Consider setting 'sonar.projectBaseDir' property.";

@Before
public void init() {
TestUtils.reset(ORCHESTRATOR);
Expand All @@ -49,12 +52,12 @@ public void givenRazorPagesMainCode_whenScannerForCliIsUsed_logsCSharpWarning()
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

assertThat(result.getLogsLines(l -> l.contains("WARN")))
// ToDo revert back to containsExactlyInAnyOrder https://github.com/SonarSource/sonar-dotnet/issues/6714
.contains(
.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: Incremental PR analysis: Could not determine common base path, cache will not be computed. Consider setting 'sonar.projectBaseDir' property.",
"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",
"WARN: Incremental PR analysis: Could not determine common base path, cache will not be computed. Consider setting 'sonar.projectBaseDir' property.");
INCREMENTAL_PR_ANALYSIS_WARNING,
INCREMENTAL_PR_ANALYSIS_WARNING
);
// The HTML plugin works
assertThat(TestUtils.getMeasureAsInt(ORCHESTRATOR, RAZOR_PAGES_PROJECT, "violations")).isEqualTo(2);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
Expand All @@ -68,10 +71,9 @@ public void givenMainHtmlCodeAndTestCSharpCode_whenScannerForCliIsUsed_logsCShar
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

assertThat(result.getLogsLines(l -> l.contains("WARN")))
// ToDo revert back to containsExactlyInAnyOrder https://github.com/SonarSource/sonar-dotnet/issues/6714
.contains(
.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: Incremental PR analysis: Could not determine common base path, cache will not be computed. Consider setting 'sonar.projectBaseDir' property."
INCREMENTAL_PR_ANALYSIS_WARNING
);
// The HTML plugin works
assertThat(TestUtils.getMeasureAsInt(ORCHESTRATOR, HTML_IN_MAIN_AND_CSHARP_IN_TEST_SUBFOLDERS, "violations")).isEqualTo(2);
Expand All @@ -86,10 +88,9 @@ public void givenTestHtmlAndCSharpCode_whenScannerForCliIsUsed_logsCSharpWarning
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

assertThat(result.getLogsLines(l -> l.contains("WARN")))
// ToDo revert back to containsExactlyInAnyOrder https://github.com/SonarSource/sonar-dotnet/issues/6714
.contains(
.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: Incremental PR analysis: Could not determine common base path, cache will not be computed. Consider setting 'sonar.projectBaseDir' property."
INCREMENTAL_PR_ANALYSIS_WARNING
);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}
Expand All @@ -102,14 +103,17 @@ public void givenTestHtmlCode_whenScannerForCliIsUsed_doesNotLogCsharpWarning()
.setProperty("sonar.cs.file.suffixes=", ".no_extension");
BuildResult result = ORCHESTRATOR.executeBuild(scanner);

// https://github.com/SonarSource/sonar-dotnet/issues/6714
//assertThat(result.getLogsLines(l -> l.contains("WARN"))).isEmpty();
assertThat(result.getLogsLines(l -> l.contains("WARN"))).isEmpty();
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}

private SonarScanner getSonarScanner(String projectKey, String projectDir) {
return SonarScanner.create(new File(projectDir))
File projectDirPath = new File(projectDir);
return SonarScanner.create(projectDirPath)
.setProjectKey(projectKey)
// This is set just to underline that the message regarding Incremental PR Analysis is confusing when the Scanner for .NET is not used.
// The Scanner for .NET under the hood sets the `sonar.pullrequest.cache.basepath` property (which is needed by the plugin) based on `sonar.projectBaseDir` property.
.setProperty("sonar.projectBaseDir", projectDirPath.getAbsolutePath())
.setSourceDirs(".");
}
}

0 comments on commit a783fbe

Please sign in to comment.