示例#1
0
def test_from_invalid_c(tempdir: Path):
    with open(tempdir / "foo.c", "w") as f:
        f.write("int main() syntax error!")

    with pytest.raises(
        pg.GraphCreationError,
        match="error: expected function body after function declarator",
    ):
        pg.from_clang([str(tempdir / "foo.c")])
示例#2
0
def test_cxx_input_with_undefined_identifier(tempdir: Path):
    """Implicit use is an error in C++."""
    with open(tempdir / "a.cpp", "w") as f:
        f.write(
            """
void A() {
    B();
}
"""
        )
    with pytest.raises(GraphCreationError, match="error: use of undeclared identifier"):
        pg.from_clang([str(tempdir / "a.cpp")])
示例#3
0
def test_from_multifile_c(tempdir: Path):
    """Multi-file inputs are not yet supported."""
    with open(tempdir / "a.c", "w") as f:
        f.write("int A() { return 0; }")
    with open(tempdir / "b.c", "w") as f:
        f.write("int B() { return 0; }")

    # TODO(https://github.com/ChrisCummins/ProGraML/issues/168): Add support
    # for multi-file inputs.
    with pytest.raises(
        pg.GraphCreationError,
        match="error: unable to handle compilation, expected exactly one compiler job",
    ):
        pg.from_clang([str(tempdir / "a.c"), str(tempdir / "b.c")])
示例#4
0
def test_multiple_inputs(tempdir: Path):
    with open(tempdir / "a.c", "w") as f:
        f.write("int A() { return 0; }")
    graphs = list(pg.from_clang([[str(tempdir / "a.c")]] * 10))
    assert len(graphs) == 10
    for graph in graphs:
        assert isinstance(graph, pg.ProgramGraph)
示例#5
0
def test_c_input_with_undefined_identifier(tempdir: Path):
    """Implicit use is allowed in C."""
    with open(tempdir / "a.c", "w") as f:
        f.write(
            """
void A() {
    B();
}
"""
        )
    graph = pg.from_clang([str(tempdir / "a.c")])
    assert isinstance(graph, pg.ProgramGraph)
示例#6
0
def test_cxx_input_with_std_header(tempdir: Path):
    with open(tempdir / "a.cpp", "w") as f:
        f.write(
            """
#include <iostream>
void A() {
    std::cout << "Hello, world" << std::endl;
}
"""
        )
    graph = pg.from_clang([str(tempdir / "a.cpp")])
    assert isinstance(graph, pg.ProgramGraph)
示例#7
0
def test_c_input_with_std_header(tempdir: Path):
    with open(tempdir / "a.c", "w") as f:
        f.write(
            """
#include <stdio.h>
void A() {
    printf("Hello, world\\n");
}
"""
        )
    graph = pg.from_clang([str(tempdir / "a.c")])
    assert isinstance(graph, pg.ProgramGraph)
示例#8
0
def test_c_input(tempdir: Path):
    with open(tempdir / "a.c", "w") as f:
        f.write("int A() { return 0; }")
    graph = pg.from_clang([str(tempdir / "a.c")])
    assert isinstance(graph, pg.ProgramGraph)
示例#9
0
def test_from_clang_smoke_test(llvm_ir_path: Path):
    """Smoke test on real IRs."""
    graph = pg.from_clang([str(llvm_ir_path)])
    assert isinstance(graph, pg.ProgramGraph)