use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueMediumTest method prepareInputFile.
private ClientInputFile prepareInputFile(String relativePath, String content, final boolean isTest) throws IOException {
final File file = new File(baseDir, relativePath);
FileUtils.write(file, content);
ClientInputFile inputFile = TestUtils.createInputFile(file.toPath(), relativePath, isTest);
return inputFile;
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueMediumTest method emptyQPJava.
@Test
public void emptyQPJava() throws IOException {
ClientInputFile inputFile = prepareJavaInputFile();
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new ConnectedAnalysisConfiguration("test-project", baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), new StoreIssueListener(issues), null, null);
assertThat(issues).isEmpty();
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueMediumTest method simpleJavaTestUnbinded.
@Test
public void simpleJavaTestUnbinded() throws Exception {
ClientInputFile inputFile = prepareJavaTestInputFile();
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), new StoreIssueListener(issues), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path", "severity").containsOnly(tuple("squid:S2187", 1, inputFile.getPath(), "MAJOR"));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueMediumTest method simpleJavaScriptUnbinded.
@Test
public void simpleJavaScriptUnbinded() throws Exception {
String ruleKey = "javascript:UnusedVariable";
RuleDetails ruleDetails = sonarlint.getRuleDetails(ruleKey);
assertThat(ruleDetails.getKey()).isEqualTo(ruleKey);
assertThat(ruleDetails.getName()).isEqualTo("Unused local variables should be removed");
assertThat(ruleDetails.getLanguage()).isEqualTo("js");
assertThat(ruleDetails.getSeverity()).isEqualTo("MAJOR");
assertThat(ruleDetails.getHtmlDescription()).contains("<p>", "If a local variable is declared but not used");
assertThat(ruleDetails.getExtendedDescription()).isEmpty();
ClientInputFile inputFile = prepareInputFile("foo.js", "function foo() {\n" + " var x;\n" + " var y; //NOSONAR\n" + "}", false);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(new ConnectedAnalysisConfiguration(null, baseDir.toPath(), temp.newFolder().toPath(), Arrays.asList(inputFile), ImmutableMap.<String, String>of()), new StoreIssueListener(issues), null, null);
assertThat(issues).extracting("ruleKey", "startLine", "inputFile.path").containsOnly(tuple(ruleKey, 2, inputFile.getPath()));
}
use of org.sonarsource.sonarlint.core.client.api.common.analysis.ClientInputFile in project sonarlint-core by SonarSource.
the class LogMediumTest method changeLogOutputForAnalysis.
/**
* If this test starts to fail randomly, check if any other test class in the core module is using {@link org.sonar.api.utils.log.LogTester} without
* setting the root level back to debug in @AfterClass!
*/
@Test
public void changeLogOutputForAnalysis() throws Exception {
logs.clear();
ClientInputFile inputFile = prepareInputFile("foo.js", "function foo() {var x;}", false);
sonarlint.analyze(createConfig(inputFile), createNoOpIssueListener(), null, null);
assertThat(logs.get(LogOutput.Level.DEBUG)).isNotEmpty();
logs.clear();
final Multimap<LogOutput.Level, String> logs2 = Multimaps.synchronizedListMultimap(LinkedListMultimap.create());
sonarlint.analyze(createConfig(inputFile), createNoOpIssueListener(), createLogOutput(logs2), null);
assertThat(logs.get(LogOutput.Level.DEBUG)).isEmpty();
assertThat(logs2.get(LogOutput.Level.DEBUG)).isNotEmpty();
}
Aggregations