|
|
@@ -19,9 +19,16 @@ |
|
|
|
*/ |
|
|
|
package org.sonar.batch.mediumtest.highlighting; |
|
|
|
|
|
|
|
import org.hamcrest.TypeSafeMatcher; |
|
|
|
import org.hamcrest.BaseMatcher; |
|
|
|
import org.hamcrest.Description; |
|
|
|
import org.hamcrest.Matcher; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
import com.google.common.collect.ImmutableMap; |
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.IOException; |
|
|
|
|
|
|
|
import org.apache.commons.io.FileUtils; |
|
|
|
import org.apache.commons.lang.StringUtils; |
|
|
|
import org.junit.After; |
|
|
@@ -34,7 +41,6 @@ import org.sonar.api.batch.sensor.highlighting.TypeOfText; |
|
|
|
import org.sonar.batch.mediumtest.BatchMediumTester; |
|
|
|
import org.sonar.batch.mediumtest.TaskResult; |
|
|
|
import org.sonar.xoo.XooPlugin; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
|
|
|
|
public class HighlightingMediumTest { |
|
|
@@ -42,6 +48,9 @@ public class HighlightingMediumTest { |
|
|
|
@Rule |
|
|
|
public TemporaryFolder temp = new TemporaryFolder(); |
|
|
|
|
|
|
|
@Rule |
|
|
|
public ExpectedException exception = ExpectedException.none(); |
|
|
|
|
|
|
|
public BatchMediumTester tester = BatchMediumTester.builder() |
|
|
|
.registerPlugin("xoo", new XooPlugin()) |
|
|
|
.addDefaultQProfile("xoo", "Sonar Way") |
|
|
@@ -87,6 +96,44 @@ public class HighlightingMediumTest { |
|
|
|
assertThat(result.highlightingTypeFor(file, 2, 8)).isEmpty(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void computeInvalidOffsets() throws IOException { |
|
|
|
|
|
|
|
File baseDir = temp.newFolder(); |
|
|
|
File srcDir = new File(baseDir, "src"); |
|
|
|
srcDir.mkdir(); |
|
|
|
|
|
|
|
File xooFile = new File(srcDir, "sample.xoo"); |
|
|
|
File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting"); |
|
|
|
FileUtils.write(xooFile, "Sample xoo\ncontent plop"); |
|
|
|
FileUtils.write(xoohighlightingFile, "0:10:s\n18:18:k"); |
|
|
|
|
|
|
|
exception.expect(IllegalStateException.class); |
|
|
|
exception.expectMessage("Error processing line 2"); |
|
|
|
exception.expectCause(new TypeSafeMatcher<IllegalArgumentException>() { |
|
|
|
@Override |
|
|
|
public void describeTo(Description description) { |
|
|
|
description.appendText("Invalid cause"); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected boolean matchesSafely(IllegalArgumentException e) { |
|
|
|
return e.getMessage().contains("Unable to highlight file"); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
TaskResult result = tester.newTask() |
|
|
|
.properties(ImmutableMap.<String, String>builder() |
|
|
|
.put("sonar.projectBaseDir", baseDir.getAbsolutePath()) |
|
|
|
.put("sonar.projectKey", "com.foo.project") |
|
|
|
.put("sonar.projectName", "Foo Project") |
|
|
|
.put("sonar.projectVersion", "1.0-SNAPSHOT") |
|
|
|
.put("sonar.projectDescription", "Description of Foo Project") |
|
|
|
.put("sonar.sources", "src") |
|
|
|
.build()) |
|
|
|
.start(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void computeSyntaxHighlightingOnBigFile() throws IOException { |
|
|
|
|