diff options
Diffstat (limited to 'sonar-scanner-engine/src/test')
5 files changed, 286 insertions, 253 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java index 9d05effedbf..40910a0f364 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ReportPublisherTest.java @@ -39,11 +39,11 @@ import org.sonar.api.platform.Server; import org.sonar.api.testfixtures.log.LogTester; import org.sonar.api.utils.MessageException; import org.sonar.api.utils.TempFolder; -import org.sonar.scanner.http.DefaultScannerWsClient; import org.sonar.scanner.bootstrap.GlobalAnalysisMode; import org.sonar.scanner.ci.CiConfiguration; import org.sonar.scanner.ci.DevOpsPlatformInfo; import org.sonar.scanner.fs.InputModuleHierarchy; +import org.sonar.scanner.http.DefaultScannerWsClient; import org.sonar.scanner.protocol.output.FileStructure; import org.sonar.scanner.protocol.output.ScannerReport; import org.sonar.scanner.scan.ScanProperties; @@ -146,13 +146,14 @@ public class ReportPublisherTest { public void dump_information_about_report_uploading() throws IOException { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://localhost\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://localhost/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://localhost + serverVersion=6.4 + dashboardUrl=https://localhost/dashboard?id=org.sonarsource.sonarqube%3Asonarqube + ceTaskId=TASK-123 + ceTaskUrl=https://localhost/api/ce/task?id=TASK-123 + """); } @Test @@ -185,13 +186,14 @@ public class ReportPublisherTest { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://publicserver/sonarqube\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://publicserver/sonarqube + serverVersion=6.4 + dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube + ceTaskId=TASK-123 + ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123 + """); } @Test @@ -204,13 +206,14 @@ public class ReportPublisherTest { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://publicserver/sonarqube\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://publicserver/sonarqube + serverVersion=6.4 + dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&branch=branch-6.7 + ceTaskId=TASK-123 + ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123 + """); } @Test @@ -225,13 +228,14 @@ public class ReportPublisherTest { underTest.prepareAndDumpMetadata("TASK-123"); - assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo( - "projectKey=org.sonarsource.sonarqube:sonarqube\n" + - "serverUrl=https://publicserver/sonarqube\n" + - "serverVersion=6.4\n" + - "dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&pullRequest=105\n" + - "ceTaskId=TASK-123\n" + - "ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123\n"); + assertThat(readFileToString(properties.metadataFilePath().toFile(), StandardCharsets.UTF_8)).isEqualTo(""" + projectKey=org.sonarsource.sonarqube:sonarqube + serverUrl=https://publicserver/sonarqube + serverVersion=6.4 + dashboardUrl=https://publicserver/sonarqube/dashboard?id=org.sonarsource.sonarqube%3Asonarqube&pullRequest=105 + ceTaskId=TASK-123 + ceTaskUrl=https://publicserver/sonarqube/api/ce/task?id=TASK-123 + """); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java index 078d91fb6d6..346f35af705 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/ChangedLinesComputerTest.java @@ -31,12 +31,14 @@ public class ChangedLinesComputerTest { @Test public void do_not_count_deleted_line() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -1 +0,0 @@\n" - + "-deleted line\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -1 +0,0 @@ + -deleted line + """; printDiff(example); assertThat(underTest.changedLines()).isEmpty(); @@ -44,12 +46,14 @@ public class ChangedLinesComputerTest { @Test public void count_single_added_line() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -0,0 +1 @@\n" - + "+added line\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -0,0 +1 @@ + +added line + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(1); @@ -57,14 +61,16 @@ public class ChangedLinesComputerTest { @Test public void count_multiple_added_lines() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -1 +1,3 @@\n" - + " unchanged line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -1 +1,3 @@ + unchanged line + +added line 1 + +added line 2 + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(2, 3); @@ -72,72 +78,78 @@ public class ChangedLinesComputerTest { @Test public void compute_from_multiple_hunks() throws IOException { - String example = "diff --git a/lao b/lao\n" - + "index 635ef2c..5af88a8 100644\n" - + "--- a/lao\n" - + "+++ b/lao\n" - + "@@ -1,7 +1,6 @@\n" - + "-The Way that can be told of is not the eternal Way;\n" - + "-The name that can be named is not the eternal name.\n" - + " The Nameless is the origin of Heaven and Earth;\n" - + "-The Named is the mother of all things.\n" - + "+The named is the mother of all things.\n" - + "+\n" - + " Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + " And let there always be being,\n" - + "@@ -9,3 +8,6 @@ And let there always be being,\n" - + " The two are the same,\n" - + " But after they are produced,\n" - + " they have different names.\n" - + "+They both may be called deep and profound.\n" - + "+Deeper and more profound,\n" - + "+The door of all subtleties!\n"; + String example = """ + diff --git a/lao b/lao + index 635ef2c..5af88a8 100644 + --- a/lao + +++ b/lao + @@ -1,7 +1,6 @@ + -The Way that can be told of is not the eternal Way; + -The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + -The Named is the mother of all things. + +The named is the mother of all things. + + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + @@ -9,3 +8,6 @@ And let there always be being, + The two are the same, + But after they are produced, + they have different names. + +They both may be called deep and profound. + +Deeper and more profound, + +The door of all subtleties! + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(2, 3, 11, 12, 13); } @Test public void compute_from_multiple_hunks_with_extra_header_lines() throws IOException { - String example = "diff --git a/lao b/lao\n" - + "new file mode 100644\n" - + "whatever " - + "other " - + "surprise header lines git might throw at us...\n" - + "index 635ef2c..5af88a8 100644\n" - + "--- a/lao\n" - + "+++ b/lao\n" - + "@@ -1,7 +1,6 @@\n" - + "-The Way that can be told of is not the eternal Way;\n" - + "-The name that can be named is not the eternal name.\n" - + " The Nameless is the origin of Heaven and Earth;\n" - + "-The Named is the mother of all things.\n" - + "+The named is the mother of all things.\n" - + "+\n" - + " Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + " And let there always be being,\n" - + "@@ -9,3 +8,6 @@ And let there always be being,\n" - + " The two are the same,\n" - + " But after they are produced,\n" - + " they have different names.\n" - + "+They both may be called deep and profound.\n" - + "+Deeper and more profound,\n" - + "+The door of all subtleties!\n"; + String example = """ + diff --git a/lao b/lao + new file mode 100644 + whatever \ + other \ + surprise header lines git might throw at us... + index 635ef2c..5af88a8 100644 + --- a/lao + +++ b/lao + @@ -1,7 +1,6 @@ + -The Way that can be told of is not the eternal Way; + -The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + -The Named is the mother of all things. + +The named is the mother of all things. + + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + @@ -9,3 +8,6 @@ And let there always be being, + The two are the same, + But after they are produced, + they have different names. + +They both may be called deep and profound. + +Deeper and more profound, + +The door of all subtleties! + """; printDiff(example); assertThat(underTest.changedLines()).containsExactly(2, 3, 11, 12, 13); } @Test public void throw_exception_invalid_start_line_format() throws IOException { - String example = "diff --git a/file-b1.xoo b/file-b1.xoo\n" - + "index 0000000..c2a9048\n" - + "--- a/foo\n" - + "+++ b/bar\n" - + "@@ -1 +x1,3 @@\n" - + " unchanged line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + diff --git a/file-b1.xoo b/file-b1.xoo + index 0000000..c2a9048 + --- a/foo + +++ b/bar + @@ -1 +x1,3 @@ + unchanged line + +added line 1 + +added line 2 + """; assertThatThrownBy(() -> printDiff(example)) .isInstanceOf(IllegalStateException.class); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java index f430cc9e50f..884253a7e4f 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java @@ -85,31 +85,34 @@ public class GitScmProviderTest { // Sample content for unified diffs // http://www.gnu.org/software/diffutils/manual/html_node/Example-Unified.html#Example-Unified - private static final String CONTENT_LAO = "The Way that can be told of is not the eternal Way;\n" - + "The name that can be named is not the eternal name.\n" - + "The Nameless is the origin of Heaven and Earth;\n" - + "The Named is the mother of all things.\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n"; - - private static final String CONTENT_TZU = "The Nameless is the origin of Heaven and Earth;\n" - + "The named is the mother of all things.\n" - + "\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n" - + "They both may be called deep and profound.\n" - + "Deeper and more profound,\n" - + "The door of all subtleties!"; + private static final String CONTENT_LAO = """ + The Way that can be told of is not the eternal Way; + The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + The Named is the mother of all things. + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + """; + + private static final String CONTENT_TZU = """ + The Nameless is the origin of Heaven and Earth; + The named is the mother of all things. + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + They both may be called deep and profound. + Deeper and more profound, + The door of all subtleties!"""; private static final String BRANCH_NAME = "branch"; private static final String TEST_DOC_LINK = "documentation link"; @@ -147,7 +150,8 @@ public class GitScmProviderTest { public void returnImplem() { JGitBlameCommand jblameCommand = new JGitBlameCommand(); NativeGitBlameCommand nativeBlameCommand = new NativeGitBlameCommand(System2.INSTANCE, new ProcessWrapperFactory()); - CompositeBlameCommand compositeBlameCommand = new CompositeBlameCommand(analysisWarnings, new PathResolver(), jblameCommand, nativeBlameCommand, new DefaultBlameStrategy(mock(Configuration.class))); + CompositeBlameCommand compositeBlameCommand = new CompositeBlameCommand(analysisWarnings, new PathResolver(), jblameCommand, nativeBlameCommand, + new DefaultBlameStrategy(mock(Configuration.class))); GitScmProvider gitScmProvider = new GitScmProvider(compositeBlameCommand, analysisWarnings, gitIgnoreCommand, system2, documentationLinkGenerator); assertThat(gitScmProvider.blameCommand()).isEqualTo(compositeBlameCommand); @@ -238,8 +242,7 @@ public class GitScmProviderTest { .extracting(ChangedFile::getAbsolutFilePath, ChangedFile::getOldRelativeFilePathReference) .containsExactlyInAnyOrder( tuple(newFileM1AbsolutPath, fileM1), - tuple(newFileM2AbsolutPath, fileM2) - ); + tuple(newFileM2AbsolutPath, fileM2)); } @Test @@ -454,8 +457,7 @@ public class GitScmProviderTest { Map<Path, ChangedFile> changedFiles = Map.of( newFileM1AbsolutPath, ChangedFile.of(newFileM1AbsolutPath, fileM1), - newFileM2AbsolutPath, ChangedFile.of(newFileM2AbsolutPath, fileM2) - ); + newFileM2AbsolutPath, ChangedFile.of(newFileM2AbsolutPath, fileM2)); Map<Path, Set<Integer>> changedLines = newScmProvider().branchChangedLinesWithFileMovementDetection("master", worktree.resolve("project1"), changedFiles); @@ -463,8 +465,7 @@ public class GitScmProviderTest { assertThat(changedLines) .containsOnly( entry(newFileM1AbsolutPath, Set.of(2)), - entry(newFileM2AbsolutPath, Set.of(1)) - ); + entry(newFileM2AbsolutPath, Set.of(1))); } @Test @@ -725,8 +726,7 @@ public class GitScmProviderTest { assertThat(provider.branchChangedLines("master", worktree, changedFiles)) .containsOnly( entry(worktree.resolve(f1), Collections.singleton(1)), - entry(worktree.resolve(f2), Collections.singleton(2)) - ); + entry(worktree.resolve(f2), Collections.singleton(2))); } @Test diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java index bf038962535..f55ba21efc7 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/ChangedLinesComputerTest.java @@ -45,12 +45,14 @@ public class ChangedLinesComputerTest { @Test public void do_not_count_deleted_line() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +0,0 @@\n" - + "-deleted line\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +0,0 @@ + -deleted line + """; printDiff(example); assertThat(underTest.changedLines()).isEmpty(); @@ -58,12 +60,14 @@ public class ChangedLinesComputerTest { @Test public void count_single_added_line() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -0,0 +1 @@\n" - + "+added line\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -0,0 +1 @@ + +added line + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), singleton(1))); @@ -71,14 +75,16 @@ public class ChangedLinesComputerTest { @Test public void count_multiple_added_lines() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), new HashSet<>(Arrays.asList(2, 3)))); @@ -86,14 +92,16 @@ public class ChangedLinesComputerTest { @Test public void handle_index_using_absolute_paths() throws IOException { - String example = "Index: /foo/sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: /foo/sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), new HashSet<>(Arrays.asList(2, 3)))); @@ -101,41 +109,45 @@ public class ChangedLinesComputerTest { @Test public void compute_from_multiple_hunks() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- lao\t2002-02-21 23:30:39.942229878 -0800\n" - + "+++ tzu\t2002-02-21 23:30:50.442260588 -0800\n" - + "@@ -1,7 +1,6 @@\n" - + "-The Way that can be told of is not the eternal Way;\n" - + "-The name that can be named is not the eternal name.\n" - + " The Nameless is the origin of Heaven and Earth;\n" - + "-The Named is the mother of all things.\n" - + "+The named is the mother of all things.\n" - + "+\n" - + " Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + " And let there always be being,\n" - + "@@ -9,3 +8,6 @@\n" - + " The two are the same,\n" - + " But after they are produced,\n" - + " they have different names.\n" - + "+They both may be called deep and profound.\n" - + "+Deeper and more profound,\n" - + "+The door of all subtleties!\n"; + String example = """ + Index: sample1 + =================================================================== + --- lao\t2002-02-21 23:30:39.942229878 -0800 + +++ tzu\t2002-02-21 23:30:50.442260588 -0800 + @@ -1,7 +1,6 @@ + -The Way that can be told of is not the eternal Way; + -The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + -The Named is the mother of all things. + +The named is the mother of all things. + + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + @@ -9,3 +8,6 @@ + The two are the same, + But after they are produced, + they have different names. + +They both may be called deep and profound. + +Deeper and more profound, + +The door of all subtleties! + """; printDiff(example); assertThat(underTest.changedLines()).isEqualTo(Collections.singletonMap(rootBaseDir.resolve("sample1"), new HashSet<>(Arrays.asList(2, 3, 11, 12, 13)))); } @Test(expected = IllegalStateException.class) public void crash_on_invalid_start_line_format() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +x1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +x1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); underTest.changedLines(); @@ -143,40 +155,42 @@ public class ChangedLinesComputerTest { @Test public void parse_diff_with_multiple_files() throws IOException { - String example = "Index: sample1\n" - + "===================================================================\n" - + "--- a/sample1\n" - + "+++ b/sample1\n" - + "@@ -1 +0,0 @@\n" - + "-deleted line\n" - + "Index: sample2\n" - + "===================================================================\n" - + "--- a/sample2\n" - + "+++ b/sample2\n" - + "@@ -0,0 +1 @@\n" - + "+added line\n" - + "Index: sample3\n" - + "===================================================================\n" - + "--- a/sample3\n" - + "+++ b/sample3\n" - + "@@ -0,0 +1,2 @@\n" - + "+added line 1\n" - + "+added line 2\n" - + "Index: sample3-not-included\n" - + "===================================================================\n" - + "--- a/sample3-not-included\n" - + "+++ b/sample3-not-included\n" - + "@@ -0,0 +1,2 @@\n" - + "+added line 1\n" - + "+added line 2\n" - + "Index: sample4\n" - + "===================================================================\n" - + "--- a/sample4\n" - + "+++ b/sample4\n" - + "@@ -1 +1,3 @@\n" - + " same line\n" - + "+added line 1\n" - + "+added line 2\n"; + String example = """ + Index: sample1 + =================================================================== + --- a/sample1 + +++ b/sample1 + @@ -1 +0,0 @@ + -deleted line + Index: sample2 + =================================================================== + --- a/sample2 + +++ b/sample2 + @@ -0,0 +1 @@ + +added line + Index: sample3 + =================================================================== + --- a/sample3 + +++ b/sample3 + @@ -0,0 +1,2 @@ + +added line 1 + +added line 2 + Index: sample3-not-included + =================================================================== + --- a/sample3-not-included + +++ b/sample3-not-included + @@ -0,0 +1,2 @@ + +added line 1 + +added line 2 + Index: sample4 + =================================================================== + --- a/sample4 + +++ b/sample4 + @@ -1 +1,3 @@ + same line + +added line 1 + +added line 2 + """; printDiff(example); Map<Path, Set<Integer>> expected = new HashMap<>(); diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java index f753e31bd8f..89dc17cf905 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/svn/SvnScmProviderTest.java @@ -51,31 +51,34 @@ public class SvnScmProviderTest { // Sample content for unified diffs // http://www.gnu.org/software/diffutils/manual/html_node/Example-Unified.html#Example-Unified - private static final String CONTENT_LAO = "The Way that can be told of is not the eternal Way;\n" - + "The name that can be named is not the eternal name.\n" - + "The Nameless is the origin of Heaven and Earth;\n" - + "The Named is the mother of all things.\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n"; - - private static final String CONTENT_TZU = "The Nameless is the origin of Heaven and Earth;\n" - + "The named is the mother of all things.\n" - + "\n" - + "Therefore let there always be non-being,\n" - + " so we may see their subtlety,\n" - + "And let there always be being,\n" - + " so we may see their outcome.\n" - + "The two are the same,\n" - + "But after they are produced,\n" - + " they have different names.\n" - + "They both may be called deep and profound.\n" - + "Deeper and more profound,\n" - + "The door of all subtleties!"; + private static final String CONTENT_LAO = """ + The Way that can be told of is not the eternal Way; + The name that can be named is not the eternal name. + The Nameless is the origin of Heaven and Earth; + The Named is the mother of all things. + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + """; + + private static final String CONTENT_TZU = """ + The Nameless is the origin of Heaven and Earth; + The named is the mother of all things. + + Therefore let there always be non-being, + so we may see their subtlety, + And let there always be being, + so we may see their outcome. + The two are the same, + But after they are produced, + they have different names. + They both may be called deep and profound. + Deeper and more profound, + The door of all subtleties!"""; @Rule public TemporaryFolder temp = new TemporaryFolder(); |