Skip to content

Commit

Permalink
Assert sonar.token warning
Browse files Browse the repository at this point in the history
  • Loading branch information
mary-georgiou-sonarsource committed Mar 20, 2023
1 parent 4db4ba1 commit c024960
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 23 deletions.
10 changes: 8 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,10 @@ 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");
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");
}

@Test
Expand All @@ -65,6 +68,9 @@ 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.");
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."
);
}
}
25 changes: 13 additions & 12 deletions its/src/test/java/com/sonar/it/csharp/TestProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,13 @@ public void projectIsAnalyzed() {

@Test
public void logsContainInfoAndWarning() {
assertThat(buildResult.getLogs()).contains(
"SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"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."
assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild C# project: 1 TEST project.");
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.",
"WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"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"
);
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
}

@Test
Expand Down Expand Up @@ -103,11 +102,13 @@ public void with_html_and_csharp_code_explicitly_marked_as_test_should_not_popul
assertThat(getMeasureAsInt(EXPLICITLY_MARKED_AS_TEST, "ncloc")).isNull();

assertThat(buildResult.getLogsLines(l -> l.contains("WARN")))
.contains("WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"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");
.contains(
"WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"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",
"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."
);
assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild C# project: 1 TEST project.");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "C#");
}
}
10 changes: 5 additions & 5 deletions its/src/test/java/com/sonar/it/shared/ScannerCliTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ public void givenRazorPagesMainCode_whenScannerForCliIsUsed_logsCSharpWarning()
.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",
"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.",
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);
}

@Test
Expand All @@ -73,11 +73,11 @@ public void givenMainHtmlCodeAndTestCSharpCode_whenScannerForCliIsUsed_logsCShar
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: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
INCREMENTAL_PR_ANALYSIS_WARNING
);
// The HTML plugin works
assertThat(TestUtils.getMeasureAsInt(ORCHESTRATOR, HTML_IN_MAIN_AND_CSHARP_IN_TEST_SUBFOLDERS, "violations")).isEqualTo(2);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}

@Test
Expand All @@ -90,9 +90,9 @@ public void givenTestHtmlAndCSharpCode_whenScannerForCliIsUsed_logsCSharpWarning
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: The properties 'sonar.login' and 'sonar.password' are deprecated. They will not be supported in the future. Please instead use the 'sonar.token' parameter.",
INCREMENTAL_PR_ANALYSIS_WARNING
);
TestUtils.verifyNoGuiWarnings(ORCHESTRATOR, result);
}

@Test
Expand All @@ -103,8 +103,8 @@ 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);
assertThat(result.getLogsLines(l -> l.contains("WARN")))
.containsExactly("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.");
}

private SonarScanner getSonarScanner(String projectKey, String projectDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,13 @@ public void logsContainInfo() {
.contains("WARN: SonarScanner for .NET detected only TEST files and no MAIN files for C# in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"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");
"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",
"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."
);

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);
}

@Test
Expand Down
5 changes: 3 additions & 2 deletions its/src/test/java/com/sonar/it/vbnet/TestProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ public void with_vbnet_only_test_should_not_populate_metrics() throws Exception
.contains("WARN: SonarScanner for .NET detected only TEST files and no MAIN files for VB.NET in the current solution. " +
"Only TEST-code related results will be imported to your SonarQube/SonarCloud project. " +
"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");
"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",
"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."
);

assertThat(buildResult.getLogsLines(l -> l.contains("INFO"))).contains("INFO: Found 1 MSBuild VB.NET project: 1 TEST project.");
TestUtils.verifyGuiTestOnlyProjectAnalysisWarning(ORCHESTRATOR, buildResult, "VB.NET");
}

@Test
Expand Down

0 comments on commit c024960

Please sign in to comment.