Пример #1
0
def test_as_dict(mock_revision, mock_hgmo):
    """
    Test dict export for InferIssue
    """

    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "SomeKindOfBug",
        "qualifier": "Error on this line",
    }
    issue = InferIssue("mock-infer", parts, mock_revision)

    assert issue.as_dict() == {
        "analyzer": "mock-infer",
        "check": "SOMETYPE",
        "column": -1,
        "in_patch": False,
        "level": "SomeKindOfBug",
        "line": 3,
        "message": "Error on this line",
        "nb_lines": 1,
        "path": "path/to/file.java",
        "publishable": False,
        "validates": True,
        "hash": "405fafd74d01b0d109903804e6cf3a5a",
    }
Пример #2
0
def test_as_dict(mock_revision, mock_hgmo, mock_task):
    """
    Test dict export for InferIssue
    """

    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "WARNING",
        "qualifier": "Error on this line",
    }
    issue = InferIssue(mock_task(InferTask, "mock-infer"), parts,
                       mock_revision)

    assert issue.as_dict() == {
        "analyzer": "mock-infer",
        "check": "SOMETYPE",
        "column": -1,
        "in_patch": False,
        "level": "warning",
        "line": 3,
        "message": "Error on this line",
        "nb_lines": 1,
        "path": "path/to/file.java",
        "publishable": False,
        "validates": True,
        "hash": "f446f72d667c04e3d9164f91af424414",
    }
Пример #3
0
def test_as_markdown(mock_revision, mock_task):
    """
    Test markdown generation for InferIssue
    """

    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "WARNING",
        "qualifier": "Error on this line",
    }
    issue = InferIssue(mock_task(InferTask, "mock-infer"), parts,
                       mock_revision)

    assert (issue.as_markdown() == """
## infer error

- **Message**: Error on this line
- **Location**: path/to/file.java:3:-1
- **In patch**: no
- **Infer check**: SOMETYPE
- **Publishable **: no
""")
Пример #4
0
def test_as_markdown(mock_revision):
    """
    Test markdown generation for InferIssue
    """
    from code_review_bot.tasks.infer import InferIssue

    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "SomeKindOfBug",
        "qualifier": "Error on this line",
    }
    issue = InferIssue(parts, mock_revision)
    issue.body = "Dummy body"

    assert (issue.as_markdown() == """
## infer error

- **Message**: Error on this line
- **Location**: path/to/file.java:3:-1
- **In patch**: no
- **Infer check**: SOMETYPE
- **Publishable **: no
- **Is new**: no

```
Dummy body
```
""")
Пример #5
0
def test_as_dict(mock_revision, mock_hgmo):
    """
    Test dict export for InferIssue
    """

    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "WARNING",
        "qualifier": "Error on this line",
    }
    issue = InferIssue("mock-infer", parts, mock_revision)

    assert issue.as_dict() == {
        "analyzer": "mock-infer",
        "check": "SOMETYPE",
        "column": -1,
        "in_patch": False,
        "level": "warning",
        "line": 3,
        "message": "Error on this line",
        "nb_lines": 1,
        "path": "path/to/file.java",
        "publishable": False,
        "validates": True,
        "hash": "fdbdadc20b9d1d905f7d123eb847902b",
    }
Пример #6
0
def test_as_text(mock_revision):
    """
    Test text export for InferIssue
    """
    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "SomeKindOfBug",
        "qualifier": "Error on this line",
    }
    issue = InferIssue("mock-infer", parts, mock_revision)

    expected = "SomeKindOfBug: Error on this line [infer: SOMETYPE]"
    assert issue.as_text() == expected
Пример #7
0
    def _test_reporter(api, analyzers_skipped):
        # Always use the same setup, only varies the analyzers
        revision = Revision.from_try(mock_try_task, api)
        revision.lines = {"test.cpp": [0, 41, 42, 43], "dom/test.cpp": [42]}
        reporter = PhabricatorReporter(
            {"analyzers_skipped": analyzers_skipped}, api=api
        )

        issues = [
            ClangFormatIssue("mock-clang-format", "dom/test.cpp", 42, 1, revision),
            ClangTidyIssue(
                "mock-clang-tidy",
                revision,
                "test.cpp",
                "42",
                "51",
                "modernize-use-nullptr",
                "dummy message",
            ),
            InferIssue(
                "mock-infer",
                {
                    "file": "test.cpp",
                    "line": 42,
                    "column": 1,
                    "bug_type": "dummy",
                    "kind": "WARNING",
                    "qualifier": "dummy message.",
                },
                revision,
            ),
            MozLintIssue(
                "mock-lint-flake8",
                "test.cpp",
                1,
                "error",
                42,
                "flake8",
                "Python error",
                "EXXX",
                revision,
            ),
            CoverageIssue("test.cpp", 0, "This file is uncovered", revision),
        ]

        assert all(i.is_publishable() for i in issues)

        revision.improvement_patches = [
            ImprovementPatch("dummy", repr(revision), "Whatever"),
            ImprovementPatch("mock-clang-tidy", repr(revision), "Some C fixes"),
            ImprovementPatch("mock-clang-format", repr(revision), "Some lint fixes"),
            ImprovementPatch("mock-infer", repr(revision), "Some java fixes"),
            ImprovementPatch("mock-lint-flake8", repr(revision), "Some js fixes"),
        ]
        list(
            map(lambda p: p.write(), revision.improvement_patches)
        )  # trigger local write

        return reporter.publish(issues, revision, [])
