def expect_cpp_code_generic_compile_error(expected_error_regex, tmppy_source, module_ir2, module_ir1, cxx_source):
    "\n    Tests that the given source produces the expected error during compilation.\n\n    :param expected_error_regex: A regex used to match the _py2tmp error type,\n           e.g. 'NoBindingFoundForAbstractClassError<ScalerImpl>'.\n    :param cxx_source: The second part of the source code. This will be dedented.\n    "
    expected_error_regex = expected_error_regex.replace(' ', '')

    def check_error(e, error_message_lines, error_message_head, normalized_error_message_lines):
        for line in normalized_error_message_lines:
            if re.search(expected_error_regex, line):
                return
        pytest.fail(textwrap.dedent('                Expected error {expected_error} but the compiler output did not contain that.\n                Compiler command line: {compiler_command}\n                Error message was:\n                {error_message}\n\n                TMPPy source:\n                {tmppy_source}\n                    \n                TMPPy IR2:\n                {tmppy_ir2}\n                \n                TMPPy IR1:\n                {tmppy_ir1}\n                \n                C++ source:\n                {cxx_source}\n                ').format(expected_error=expected_error_regex, compiler_command=e.command, tmppy_source=add_line_numbers(tmppy_source), tmppy_ir2=str(module_ir2), tmppy_ir1=str(module_ir1), cxx_source=add_line_numbers(cxx_source), error_message=error_message_head), pytrace=False)
    expect_cpp_code_compile_error_helper(check_error, tmppy_source, module_ir2, module_ir1, cxx_source)
Tests that the given source produces the expected error during compilation.

:param expected_error_regex: A regex used to match the _py2tmp error type,
       e.g. 'NoBindingFoundForAbstractClassError<ScalerImpl>'.
:param cxx_source: The second part of the source code. This will be dedented.
def expect_cpp_code_generic_compile_error(expected_error_regex, tmppy_source, module_ir2, module_ir1, cxx_source):
    "\n    Tests that the given source produces the expected error during compilation.\n\n    :param expected_error_regex: A regex used to match the _py2tmp error type,\n           e.g. 'NoBindingFoundForAbstractClassError<ScalerImpl>'.\n    :param cxx_source: The second part of the source code. This will be dedented.\n    "
    expected_error_regex = expected_error_regex.replace(' ', )

    def check_error(e, error_message_lines, error_message_head, normalized_error_message_lines):
        for line in normalized_error_message_lines:
            if re.search(expected_error_regex, line):
                return
        pytest.fail(textwrap.dedent('                Expected error {expected_error} but the compiler output did not contain that.\n                Compiler command line: {compiler_command}\n                Error message was:\n                {error_message}\n\n                TMPPy source:\n                {tmppy_source}\n                    \n                TMPPy IR2:\n                {tmppy_ir2}\n                \n                TMPPy IR1:\n                {tmppy_ir1}\n                \n                C++ source:\n                {cxx_source}\n                ').format(expected_error=expected_error_regex, compiler_command=e.command, tmppy_source=add_line_numbers(tmppy_source), tmppy_ir2=str(module_ir2), tmppy_ir1=str(module_ir1), cxx_source=add_line_numbers(cxx_source), error_message=error_message_head), pytrace=False)
    expect_cpp_code_compile_error_helper(check_error, tmppy_source, module_ir2, module_ir1, cxx_source)