Search in sources :

Example 1 with SingleFileVerifier

use of com.sonarsource.checks.verifier.SingleFileVerifier in project sonar-go by SonarSource.

the class TestUtils method checkNoIssue.

public static void checkNoIssue(Check check, Path testFile, UastNode uast) throws IOException {
    SingleFileVerifier verifier = analyze(check, testFile, uast);
    verifier.assertNoIssues();
}
Also used : SingleFileVerifier(com.sonarsource.checks.verifier.SingleFileVerifier)

Example 2 with SingleFileVerifier

use of com.sonarsource.checks.verifier.SingleFileVerifier in project sonar-go by SonarSource.

the class TestUtils method checkRule.

public static void checkRule(Check check, Path testFile, UastNode uast) throws IOException {
    SingleFileVerifier verifier = analyze(check, testFile, uast);
    verifier.assertOneOrMoreIssues();
}
Also used : SingleFileVerifier(com.sonarsource.checks.verifier.SingleFileVerifier)

Example 3 with SingleFileVerifier

use of com.sonarsource.checks.verifier.SingleFileVerifier in project sonar-go by SonarSource.

the class TestUtils method analyze.

private static SingleFileVerifier analyze(Check check, Path testFile, UastNode uast) throws IOException {
    TestInputFileBuilder inputFile = TestInputFileBuilder.create("test", testFile.getParent().toFile(), testFile.toFile());
    inputFile.setContents(new String(Files.readAllBytes(testFile), StandardCharsets.UTF_8));
    inputFile.setCharset(StandardCharsets.UTF_8);
    Engine engine = new Engine(Collections.singletonList(check));
    List<Issue> issues = engine.scan(uast, inputFile.build()).issues;
    SingleFileVerifier verifier = SingleFileVerifier.create(testFile, StandardCharsets.UTF_8);
    uast.getDescendants(UastNode.Kind.COMMENT, comment -> verifier.addComment(comment.token.line, comment.token.column, comment.token.value, 2, 0));
    issues.forEach(issue -> reportIssueTo(verifier, issue));
    return verifier;
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) Issue(org.sonar.commonruleengine.Issue) SingleFileVerifier(com.sonarsource.checks.verifier.SingleFileVerifier) Engine(org.sonar.commonruleengine.Engine)

Aggregations

SingleFileVerifier (com.sonarsource.checks.verifier.SingleFileVerifier)3 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)1 Engine (org.sonar.commonruleengine.Engine)1 Issue (org.sonar.commonruleengine.Issue)1