示例#1
0
文件: test_cc.py 项目: 17451k/clade
def test_cc_ignore_cc1(tmpdir, cmds_file, ignore_cc1):
    conf = {"CC.ignore_cc1": ignore_cc1}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("CC")

    found_cc1 = False

    for cmd in e.load_all_cmds(with_opts=True):
        if"-cc1" in cmd["opts"]:
            found_cc1 = True

    if ignore_cc1 or found_cc1:
        assert ignore_cc1 != found_cc1
示例#2
0
def test_path_capital(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    c.parse("SrcGraph")

    tmpdir = str(tmpdir)

    test_small = pathlib.Path(tmpdir) / "test.c"
    test_capital = pathlib.Path(tmpdir) / "TEST.c"

    test_small.touch()
    test_capital.touch()

    c.Path.normalize_rel_path("TEST.c", tmpdir)
    c.Path.normalize_rel_path("test.c", tmpdir)

    assert "test.c" in c.Path.get_rel_path("test.c", tmpdir)
    assert "TEST.c" in c.Path.get_rel_path("TEST.c", tmpdir)

    # Clear cache
    c.Path.paths = dict()

    assert "test.c" in c.Path.get_rel_path("test.c", tmpdir)
    assert "TEST.c" in c.Path.get_rel_path("TEST.c", tmpdir)
示例#3
0
文件: test_cc.py 项目: 17451k/clade
def test_cc_store_deps(tmpdir, cmds_file, store_deps):
    conf = {"Compiler.store_deps": store_deps}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("CC")

    storage_dir = e.extensions["Storage"].get_storage_dir()

    for cmd in e.load_all_cmds(with_deps=True, compile_only=True):
        for file in cmd["deps"]:
            if not os.path.isabs(file):
                file = os.path.join(cmd["cwd"], file)

            assert os.path.exists(storage_dir + os.sep + file) == store_deps
示例#4
0
def test_functions(tmpdir, cmds_file):
    conf = {"CmdGraph.requires": ["CC", "MV"]}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("Functions")

    funcs = e.load_functions()
    funcs_by_file = e.load_functions_by_file()
    funcs_by_main_c = e.load_functions_by_file([main_c])

    funcs_are_ok(funcs)
    funcs_by_file_are_ok(funcs_by_file)
    funcs_are_consistent(funcs, funcs_by_file)
    filtered_funcs_by_file_are_ok(funcs_by_file, funcs_by_main_c)
示例#5
0
def test_callgraph(tmpdir, cmds_file):
    conf = {"CmdGraph.requires": ["CC", "MV"]}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("Callgraph")

    callgraph = e.load_callgraph()
    callgraph_by_zero_c = e.load_callgraph([zero_c])
    calls_by_ptr = e.load_calls_by_ptr()
    used_in = e.load_used_in()

    callgraph_is_ok(callgraph)
    callgraph_by_file_is_ok(callgraph, callgraph_by_zero_c)
    calls_by_ptr_is_ok(calls_by_ptr)
    used_in_is_ok(used_in)
示例#6
0
def test_cross_ref(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("CrossRef")

    ref_to = e.load_ref_to_by_file()
    ref_to_are_ok(ref_to)

    ref_to_main_c = e.load_ref_to_by_file([main_c])
    filtered_ref_to_are_ok(ref_to, ref_to_main_c)

    ref_from = e.load_ref_from_by_file()
    ref_from_are_ok(ref_from)

    ref_from_main_c = e.load_ref_from_by_file([main_c])
    filtered_ref_from_are_ok(ref_from, ref_from_main_c)
示例#7
0
文件: test_info.py 项目: 17451k/clade
def test_info(tmpdir, cmds_file):
    conf = {"CC.filter_deps": False, "Info.extra_CIF_pts": ["-hello"]}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("Info")

    assert list(e.iter_definitions())
    assert list(e.iter_declarations())
    assert not list(e.iter_exported())
    assert list(e.iter_calls())
    assert list(e.iter_calls_by_pointers())
    assert list(e.iter_functions_usages())
    assert list(e.iter_macros_definitions())
    assert list(e.iter_macros_expansions())
    assert list(e.iter_typedefs())
示例#8
0
文件: test_cc.py 项目: 17451k/clade
def test_cc_with_system_header_files(tmpdir, cmds_file, with_system_header_files):
    conf = {"CC.with_system_header_files": with_system_header_files}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("CC")

    for cmd in e.load_all_cmds(with_deps=True, compile_only=True):
        if not with_system_header_files:
            for file in cmd["deps"]:
                assert not re.search(r"/usr", file)
        else:
            for file in cmd["deps"]:
                if re.search(r"/usr", file):
                    break
            else:
                assert False
示例#9
0
def test_as(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("AS")

    cmds = e.load_all_cmds(with_opts=True, with_raw=True)
    target_cmd = dict()

    for cmd in cmds:
        for cmd_in in cmd["in"]:
            if re.search("empty.s", cmd_in):
                target_cmd = cmd

    assert len(cmds) >= 1
    assert len(target_cmd["in"]) == 1
    assert len(target_cmd["out"]) == 1
    assert len(target_cmd["opts"]) == 2
    assert len(target_cmd["command"]) == 6
示例#10
0
def test_ld(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("LD")

    cmds = e.load_all_cmds(with_opts=True, with_raw=True)

    target_cmd = dict()

    for cmd in cmds:
        for cmd_out in cmd["out"]:
            if re.search("main.o2", cmd_out):
                target_cmd = cmd

    assert len(cmds) >= 1
    assert len(target_cmd["in"]) == 2
    assert len(target_cmd["out"]) == 1
    assert len(target_cmd["opts"]) == 7
    assert len(target_cmd["command"]) == 11
示例#11
0
def test_src_graph(tmpdir, cmds_file):
    conf = {"CmdGraph.requires": ["CC", "MV"]}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("SrcGraph")

    src_graph = e.load_src_graph()

    assert src_graph
    assert len(src_graph[test_file]["compiled_in"]) == 3
    assert len(src_graph[test_file]["used_by"]) == 2

    src_info = e.load_src_info()
    assert src_info
    assert src_info[test_file]["loc"] == 11

    graph_part = e.load_src_graph([test_file])
    assert graph_part
    assert len(graph_part[test_file]["used_by"]) == 2
    assert len(src_graph[test_file]["compiled_in"]) == 3
示例#12
0
文件: test_cc.py 项目: mutilin/clade
def test_cc_load_all_cmds(tmpdir, cmds_file, with_opts, with_deps):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("CC")

    cmds = list(e.load_all_cmds(with_opts=with_opts, with_deps=with_deps))
    assert len(cmds) > 1

    for cmd in cmds:
        assert ("opts" in cmd) == with_opts
        assert ("deps" in cmd) == with_deps

        cmd_by_id = e.load_cmd_by_id(cmd["id"])

        assert cmd_by_id["id"] == cmd["id"]
        assert cmd_by_id["in"] == cmd["in"]
        assert cmd_by_id["out"] == cmd["out"]

        if with_opts:
            assert cmd["opts"] == e.load_opts_by_id(cmd["id"])

        if with_deps:
            assert cmd["deps"] == e.load_deps_by_id(cmd["id"])
示例#13
0
def test_cmd_graph_requires(tmpdir, cmds_file):
    conf = {"CmdGraph.requires": ["CC", "MV"]}

    c = Clade(tmpdir, cmds_file, conf)
    e = c.parse("CmdGraph")

    cmd_graph = e.load_cmd_graph()

    cmd_id = None
    for cmd in e.extensions["CC"].load_all_cmds():
        if "main.c" in cmd["in"] and "zero.c" in cmd[
                "in"] and "tmp_main" in cmd["out"]:
            cmd_id = str(cmd["id"])

    assert cmd_id
    assert cmd_graph
    assert cmd_graph[cmd_id]["type"] == "CC"
    assert len(cmd_graph[cmd_id]["used_by"]) == 1
    assert cmd_graph[cmd_id]["using"] == []

    used_by_id = cmd_graph[cmd_id]["used_by"][0]
    assert cmd_graph[used_by_id]["using"] == [cmd_id]
示例#14
0
def test_pid_graph(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("PidGraph")

    last_id = get_last_id(cmds_file)

    pid_graph = e.load_pid_graph()
    pid_by_id = e.load_pid_by_id()

    cmd_ids = list(str(x) for x in range(1, int(last_id) + 1))
    assert len(pid_graph) == len(cmd_ids)

    for cmd_id in cmd_ids:
        assert cmd_id in pid_graph
        assert len(pid_graph[cmd_id]) >= 1

        for pid in pid_graph[cmd_id]:
            assert int(pid) < int(cmd_id)

    assert len(pid_by_id) == len(cmd_ids)

    for cmd_id in cmd_ids:
        assert cmd_id in pid_by_id
        assert int(pid_by_id[cmd_id]) < int(cmd_id)
示例#15
0
def test_cxx(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("CXX")

    assert len(list(e.load_all_cmds(compile_only=True))) >= 1
示例#16
0
def test_parse_undef(tmpdir):
    with pytest.raises(NotImplementedError):
        c = Clade(tmpdir)
        c.parse("XYZ")
示例#17
0
def test_cant_create_work_dir():
    with pytest.raises(PermissionError):
        c = Clade("/clade_test")
        c.parse("CC")
示例#18
0
def test_cmd_graph_empty_conf(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("CmdGraph")

    assert e.load_cmd_graph()
示例#19
0
def test_variables(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("Variables")

    variables_are_ok(e.load_variables())
    used_in_vars_is_ok(e.load_used_in_vars())
示例#20
0
def test_macros(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    c.parse("Macros")

    definitions_are_ok(c.get_macros_definitions())
    expansions_are_ok(c.get_macros_expansions())
示例#21
0
文件: test_cc.py 项目: mutilin/clade
def test_cc_empty_conf(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("CC")

    assert len(list(e.load_all_cmds()))
示例#22
0
def test_path(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    c.parse("SrcGraph")

    assert c.Path.normalize_rel_path(test_file_rel,
                                     os.getcwd()) == test_file_abs
示例#23
0
def test_typedefs(tmpdir, cmds_file):
    c = Clade(tmpdir, cmds_file)
    e = c.parse("Typedefs")

    typedefs_are_ok(e.load_typedefs())