Exemplo n.º 1
0
def test_repeats(mock_clang_repeats, mock_revision, mock_config):
    '''
    Test repeated issues are removed through set usage
    '''

    from static_analysis_bot.clang.tidy import ClangTidy
    clang_tidy = ClangTidy()

    issues = clang_tidy.parse_issues(mock_clang_repeats, mock_revision)
    assert isinstance(issues, list)

    # We have 2 issues for modernize-loop-convert
    # on the same file/line/char
    assert len(issues) == 4
    count = Counter(i.check for i in issues)
    assert count['modernize-loop-convert'] == 2

    # A set should remove repeats
    issues = set(issues)
    assert len(issues) == 3
    count = Counter(i.check for i in issues)
    assert count['modernize-loop-convert'] == 1
Exemplo n.º 2
0
def test_repeats(mock_clang_repeats, mock_clang, mock_revision, mock_config, mock_repository):
    '''
    Test repeated issues are removed through set usage
    '''

    from static_analysis_bot.clang.tidy import ClangTidy
    clang_tidy = ClangTidy()

    issues = clang_tidy.parse_issues(mock_clang_repeats, mock_revision)
    assert isinstance(issues, list)

    # We have 2 issues for modernize-loop-convert
    # on the same file/line/char
    assert len(issues) == 4
    count = Counter(i.check for i in issues)
    assert count['modernize-loop-convert'] == 2

    # A set should remove repeats
    issues = set(issues)
    assert len(issues) == 3
    count = Counter(i.check for i in issues)
    assert count['modernize-loop-convert'] == 1
Exemplo n.º 3
0
def test_clang_tidy_parser(mock_config, mock_repository, mock_revision,
                           mock_clang_output, mock_clang_issues):
    '''
    Test the clang-tidy (or mach static-analysis) parser
    '''
    from static_analysis_bot.clang.tidy import ClangTidy
    clang_tidy = ClangTidy()

    # Empty Output
    clang_output = 'Nothing.'
    issues = clang_tidy.parse_issues(clang_output, mock_revision)
    assert issues == []

    # No warnings
    clang_output = 'Whatever text.\n0 warnings present.'
    issues = clang_tidy.parse_issues(clang_output, mock_revision)
    assert issues == []

    # One warning, but no header
    clang_output = 'Whatever text.\n1 warnings present.'
    with pytest.raises(Exception):
        clang_tidy.parse_issues(clang_output, mock_revision)

    # One warning, One header
    clang_output = '/path/to/test.cpp:42:39: error: methods annotated with MOZ_NO_DANGLING_ON_TEMPORARIES cannot be && ref-qualified [mozilla-dangling-on-temporary]'  # noqa
    clang_output += '\n1 warnings present.'
    issues = clang_tidy.parse_issues(clang_output, mock_revision)
    assert len(issues) == 1
    assert issues[0].path == '/path/to/test.cpp'
    assert issues[0].line == 42
    assert issues[0].check == 'mozilla-dangling-on-temporary'

    # Real case
    issues = clang_tidy.parse_issues(mock_clang_output, mock_revision)
    assert len(issues) == 13
    sep = '\n' + '-' * 20 + '\n'
    summary = sep.join(issue.as_text() for issue in issues)
    assert summary == mock_clang_issues
Exemplo n.º 4
0
def test_clang_tidy_parser(mock_config, mock_repository, mock_revision, mock_clang_output, mock_clang_issues):
    '''
    Test the clang-tidy (or mach static-analysis) parser
    '''
    from static_analysis_bot.clang.tidy import ClangTidy
    clang_tidy = ClangTidy()

    # Empty Output
    clang_output = 'Nothing.'
    issues = clang_tidy.parse_issues(clang_output, mock_revision)
    assert issues == []

    # No warnings
    clang_output = 'Whatever text.\n0 warnings present.'
    issues = clang_tidy.parse_issues(clang_output, mock_revision)
    assert issues == []

    # One warning, but no header
    clang_output = 'Whatever text.\n1 warnings present.'
    with pytest.raises(Exception):
        clang_tidy.parse_issues(clang_output, mock_revision)

    # One warning, One header
    clang_output = '/path/to/test.cpp:42:39: error: methods annotated with MOZ_NO_DANGLING_ON_TEMPORARIES cannot be && ref-qualified [mozilla-dangling-on-temporary]'  # noqa
    clang_output += '\n1 warnings present.'
    issues = clang_tidy.parse_issues(clang_output, mock_revision)
    assert len(issues) == 1
    assert issues[0].path == '/path/to/test.cpp'
    assert issues[0].line == 42
    assert issues[0].check == 'mozilla-dangling-on-temporary'

    # Real case
    issues = clang_tidy.parse_issues(mock_clang_output, mock_revision)
    assert len(issues) == 13
    sep = '\n' + '-'*20 + '\n'
    summary = sep.join(issue.as_text() for issue in issues)
    assert summary == mock_clang_issues