diff options
author | Klaudio Sinani <klaudio.sinani@sonarsource.com> | 2022-04-13 21:05:57 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-04-21 20:02:49 +0000 |
commit | b5e4dea47b838beafcad61ace24aea6a2d23ed1c (patch) | |
tree | e9ca3dc3588d571658bf7583fddbd6591f94ccfb /sonar-scanner-engine/src/test/java/org/sonar/scm | |
parent | 0599d3bbc85be6a96a18cd67ca84bc0c236c5f51 (diff) | |
download | sonarqube-b5e4dea47b838beafcad61ace24aea6a2d23ed1c.tar.gz sonarqube-b5e4dea47b838beafcad61ace24aea6a2d23ed1c.zip |
MMF-2692 Initial git blame command implementation
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scm')
-rw-r--r-- | sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java new file mode 100644 index 00000000000..2785ceeb7ad --- /dev/null +++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java @@ -0,0 +1,51 @@ +package org.sonar.scm.git; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.List; +import org.junit.Test; +import org.sonar.api.batch.scm.BlameLine; + +import static org.sonar.scm.git.GitBlameCommand.gitBlame; +import static org.sonar.scm.git.GitBlameCommand.gitClone; +import static org.sonar.scm.git.GitBlameCommand.gitCommit; +import static org.sonar.scm.git.GitBlameCommand.gitInit; +import static org.sonar.scm.git.GitBlameCommand.gitStage; +import static org.assertj.core.api.Assertions.assertThat; + +public class GitBlameCommandTest { + private static final String ORIGIN_URL = "https://github.com/klaussinani/taskbook.git"; + + @Test + public void testBlame() throws IOException, InterruptedException { + String tmpDirectory = Files.createTempDirectory("tmpDirectory").toFile().getAbsolutePath(); + Path directory = Paths.get(tmpDirectory); + gitClone(directory, ORIGIN_URL); + List<BlameLine> blameOutput = gitBlame(directory, "readme.md"); + assertThat(blameOutput.size()).isEqualTo(378); + } + + @Test + public void initAndAddFile() throws IOException, InterruptedException { + String tmpDirectory = Files.createTempDirectory("tmpDirectory").toFile().getAbsolutePath(); + Path directory = Paths.get(tmpDirectory); + Files.createDirectories(directory); + gitInit(directory); + Files.write(directory.resolve("bar.c"), new byte[0]); + gitStage(directory); + gitCommit(directory, "Add bar.c"); + } + + @Test + public void cloneAndAddFile() throws IOException, InterruptedException { + String tmpDirectory = Files.createTempDirectory("tmpDirectory").toFile().getAbsolutePath(); + Path directory = Paths.get(tmpDirectory); + gitClone(directory, ORIGIN_URL); + Files.write(directory.resolve("bar.c"), new byte[0]); + gitStage(directory); + gitCommit(directory, "Add bar.c"); + // gitPush(directory); // don't push + } +}
\ No newline at end of file |