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

SQ Plugin: Remove usages of deprecated Build.setProfile in the integration tests #9563

Merged
merged 2 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,6 @@ private BuildResult analyzeCoverageTestProject(String projectName, boolean analy
.setParam("value", "" + analyzeGenerated)
.execute();

return Tests.analyzeProject(temp, projectName, null, keyValues);
return Tests.analyzeProject(temp, projectName, keyValues);
}
}
12 changes: 6 additions & 6 deletions its/src/test/java/com/sonar/it/csharp/CoverageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void open_cover_on_MultipleProjects_with_UnixWildcardPattern() throws Exception

@Test
void open_cover_with_deterministic_source_paths() throws Exception {
BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "no_rule", "sonar.cs.opencover.reportsPaths", "opencover.xml");
BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "sonar.cs.opencover.reportsPaths", "opencover.xml");

assertThat(buildResult.getLogs()).contains(
"Sensor C# Tests Coverage Report Import",
Expand Down Expand Up @@ -169,7 +169,7 @@ void visual_studio_on_MultipleProjects() throws Exception {

@Test
void visual_studio_with_deterministic_source_paths() throws Exception {
BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "no_rule", "sonar.cs.vscoveragexml.reportsPaths", "VisualStudio.coveragexml");
BuildResult buildResult = Tests.analyzeProject(temp, "CoverageWithDeterministicSourcePaths", "sonar.cs.vscoveragexml.reportsPaths", "VisualStudio.coveragexml");

assertThat(buildResult.getLogs()).contains(
"Sensor C# Tests Coverage Report Import",
Expand All @@ -184,7 +184,7 @@ void visual_studio_with_deterministic_source_paths() throws Exception {

@Test
void no_coverage_on_tests() throws Exception {
BuildResult buildResult = Tests.analyzeProject(temp, "NoCoverageOnTests", "no_rule", "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml");
BuildResult buildResult = Tests.analyzeProject(temp, "NoCoverageOnTests", "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml");

assertThat(buildResult.getLogs()).contains(
"Sensor C# Tests Coverage Report Import",
Expand All @@ -209,15 +209,15 @@ void should_support_wildcard_patterns() throws Exception {
}

private BuildResult analyzeCoverageTestProject(String... keyValues) throws IOException {
return Tests.analyzeProject(temp, "CoverageTest", "no_rule", keyValues);
return Tests.analyzeProject(temp, "CoverageTest", keyValues);
}

private BuildResult analyzeMultipleProjectsTestProject(String coverageProperty, String coverageFileName) throws IOException {
return Tests.analyzeProject(temp, "CoverageTest.MultipleProjects", "no_rule", coverageProperty, coverageFileName);
return Tests.analyzeProject(temp, "CoverageTest.MultipleProjects", coverageProperty, coverageFileName);
}

private BuildResult analyzeMultipleFrameworksTestProject(String coverageProperty, String coverageFileNames) throws IOException {
return Tests.analyzeProject(temp, "CoverageTest.MultipleFrameworks", "no_rule", coverageProperty, coverageFileNames);
return Tests.analyzeProject(temp, "CoverageTest.MultipleFrameworks", coverageProperty, coverageFileNames);
}

private void assertCoverageMetrics(String componentKey, int linesToCover, int uncoveredLines, int conditionsToCover, int uncoveredConditions) {
Expand Down
6 changes: 3 additions & 3 deletions its/src/test/java/com/sonar/it/csharp/ExternalIssuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void external_issues_imported_by_default_for_test_project() throws Exception {
void external_issues_are_ignored() throws Exception {
var projectKey = MAIN_PROJECT_DIR + "_ignored";
var componentId = projectKey + PROGRAM_COMPONENT_ID;
Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, null,
Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR,
"sonar.cs.roslyn.ignoreIssues", "true");

assertThat(getComponent(componentId)).isNotNull();
Expand All @@ -96,7 +96,7 @@ void external_issues_are_ignored() throws Exception {
void external_issues_categories_multiple_categories_mapped() throws Exception {
var projectKey = MAIN_PROJECT_DIR + "_categories_mapped";
var componentId = projectKey + PROGRAM_COMPONENT_ID;
Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, null,
Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR,
// notice that bugCategories has a list of 2 external categories
"sonar.cs.roslyn.bugCategories", "StyleCop.CSharp.DocumentationRules,StyleCop.CSharp.MaintainabilityRules",
"sonar.cs.roslyn.vulnerabilityCategories", "StyleCop.CSharp.OrderingRules");
Expand Down Expand Up @@ -124,7 +124,7 @@ void external_issues_categories_multiple_categories_mapped() throws Exception {
void external_issues_all_three_properties() throws Exception {
var projectKey = MAIN_PROJECT_DIR + "_three_properties";
var componentId = projectKey + PROGRAM_COMPONENT_ID;
Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR, null,
Tests.analyzeProject(projectKey, temp, MAIN_PROJECT_DIR,
"sonar.cs.roslyn.codeSmellCategories", "StyleCop.CSharp.DocumentationRules",
"sonar.cs.roslyn.bugCategories", "StyleCop.CSharp.MaintainabilityRules",
"sonar.cs.roslyn.vulnerabilityCategories", "StyleCop.CSharp.OrderingRules");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class IncrementalAnalysisTest {
@Test
void incrementalPrAnalysis_NoCache_FullAnalysisDone() throws IOException {
var projectKey = PROJECT_DIR + "_noCache_fullAnalysis";
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch", "sonar.analysisCache.enabled", "false");
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch", "sonar.analysisCache.enabled", "false");
Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR);
File withChangesPath = projectDir.resolve(PROJECT_DIR + "\\WithChanges.cs").toFile();
addIssue(withChangesPath);
Expand All @@ -73,7 +73,7 @@ void incrementalPrAnalysis_NoCache_FullAnalysisDone() throws IOException {
@Test
void incrementalPrAnalysis_cacheAvailableNoChanges_nothingReported() throws IOException {
var projectKey = PROJECT_DIR + "cacheAvailable_noChanges";
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch");
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch");
Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR);

BeginAndEndStepResults results = executeAnalysisForPRBranch(projectKey, projectDir, "");
Expand All @@ -90,7 +90,7 @@ void incrementalPrAnalysis_cacheAvailableNoChanges_nothingReported() throws IOEx
@Test
void incrementalPrAnalysis_cacheAvailableChangesDone_issuesReportedForChangedFiles() throws IOException {
var projectKey = PROJECT_DIR + "cacheAvailable_withChanges";
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch");
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch");
Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR);
File unchanged1Path = projectDir.resolve(PROJECT_DIR + "\\Unchanged1.cs").toFile();
File unchanged2Path = projectDir.resolve(PROJECT_DIR + "\\Unchanged2.cs").toFile();
Expand Down Expand Up @@ -124,7 +124,7 @@ void incrementalPrAnalysis_cacheAvailableChangesDone_issuesReportedForChangedFil
@Test
void incrementalPrAnalysis_cacheAvailableProjectBaseDirChanged_everythingIsReanalyzed() throws IOException {
var projectKey = PROJECT_DIR + "cacheAvailable_baseDirChanged";
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, null, "sonar.branch.name", "base-branch");
Tests.analyzeProject(projectKey, temp, PROJECT_DIR, "sonar.branch.name", "base-branch");
Path projectDir = TestUtils.projectDir(temp, PROJECT_DIR);
File withChangesPath = projectDir.resolve(PROJECT_DIR + "\\WithChanges.cs").toFile();
addIssue(withChangesPath);
Expand Down Expand Up @@ -153,7 +153,7 @@ void incrementalPrAnalysis_cacheAvailableProjectBaseDirChanged_everythingIsReana
@Test
void incrementalPrAnalysis_cacheAvailableDuplicationIntroduced_duplicationReportedForChangedFile() throws IOException {
String projectKey = "IncrementalPRAnalysisDuplication";
Tests.analyzeProject(temp, projectKey, null, "sonar.branch.name", "base-branch");
Tests.analyzeProject(temp, projectKey, "sonar.branch.name", "base-branch");
Path projectDir = TestUtils.projectDir(temp, projectKey);
File originalFile = projectDir.resolve("IncrementalPRAnalysisDuplication\\OriginalClass.cs").toFile();
File duplicatedFile = projectDir.resolve("IncrementalPRAnalysisDuplication\\CopyClass.cs").toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public class MetricsIncludeHeaderCommentTest {
public static void beforeAll() throws Exception {
Path projectDir = TestUtils.projectDir(temp, "MetricsTest");
ScannerForMSBuild beginStep = TestUtils.createBeginStep(PROJECT_KEY, projectDir)
.setProfile("no_rule")
// Without that, the MetricsTest project is considered as a Test project :)
.setProperty("sonar.msbuild.testProjectPattern", "noTests");

Expand Down
2 changes: 1 addition & 1 deletion its/src/test/java/com/sonar/it/csharp/MetricsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public class MetricsTest {
@BeforeAll
public static void beforeAll() throws Exception {
// Without setting the testProjectPattern, the MetricsTest project is considered as a Test project :)
Tests.analyzeProject(temp, PROJECT, "no_rule", "sonar.msbuild.testProjectPattern", "noTests");
Tests.analyzeProject(temp, PROJECT, "sonar.msbuild.testProjectPattern", "noTests");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion its/src/test/java/com/sonar/it/csharp/NoSonarTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class NoSonarTest {

@BeforeAll
public static void init() throws Exception {
buildResult = Tests.analyzeProject(temp, PROJECT, "class_name");
buildResult = Tests.analyzeProject(temp, PROJECT);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class RazorMetricsTest {

@BeforeAll
public static void beforeAll() throws Exception {
Tests.analyzeProject(temp, PROJECT, "no_rule");
Tests.analyzeProject(temp, PROJECT);
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion its/src/test/java/com/sonar/it/csharp/SharedFilesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class SharedFilesTest {

@Test
void should_analyze_shared_files() throws Exception {
BuildResult buildResult = Tests.analyzeProject(temp, "SharedFilesTest", null, "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml");
BuildResult buildResult = Tests.analyzeProject(temp, "SharedFilesTest", "sonar.cs.vscoveragexml.reportsPaths", "reports/visualstudio.coveragexml");

assertThat(getComponent("SharedFilesTest:Class1.cs")).isNotNull();
assertThat(getComponent("SharedFilesTest:ConsoleApp1/Program1.cs")).isNotNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void should_supportS_symbolic_links() throws Exception {
try {
Files.createSymbolicLink(link, target);

var buildResult = Tests.analyzeProjectPath("SymbolicLinks", projectFullPath, null, "sonar.verbose", "true");
var buildResult = Tests.analyzeProjectPath("SymbolicLinks", projectFullPath, "sonar.verbose", "true");

assertThat(buildResult.isSuccess()).isTrue();

Expand Down
2 changes: 1 addition & 1 deletion its/src/test/java/com/sonar/it/csharp/TestProjectTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void issuesAreImportedForTestProject() {

@Test
void with_html_and_csharp_code_explicitly_marked_as_test_should_not_populate_metrics() throws Exception {
BuildResult buildResult = Tests.analyzeProject(temp, EXPLICITLY_MARKED_AS_TEST, "no_rule");
BuildResult buildResult = Tests.analyzeProject(temp, EXPLICITLY_MARKED_AS_TEST);

assertThat(Tests.getComponent("HtmlCSharpExplicitlyMarkedAsTest:Foo.cs")).isNotNull();
assertThat(getMeasureAsInt(EXPLICITLY_MARKED_AS_TEST, "files")).isNull();
Expand Down
18 changes: 6 additions & 12 deletions its/src/test/java/com/sonar/it/csharp/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,20 @@ public void afterAll(ExtensionContext extensionContext) throws Exception {
public static BuildResult analyzeProject(Path temp, String projectDir) throws IOException {
return analyzeProject(projectDir, temp, projectDir);
}

public static BuildResult analyzeProject(String projectKey, Path temp, String projectDir) throws IOException {
return analyzeProject(projectKey, temp, projectDir, null);
}

public static BuildResult analyzeProject(Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException {
return analyzeProject(projectDir, temp, projectDir, profileKey, keyValues);

public static BuildResult analyzeProject(Path temp, String projectDir, String... keyValues) throws IOException {
return analyzeProject(projectDir, temp, projectDir, keyValues);
}

public static BuildResult analyzeProject(String projectKey, Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException {
public static BuildResult analyzeProject(String projectKey, Path temp, String projectDir, String... keyValues) throws IOException {
Path projectFullPath = TestUtils.projectDir(temp, projectDir);

return analyzeProjectPath(projectKey, projectFullPath, profileKey, keyValues);
return analyzeProjectPath(projectKey, projectFullPath, keyValues);
}

public static BuildResult analyzeProjectPath(String projectKey, Path projectFullPath, @Nullable String profileKey, String... keyValues) {
public static BuildResult analyzeProjectPath(String projectKey, Path projectFullPath, String... keyValues) {
ScannerForMSBuild beginStep = TestUtils.createBeginStep(projectKey, projectFullPath)
.setProfile(profileKey)
.setProperties(keyValues);

ORCHESTRATOR.executeBuild(beginStep);
TestUtils.runBuild(projectFullPath);
return ORCHESTRATOR.executeBuild(TestUtils.createEndStep(projectFullPath));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,6 @@ void should_support_wildcard_patterns() throws Exception {
}

private BuildResult analyzeTestProject(String... keyValues) throws IOException {
return Tests.analyzeProject(temp, PROJECT, "no_rule", keyValues);
return Tests.analyzeProject(temp, PROJECT, keyValues);
}
}
2 changes: 1 addition & 1 deletion its/src/test/java/com/sonar/it/shared/CoverageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ public void mix_only_vbnet_vscoverage() throws IOException {
}

private BuildResult analyzeCoverageMixProject(String... keyValues) throws IOException {
return Tests.analyzeProject(temp, "CSharpVBNetCoverage", null, keyValues);
return Tests.analyzeProject(temp, "CSharpVBNetCoverage", keyValues);
}
}
7 changes: 1 addition & 6 deletions its/src/test/java/com/sonar/it/shared/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,9 @@ public void afterAll(ExtensionContext extensionContext) throws Exception {
ORCHESTRATOR_STATE.stopOnce();
}

public static BuildResult analyzeProject(Path temp, String projectDir) throws IOException {
return analyzeProject(temp, projectDir, null);
}

public static BuildResult analyzeProject(Path temp, String projectDir, @Nullable String profileKey, String... keyValues) throws IOException {
public static BuildResult analyzeProject(Path temp, String projectDir, String... keyValues) throws IOException {
Path projectFullPath = TestUtils.projectDir(temp, projectDir);
ScannerForMSBuild beginStep = TestUtils.createBeginStep(projectDir, projectFullPath)
.setProfile(profileKey)
.setProperties(keyValues);
ORCHESTRATOR.executeBuild(beginStep);
TestUtils.runBuild(projectFullPath);
Expand Down
12 changes: 6 additions & 6 deletions its/src/test/java/com/sonar/it/vbnet/AutoGeneratedTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@
import static org.assertj.core.api.Assertions.assertThat;

@ExtendWith(Tests.class)
public class AutoGeneratedTest {
class AutoGeneratedTest {

@TempDir
private static Path temp;

private final String PROJECT_NAME = "VbAutoGeneratedFiles";

@Test
public void autogenerated_code_with_analyzeGenerated_false() throws Exception {
void autogenerated_code_with_analyzeGenerated_false() throws Exception {
analyzeCoverageTestProject(PROJECT_NAME, false);

// only MyModule.vb is scanned
Expand All @@ -50,7 +50,7 @@ public void autogenerated_code_with_analyzeGenerated_false() throws Exception {
}

@Test
public void autogenerated_code_with_analyzeGenerated_true() throws Exception {
void autogenerated_code_with_analyzeGenerated_true() throws Exception {
analyzeCoverageTestProject(PROJECT_NAME, true);

assertThat(getMeasureAsInt(PROJECT_NAME, "files")).isEqualTo(6);
Expand All @@ -59,7 +59,7 @@ public void autogenerated_code_with_analyzeGenerated_true() throws Exception {
}

@Test
public void autogenerated_files_are_logged() throws Exception {
void autogenerated_files_are_logged() throws Exception {
BuildResult result = analyzeCoverageTestProject(PROJECT_NAME, false, "sonar.verbose", "true");

assertThat(result.getLogsLines(x -> x.contains("was recognized as generated"))).hasSize(7);
Expand All @@ -74,9 +74,9 @@ private BuildResult analyzeCoverageTestProject(String projectName, boolean analy
.setAdminCredentials()
.setMethod(HttpMethod.POST)
.setParam("key", "sonar.vbnet.analyzeGeneratedCode")
.setParam("value", "" + analyzeGenerated)
.setParam("value", String.valueOf(analyzeGenerated))
.execute();

return Tests.analyzeProject(temp, projectName, null, keyValues);
return Tests.analyzeProject(temp, projectName, keyValues);
}
}
Loading
Loading