summaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorJulien HENRY <henryju@yahoo.fr>2018-03-12 19:15:42 +0100
committerJulien HENRY <julien.henry@sonarsource.com>2018-03-13 11:04:15 +0100
commit23e4b51cde3ed0dc76ca1d73aa6cc31715dd25d4 (patch)
treee8504c3f41db1c63d1c8c7533dbc376ad1fb3bcb /sonar-scanner-engine
parent2868b35e7d44b13c23a354e6c979e5060c25e792 (diff)
downloadsonarqube-23e4b51cde3ed0dc76ca1d73aa6cc31715dd25d4.tar.gz
sonarqube-23e4b51cde3ed0dc76ca1d73aa6cc31715dd25d4.zip
Fix tests on Windows
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java5
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java50
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java22
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java6
5 files changed, 45 insertions, 40 deletions
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
index 2c3310fe320..245702a0252 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/DefaultFileLinesContextTest.java
@@ -19,6 +19,7 @@
*/
package org.sonar.scanner;
+import java.io.File;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@@ -95,13 +96,13 @@ public class DefaultFileLinesContextTest {
@Test
public void validateLineGreaterThanZero() {
- thrown.expectMessage("Line number should be positive for file src/foo.php.");
+ thrown.expectMessage("Line number should be positive for file src" + File.separator + "foo.php.");
fileLineMeasures.setIntValue(HITS_METRIC_KEY, 0, 2);
}
@Test
public void validateLineLowerThanLineCount() {
- thrown.expectMessage("Line 4 is out of range for file src/foo.php. File has 3 lines");
+ thrown.expectMessage("Line 4 is out of range for file src" + File.separator + "foo.php. File has 3 lines");
fileLineMeasures.setIntValue(HITS_METRIC_KEY, 4, 2);
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
index e5d2d734b5d..045b89701d4 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/bootstrap/GlobalTempFolderProviderTest.java
@@ -36,6 +36,7 @@ import org.sonar.api.utils.System2;
import org.sonar.api.utils.TempFolder;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assume.assumeTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@@ -130,6 +131,7 @@ public class GlobalTempFolderProviderTest {
@Test
public void homeIsSymbolicLink() throws IOException {
+ assumeTrue(!System2.INSTANCE.isOsWindows());
File realSonarHome = temp.newFolder();
File symlink = temp.newFolder();
symlink.delete();
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
index 3901a8e9137..919881ecd6e 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/fs/FileSystemMediumTest.java
@@ -46,6 +46,7 @@ import org.sonar.xoo.XooPlugin;
import org.sonar.xoo.rule.XooRulesDefinition;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assume.assumeTrue;
public class FileSystemMediumTest {
@@ -311,7 +312,7 @@ public class FileSystemMediumTest {
.execute();
assertThat(logs.getAllAsString()).contains("1 file indexed");
- assertThat(logs.getAllAsString()).contains("'src/sample.unknown' indexed with language 'null'");
+ assertThat(logs.getAllAsString()).contains("'src" + File.separator + "sample.unknown' indexed with language 'null'");
assertThat(logs.getAllAsString()).contains("'src/sample.unknown' generated metadata");
DefaultInputFile inputFile = (DefaultInputFile) result.inputFile("src/sample.unknown");
assertThat(result.getReportComponent(inputFile.key())).isNotNull();
@@ -343,7 +344,7 @@ public class FileSystemMediumTest {
.build())
.execute();
- assertThat(logs.getAllAsString()).containsOnlyOnce("'src/myfile.binary' indexed with language 'null'");
+ assertThat(logs.getAllAsString()).containsOnlyOnce("'src" + File.separator + "myfile.binary' indexed with language 'null'");
assertThat(logs.getAllAsString()).doesNotContain("'src/myfile.binary' generating issue exclusions");
assertThat(logs.getAllAsString()).containsOnlyOnce("'src/sample.xoo' generating issue exclusions");
}
@@ -614,35 +615,33 @@ public class FileSystemMediumTest {
// SONAR-5330
@Test
public void scanProjectWithSourceSymlink() {
- if (!System2.INSTANCE.isOsWindows()) {
- File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink");
- TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
- .execute();
+ assumeTrue(!System2.INSTANCE.isOsWindows());
+ File projectDir = new File("src/test/resources/mediumtest/xoo/sample-with-symlink");
+ TaskResult result = tester
+ .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .execute();
- assertThat(result.inputFiles()).hasSize(3);
- // check that symlink was not resolved to target
- assertThat(result.inputFiles()).extractingResultOf("path").toString().startsWith(projectDir.toString());
- }
+ assertThat(result.inputFiles()).hasSize(3);
+ // check that symlink was not resolved to target
+ assertThat(result.inputFiles()).extractingResultOf("path").toString().startsWith(projectDir.toString());
}
// SONAR-6719
@Test
public void scanProjectWithWrongCase() {
- if (System2.INSTANCE.isOsWindows()) {
- File projectDir = new File("src/test/resources/mediumtest/xoo/sample");
- TaskResult result = tester
- .newScanTask(new File(projectDir, "sonar-project.properties"))
- .property("sonar.sources", "XOURCES")
- .property("sonar.tests", "TESTX")
- .execute();
+ assumeTrue(System2.INSTANCE.isOsWindows());
+ File projectDir = new File("src/test/resources/mediumtest/xoo/sample");
+ TaskResult result = tester
+ .newScanTask(new File(projectDir, "sonar-project.properties"))
+ .property("sonar.sources", "XOURCES")
+ .property("sonar.tests", "TESTX")
+ .execute();
- assertThat(result.inputFiles()).hasSize(3);
- assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly(
- "xources/hello/HelloJava.xoo",
- "xources/hello/helloscala.xoo",
- "testx/ClassOneTest.xoo");
- }
+ assertThat(result.inputFiles()).hasSize(3);
+ assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly(
+ "xources/hello/HelloJava.xoo",
+ "xources/hello/helloscala.xoo",
+ "testx/ClassOneTest.xoo");
}
@Test
@@ -740,7 +739,8 @@ public class FileSystemMediumTest {
assertThat(e)
.isInstanceOf(MessageException.class)
.hasMessage(
- "Language of file 'src/sample.xoo' can not be decided as the file matches patterns of both sonar.lang.patterns.xoo : **/*.xoo and sonar.lang.patterns.xoo2 : **/*.xoo");
+ "Language of file 'src" + File.separator
+ + "sample.xoo' can not be decided as the file matches patterns of both sonar.lang.patterns.xoo : **/*.xoo and sonar.lang.patterns.xoo2 : **/*.xoo");
}
// SONAR-9561
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
index ff938ba808e..eda36629c96 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/report/ComponentsPublisherTest.java
@@ -21,7 +21,6 @@ package org.sonar.scanner.report;
import java.io.File;
import java.io.IOException;
-import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Collections;
@@ -57,7 +56,9 @@ import org.sonar.scanner.scan.branch.BranchType;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.*;
+import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.newDefaultInputDir;
+import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.newDefaultInputFile;
+import static org.sonar.api.batch.fs.internal.TestInputFileBuilder.newDefaultInputModule;
public class ComponentsPublisherTest {
@Rule
@@ -573,11 +574,11 @@ public class ComponentsPublisherTest {
// file in dir in root
assertThat(reader.readComponent(dir1_file.batchId()).getPath()).isEqualTo("dir1/Foo.java");
- assertThat(reader.readComponent(dir1_file.batchId()).getProjectRelativePath()).isEqualTo("dir1/Foo.java");
+ assertThat(reader.readComponent(dir1_file.batchId()).getProjectRelativePath()).isEqualTo("dir1" + File.separator + "Foo.java");
// dir in dir in root
assertThat(reader.readComponent(dir1_dir1.batchId()).getPath()).isEqualTo("dir1/dir1");
- assertThat(reader.readComponent(dir1_dir1.batchId()).getProjectRelativePath()).isEqualTo("dir1/dir1");
+ assertThat(reader.readComponent(dir1_dir1.batchId()).getProjectRelativePath()).isEqualTo("dir1" + File.separator + "dir1");
// module in root
assertThat(reader.readComponent(mod1.batchId()).getPath()).isEqualTo("mod1");
@@ -585,26 +586,27 @@ public class ComponentsPublisherTest {
// dir in module in root
assertThat(reader.readComponent(mod1_dir2.batchId()).getPath()).isEqualTo("dir2");
- assertThat(reader.readComponent(mod1_dir2.batchId()).getProjectRelativePath()).isEqualTo("mod1/dir2");
+ assertThat(reader.readComponent(mod1_dir2.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "dir2");
// file in dir in module in root
assertThat(reader.readComponent(mod1_dir2_file.batchId()).getPath()).isEqualTo("dir2/Foo.java");
- assertThat(reader.readComponent(mod1_dir2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/dir2/Foo.java");
+ assertThat(reader.readComponent(mod1_dir2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "dir2" + File.separator + "Foo.java");
// module in module
assertThat(reader.readComponent(mod1_mod2.batchId()).getPath()).isEqualTo("mod2");
- assertThat(reader.readComponent(mod1_mod2.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2");
+ assertThat(reader.readComponent(mod1_mod2.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "mod2");
// file in module in module
assertThat(reader.readComponent(mod1_mod2_file.batchId()).getPath()).isEqualTo("Foo.java");
- assertThat(reader.readComponent(mod1_mod2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/Foo.java");
+ assertThat(reader.readComponent(mod1_mod2_file.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "mod2" + File.separator + "Foo.java");
// dir in module in module
assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getPath()).isEqualTo("dir");
- assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir");
+ assertThat(reader.readComponent(mod1_mod2_dir.batchId()).getProjectRelativePath()).isEqualTo("mod1" + File.separator + "mod2" + File.separator + "dir");
// file in dir in module in module
assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getPath()).isEqualTo("dir/Foo.java");
- assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getProjectRelativePath()).isEqualTo("mod1/mod2/dir/Foo.java");
+ assertThat(reader.readComponent(mod1_mod2_dir_file.batchId()).getProjectRelativePath())
+ .isEqualTo("mod1" + File.separator + "mod2" + File.separator + "dir" + File.separator + "Foo.java");
}
}
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java
index 11541a7bb5e..09f6740a9bb 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scm/DefaultBlameOutputTest.java
@@ -45,7 +45,7 @@ public class DefaultBlameOutputTest {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").build();
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("It was not expected to blame file src/main/java/Foo.java");
+ thrown.expectMessage("It was not expected to blame file " + file);
new DefaultBlameOutput(null, Arrays.<InputFile>asList(new TestInputFileBuilder("foo", "src/main/java/Foo2.java").build()))
.blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy")));
@@ -56,7 +56,7 @@ public class DefaultBlameOutputTest {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Blame date is null for file src/main/java/Foo.java at line 1");
+ thrown.expectMessage("Blame date is null for file " + file + " at line 1");
new DefaultBlameOutput(null, Arrays.<InputFile>asList(file))
.blameResult(file, Arrays.asList(new BlameLine().revision("1").author("guy")));
@@ -67,7 +67,7 @@ public class DefaultBlameOutputTest {
InputFile file = new TestInputFileBuilder("foo", "src/main/java/Foo.java").setLines(1).build();
thrown.expect(IllegalArgumentException.class);
- thrown.expectMessage("Blame revision is blank for file src/main/java/Foo.java at line 1");
+ thrown.expectMessage("Blame revision is blank for file " + file + " at line 1");
new DefaultBlameOutput(null, Arrays.<InputFile>asList(file))
.blameResult(file, Arrays.asList(new BlameLine().date(new Date()).author("guy")));