Esempio n. 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")])
Esempio n. 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")])
Esempio n. 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")])
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)