Пример #8
0
def test_as_text(mock_revision, mock_task):
    """
    Test text export for InferIssue
    """
    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "ERROR",
        "qualifier": "Error on this line",
    }
    issue = InferIssue(mock_task(InferTask, "mock-infer"), parts,
                       mock_revision)

    expected = "Warning: Error on this line [infer: SOMETYPE]"
    assert issue.as_text() == expected
Пример #9
0
def test_as_text(mock_revision):
    """
    Test text export for InferIssue
    """
    from code_review_bot.tasks.infer import InferIssue

    parts = {
        "file": "path/to/file.java",
        "line": 3,
        "column": -1,
        "bug_type": "SOMETYPE",
        "kind": "SomeKindOfBug",
        "qualifier": "Error on this line",
    }
    issue = InferIssue(parts, mock_revision)
    issue.body = "Dummy body withUppercaseChars"

    expected = "SomeKindOfBug: Error on this line [infer: SOMETYPE]"
    assert issue.as_text() == expected
Пример #10
0
def test_phabricator_analyzers(
    analyzers_skipped,
    valid_issues,
    valid_patches,
    mock_config,
    mock_phabricator,
    mock_try_task,
    mock_task,
):
    """
    Test analyzers filtering on phabricator reporter
    """
    with mock_phabricator as api:

        # Skip commenting on phabricator
        # we only care about filtering issues
        api.comment = unittest.mock.Mock(return_value=True)

        # Always use the same setup, only varies the analyzers
        revision = Revision.from_try(mock_try_task, api)
        revision.mercurial_revision = "deadbeef1234"
        revision.repository = "https://hg.mozilla.org/try"
        revision.repository_try_name = "try"
        revision.lines = {"test.cpp": [0, 41, 42, 43], "dom/test.cpp": [42]}
        reporter = PhabricatorReporter(
            {"analyzers_skipped": analyzers_skipped}, api=api
        )

    issues = [
        ClangFormatIssue(
            mock_task(ClangFormatTask, "mock-clang-format"),
            "dom/test.cpp",
            [
                (41, 41, b"no change"),
                (42, None, b"deletion"),
                (None, 42, b"change here"),
            ],
            revision,
        ),
        ClangTidyIssue(
            mock_task(ClangTidyTask, "mock-clang-tidy"),
            revision,
            "test.cpp",
            "42",
            "51",
            "modernize-use-nullptr",
            "dummy message",
        ),
        InferIssue(
            mock_task(InferTask, "mock-infer"),
            {
                "file": "test.cpp",
                "line": 42,
                "column": 1,
                "bug_type": "dummy",
                "kind": "WARNING",
                "qualifier": "dummy message.",
            },
            revision,
        ),
        MozLintIssue(
            mock_task(MozLintTask, "mock-lint-flake8"),
            "test.cpp",
            1,
            "error",
            42,
            "flake8",
            "Python error",
            "EXXX",
            revision,
        ),
        CoverageIssue(
            mock_task(ZeroCoverageTask, "coverage"),
            "test.cpp",
            0,
            "This file is uncovered",
            revision,
        ),
    ]

    assert all(i.is_publishable() for i in issues)

    revision.improvement_patches = [
        ImprovementPatch(mock_task(DefaultTask, "dummy"), repr(revision), "Whatever"),
        ImprovementPatch(
            mock_task(ClangTidyTask, "mock-clang-tidy"), repr(revision), "Some C fixes"
        ),
        ImprovementPatch(
            mock_task(ClangFormatTask, "mock-clang-format"),
            repr(revision),
            "Some lint fixes",
        ),
        ImprovementPatch(
            mock_task(InferTask, "mock-infer"), repr(revision), "Some java fixes"
        ),
        ImprovementPatch(
            mock_task(MozLintTask, "mock-lint-flake8"), repr(revision), "Some js fixes"
        ),
    ]
    list(map(lambda p: p.write(), revision.improvement_patches))  # trigger local write

    issues, patches = reporter.publish(issues, revision, [])

    # Check issues & patches analyzers
    assert len(issues) == len(valid_issues)
    assert len(patches) == len(valid_patches)
    assert [i.analyzer.name for i in issues] == valid_issues
    assert [p.analyzer.name for p in patches] == valid_patches