Search in sources :

Example 1 with TestClientInputFile

use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.

the class InputFileBuilderTest method testCreateError.

@Test
public void testCreateError() throws IOException {
    when(langDetection.language(any(InputFile.class))).thenReturn("java");
    ClientInputFile file = new TestClientInputFile(Paths.get("INVALID"), "INVALID", true, StandardCharsets.ISO_8859_1);
    InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
    exception.expect(IllegalStateException.class);
    exception.expectMessage("Failed to open a stream on file");
    builder.create(file);
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) InputFile(org.sonar.api.batch.fs.InputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Example 2 with TestClientInputFile

use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.

the class LoggedErrorHandlerTest method setUp.

@Before
public void setUp() {
    file1 = new TestClientInputFile(path1, "my/file1", false, StandardCharsets.UTF_8);
    file2 = new TestClientInputFile(path2, "my/file2", false, StandardCharsets.UTF_8);
    handler = new LoggedErrorHandler(Arrays.asList(file1, file2));
}
Also used : TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Before(org.junit.Before)

Example 3 with TestClientInputFile

use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method useRelativePathToEvaluatePathPatterns.

// SLCORE-162
@Test
public void useRelativePathToEvaluatePathPatterns() throws Exception {
    // Temporary file doesn't have the correct file suffix
    final File file = new File(baseDir, "foo.tmp");
    FileUtils.write(file, "def my_function(name):\n" + "    print \"Hello\"\n" + "    print \"world!\" # NOSONAR\n" + "\n", StandardCharsets.UTF_8);
    ClientInputFile inputFile = new TestClientInputFile(file.toPath(), "foo.py", false, StandardCharsets.UTF_8, null);
    final List<Issue> issues = new ArrayList<>();
    sonarlint.analyze(new StandaloneAnalysisConfiguration(baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.of()), issue -> issues.add(issue), null, null);
    assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple("python:PrintStatementUsage", 2, inputFile.getPath()));
}
Also used : Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) ArrayList(java.util.ArrayList) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) File(java.io.File) Test(org.junit.Test)

Example 4 with TestClientInputFile

use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.

the class StandaloneIssueMediumTest method prepareInputFile.

private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest, Charset encoding, @Nullable String language) throws IOException {
    final File file = new File(baseDir, relativePath);
    FileUtils.write(file, content, encoding);
    ClientInputFile inputFile = new TestClientInputFile(file.toPath(), relativePath, isTest, encoding, language);
    return inputFile;
}
Also used : ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) File(java.io.File)

Example 5 with TestClientInputFile

use of org.sonarsource.sonarlint.core.TestClientInputFile in project sonarlint-core by SonarSource.

the class InputFileBuilderTest method testCreate.

@Test
public void testCreate() throws IOException {
    when(langDetection.language(any(InputFile.class))).thenReturn("java");
    Path path = temp.getRoot().toPath().resolve("file");
    Files.write(path, "test".getBytes(StandardCharsets.ISO_8859_1));
    ClientInputFile file = new TestClientInputFile(path, "file", true, StandardCharsets.ISO_8859_1);
    InputFileBuilder builder = new InputFileBuilder(langDetection, metadata);
    SonarLintInputFile inputFile = builder.create(file);
    assertThat(inputFile.type()).isEqualTo(InputFile.Type.TEST);
    assertThat(inputFile.file()).isEqualTo(path.toFile());
    assertThat(inputFile.absolutePath()).isEqualTo(toSonarQubePath(path.toString()));
    assertThat(inputFile.language()).isEqualTo("java");
    assertThat(inputFile.key()).isEqualTo(toSonarQubePath(path.toAbsolutePath().toString()));
    assertThat(inputFile.lines()).isEqualTo(1);
    assertThat(builder.langDetection()).isEqualTo(langDetection);
}
Also used : FileUtils.toSonarQubePath(org.sonarsource.sonarlint.core.client.api.util.FileUtils.toSonarQubePath) Path(java.nio.file.Path) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) InputFile(org.sonar.api.batch.fs.InputFile) ClientInputFile(org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile) TestClientInputFile(org.sonarsource.sonarlint.core.TestClientInputFile) Test(org.junit.Test)

Aggregations

TestClientInputFile (org.sonarsource.sonarlint.core.TestClientInputFile)7 ClientInputFile (org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile)5 Test (org.junit.Test)4 File (java.io.File)2 Path (java.nio.file.Path)2 Before (org.junit.Before)2 InputFile (org.sonar.api.batch.fs.InputFile)2 FileUtils.toSonarQubePath (org.sonarsource.sonarlint.core.client.api.util.FileUtils.toSonarQubePath)2 ArrayList (java.util.ArrayList)1 Issue (org.sonarsource.sonarlint.core.client.api.common.analysis.Issue)1 StandaloneAnalysisConfiguration (org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration)1