def setup_cppcheck_tool_plugin(use_plugin_context=True, binary=None):
    """Initialize and return an instance of the cppcheck plugin."""
    arg_parser = argparse.ArgumentParser()
    arg_parser.add_argument(
        "--show-tool-output",
        dest="show_tool_output",
        action="store_false",
        help="Show tool output",
    )
    arg_parser.add_argument("--cppcheck-bin", dest="cppcheck_bin")
    arg_parser.add_argument("--mapping-file-suffix",
                            dest="mapping_file_suffix",
                            type=str)

    resources = Resources(
        [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")])
    config = Config(resources.get_file("config.yaml"))
    plugin_context = PluginContext(arg_parser.parse_args([]), resources,
                                   config)
    plugin_context.args.output_directory = os.path.dirname(__file__)
    cctp = CppcheckToolPlugin()
    if binary:
        plugin_context.args.cppcheck_bin = binary
    if use_plugin_context:
        cctp.set_plugin_context(plugin_context)
    return cctp
예제 #2
0
def test_checkforexceptions_false():
    """Test check_for_exceptions behavior where it should return False."""
    mm = mock.MagicMock()
    mm.group.side_effect = (
        lambda i: "test.c" if i == 1 else "some-other-error" if i == 6 else False
    )
    assert not CppcheckToolPlugin.check_for_exceptions(mm)
예제 #3
0
def test_checkforexceptions_true():
    """Test check_for_exceptions behavior where it should return True."""
    mm = mock.MagicMock()
    mm.group.side_effect = (
        lambda i: "test.c" if i == 1 else "variableScope" if i == 4 else False
    )
    assert CppcheckToolPlugin.check_for_exceptions(mm)