Esempio n. 1
0
def test_Preprocess_ClangTimeout(mocker):
    """Test that ClangTimeout is raised if clang returns with SIGKILL."""
    mock_Popen = mocker.patch("subprocess.Popen")
    mock_Popen.return_value = MockProcess(9)
    with test.Raises(errors.ClangTimeout):
        clang.Preprocess("", [])
    # ClangTimeout inherits from ClangException.
    with test.Raises(errors.ClangException):
        clang.Preprocess("", [])
Esempio n. 2
0
def test_Preprocess_no_strip_processor_lines():
    """Test that stdin marker is preserved if no strip_preprocessor_lines."""
    assert '# 1 "<stdin>" 2' in clang.Preprocess(
        """
int main(int argc, char** argv) { return 0; }
""", [],
        strip_preprocessor_lines=False)
Esempio n. 3
0
def test_Preprocess_inlined_define():
    """Test pre-processing with a #define in the source code."""
    assert clang.Preprocess(
        """
#define MY_TYPE int
int main(MY_TYPE argc, char** argv) { return 0; }
""", ['-DMY_TYPE=int']) == """
Esempio n. 4
0
def test_Preprocess_process_command(mocker):
    """Test the process comand which is run."""
    mock_Popen = mocker.patch("subprocess.Popen")
    mock_Popen.return_value = MockProcess(0)
    clang.Preprocess("", ["-foo"])
    subprocess.Popen.assert_called_once()
    cmd = subprocess.Popen.call_args_list[0][0][0]
    assert cmd[:3] == ["timeout", "-s9", "60"]
    assert cmd[4:] == ["-E", "-c", "-", "-o", "-", "-foo"]
Esempio n. 5
0
def test_Preprocess_process_command(mocker):
    """Test the process comand which is run."""
    mock_Popen = mocker.patch('subprocess.Popen')
    mock_Popen.return_value = MockProcess(0)
    clang.Preprocess('', ['-foo'])
    subprocess.Popen.assert_called_once()
    cmd = subprocess.Popen.call_args_list[0][0][0]
    assert cmd[:3] == ['timeout', '-s9', '60']
    assert cmd[4:] == ['-E', '-c', '-', '-o', '-', '-foo']
Esempio n. 6
0
def test_Preprocess_invalid_preprocessor_directive():
    """Test that an invalid preprocessor directive raises an error."""
    with pytest.raises(errors.ClangException) as e_info:
        clang.Preprocess(
            """
#this_is_not_a_valid_directive
int main(int argc, char** argv) { return 0; }
""", [])
    assert "invalid preprocessing directive" in str(e_info.value)
Esempio n. 7
0
def test_Preprocess_undefined_variable():
    """Test that an undefined variable does not cause an error."""
    assert (clang.Preprocess(
        """
int main(int argc, char** argv) { return UNDEFINED_VARIABLE; }
""",
        [],
    ) == """
int main(int argc, char** argv) { return UNDEFINED_VARIABLE; }
""")
Esempio n. 8
0
def test_Preprocess_undefined_data_type():
    """Test that an undefined data type does not cause an error."""
    assert (clang.Preprocess(
        """
int main(MY_TYPE argc, char** argv) { return 0; }
""",
        [],
    ) == """
int main(MY_TYPE argc, char** argv) { return 0; }
""")
Esempio n. 9
0
def test_Preprocess_inlined_cflag():
    """Test pre-processing with a custom define in the command line."""
    assert (clang.Preprocess(
        """
int main(MY_TYPE argc, char** argv) { return 0; }
""",
        ["-DMY_TYPE=int"],
    ) == """
int main(int argc, char** argv) { return 0; }
""")
Esempio n. 10
0
def test_Preprocess_undefined_function():
    """Test that an undefined function does not cause an error."""
    assert (clang.Preprocess(
        """
int main(int argc, char** argv) { return UNDEFINED_FUNCTION(0); }
""",
        [],
    ) == """
int main(int argc, char** argv) { return UNDEFINED_FUNCTION(0); }
""")
Esempio n. 11
0
def test_Preprocess_simple_c_program():
    """Test that a simple C program is unchanged."""
    assert (clang.Preprocess(
        """
int main(int argc, char** argv) { return 0; }
""",
        [],
    ) == """
int main(int argc, char** argv) { return 0; }
""")
Esempio n. 12
0
def test_Preprocess_include_stdio_strip():
    """Test that an included file is stripped."""
    out = clang.Preprocess(
        """
#include <stdio.h>
int main(int argc, char** argv) { return NULL; }
""", [])
    # NULL expands to either "((void *)0)" or "((void*)0)". Accept either.
    assert out == """\
int main(int argc, char** argv) { return ((void *)0); }
""" or out == """\
Esempio n. 13
0
def _ClangPreprocess(text: str, use_shim: bool) -> str:
    """Private preprocess OpenCL source implementation.

  Inline macros, removes comments, etc.

  Args:
    text: OpenCL source.
    use_shim: Inject shim header.

  Returns:
    Preprocessed source.
  """
    return clang.Preprocess(text, GetClangArgs(use_shim=use_shim))
Esempio n. 14
0
def _ClangPreprocess(text: str, use_shim: bool, use_aux_headers: bool,
                     extra_args: typing.List[str]) -> str:
    """Private preprocess OpenCL source implementation.

  Inline macros, removes comments, etc.

  Args:
    text: OpenCL source.
    use_shim: Inject shim header.

  Returns:
    Preprocessed source.
  """
    return clang.Preprocess(
        text,
        GetClangArgs(use_shim=use_shim,
                     use_aux_headers=use_aux_headers,
                     extra_args=extra_args))
Esempio n. 15
0
def ClangPreprocess(text: str) -> str:
  return clang.Preprocess(text, CLANG_ARGS)
Esempio n. 16
0
def test_Preprocess_ClangException(mocker):
    """Test that ClangException is raised if clang returns non-zero returncode."""
    mock_Popen = mocker.patch("subprocess.Popen")
    mock_Popen.return_value = MockProcess(1)
    with test.Raises(errors.ClangException):
        clang.Preprocess("", [])
Esempio n. 17
0
def test_Preprocess_empty_file():
    """Test the preprocessor output with an empty file."""
    assert clang.Preprocess("", []) == "\n"