aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test/java/org/sonar/scanner
diff options
context:
space:
mode:
authorPhilippe Perrin <philippe.perrin@sonarsource.com>2022-06-27 14:44:33 +0200
committersonartech <sonartech@sonarsource.com>2022-07-12 14:30:04 +0000
commitd1f2df5d7c34fb35d00053919752cf593a05d549 (patch)
tree3e6e5883f104645c0a1637beec81926bc93b559e /sonar-scanner-engine/src/test/java/org/sonar/scanner
parent201d5326c5e4471a1a77243cd2bd4ac71c9d4ada (diff)
downloadsonarqube-d1f2df5d7c34fb35d00053919752cf593a05d549.tar.gz
sonarqube-d1f2df5d7c34fb35d00053919752cf593a05d549.zip
SONAR-16554 fix scanner failing to create report for multi-modules projects with no code to analyse
Diffstat (limited to 'sonar-scanner-engine/src/test/java/org/sonar/scanner')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoriesInitializerTest.java34
1 files changed, 34 insertions, 0 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoriesInitializerTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoriesInitializerTest.java
index 180466e355c..81c308fabcb 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoriesInitializerTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/WorkDirectoriesInitializerTest.java
@@ -21,7 +21,9 @@ package org.sonar.scanner.scan;
import java.io.File;
import java.io.IOException;
+import java.nio.file.Path;
import java.util.Arrays;
+import java.util.List;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -114,4 +116,36 @@ public class WorkDirectoriesInitializerTest {
assertThat(moduleBWorkdir).isEmptyDirectory();
}
+ @Test
+ public void execute_on_hierarchy_should_clean_submodules_expect_submodule_with_same_work_directory_as_root() throws IOException {
+ DefaultInputModule moduleA = mock(DefaultInputModule.class);
+ DefaultInputModule moduleB = mock(DefaultInputModule.class);
+
+ when(hierarchy.children(root)).thenReturn(List.of(moduleA, moduleB));
+
+ File rootAndModuleAWorkdir = new File(rootWorkDir, "moduleA");
+ File moduleBWorkdir = new File(rootAndModuleAWorkdir, "../moduleB");
+
+ when(root.getWorkDir()).thenReturn(rootAndModuleAWorkdir.toPath());
+ when(moduleA.getWorkDir()).thenReturn(rootAndModuleAWorkdir.toPath());
+ when(moduleB.getWorkDir()).thenReturn(moduleBWorkdir.toPath());
+
+ rootAndModuleAWorkdir.mkdir();
+ createFilesToClean(rootAndModuleAWorkdir);
+ moduleBWorkdir.mkdir();
+
+ new File(rootAndModuleAWorkdir, "fooA.txt").createNewFile();
+ new File(moduleBWorkdir, "fooB.txt").createNewFile();
+
+ initializer.execute(hierarchy);
+
+ assertThat(rootWorkDir).exists();
+ assertThat(lock).exists();
+ assertThat(rootAndModuleAWorkdir).exists();
+ assertThat(rootAndModuleAWorkdir.list()).containsOnly(DirectoryLock.LOCK_FILE_NAME, "fooA.txt", "foo", "foo.txt");
+ assertThat(moduleBWorkdir)
+ .exists()
+ .isEmptyDirectory();
+ }
+
}