def check_error(e, error_message_lines, error_message_head, normalized_error_message_lines):
    for (line_number, line) in enumerate(normalized_error_message_lines):
        match = re.search('tmppy::impl::(.*Error<.*>)', line)
        if match:
            actual_py2tmp_error_line_number = line_number
            actual_py2tmp_error = match.groups()[0]
            if (config.CXX_COMPILER_NAME == 'MSVC'):
                try:
                    replacement_lines = []
                    if (normalized_error_message_lines[(line_number + 1)].strip() == 'with'):
                        for line in itertools.islice(normalized_error_message_lines, (line_number + 3), None):
                            line = line.strip()
                            if (line == ']'):
                                break
                            if line.endswith(','):
                                line = line[:(- 1)]
                            replacement_lines.append(line)
                    for replacement_line in replacement_lines:
                        match = re.search('([A-Za-z0-9_-]*)=(.*)', replacement_line)
                        if (not match):
                            raise Exception(('Failed to parse replacement line: %s' % replacement_line)) from e
                        (type_variable, type_expression) = match.groups()
                        actual_py2tmp_error = re.sub((('\\b' + type_variable) + '\\b'), type_expression, actual_py2tmp_error)
                except Exception:
                    raise Exception('Failed to parse MSVC template type arguments')
            break
    else:
        pytest.fail(textwrap.dedent('                    Expected error {expected_error} but the compiler output did not contain user-facing _py2tmp errors.\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 code:\n                    {cxx_source}\n                    ').format(expected_error=expected_py2tmp_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)
    for (line_number, line) in enumerate(error_message_lines):
        match = re.search(py2tmp_error_message_extraction_regex, line)
        if match:
            actual_static_assert_error_line_number = line_number
            actual_static_assert_error = match.groups()[0]
            break
    else:
        pytest.fail(textwrap.dedent('                    Expected error {expected_error} but the compiler output did not contain static_assert errors.\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 code:\n                    {cxx_source}\n                    ').format(expected_error=expected_py2tmp_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)
    try:
        regex_search_result = re.search(expected_py2tmp_error_regex, actual_py2tmp_error)
    except Exception as e:
        raise Exception(("re.search() failed for regex '%s'" % expected_py2tmp_error_regex)) from e
    if (not regex_search_result):
        pytest.fail(textwrap.dedent('                    The compilation failed as expected, but with a different error type.\n                    Expected _py2tmp error type:    {expected_py2tmp_error_regex}\n                    Error type was:               {actual_py2tmp_error}\n                    Expected static assert error: {expected_py2tmp_error_desc_regex}\n                    Static assert was:            {actual_static_assert_error}\n                    \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 code:\n                    {cxx_source}\n                    '.format(expected_py2tmp_error_regex=expected_py2tmp_error_regex, actual_py2tmp_error=actual_py2tmp_error, expected_py2tmp_error_desc_regex=expected_py2tmp_error_desc_regex, actual_static_assert_error=actual_static_assert_error, 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)
    try:
        regex_search_result = re.search(expected_py2tmp_error_desc_regex, actual_static_assert_error)
    except Exception as e:
        raise Exception(("re.search() failed for regex '%s'" % expected_py2tmp_error_desc_regex)) from e
    if (not regex_search_result):
        pytest.fail(textwrap.dedent('                    The compilation failed as expected, but with a different error message.\n                    Expected _py2tmp error type:    {expected_py2tmp_error_regex}\n                    Error type was:               {actual_py2tmp_error}\n                    Expected static assert error: {expected_py2tmp_error_desc_regex}\n                    Static assert was:            {actual_static_assert_error}\n                    \n                    Error message:\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 code:\n                    {cxx_source}\n                    '.format(expected_py2tmp_error_regex=expected_py2tmp_error_regex, actual_py2tmp_error=actual_py2tmp_error, expected_py2tmp_error_desc_regex=expected_py2tmp_error_desc_regex, actual_static_assert_error=actual_static_assert_error, 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)
    if ((actual_py2tmp_error_line_number > 6) or (actual_static_assert_error_line_number > 6)):
        pytest.fail(textwrap.dedent('                    The compilation failed with the expected message, but the error message contained too many lines before the relevant ones.\n                    The error type was reported on line {actual_py2tmp_error_line_number} of the message (should be <=6).\n                    The static assert was reported on line {actual_static_assert_error_line_number} of the message (should be <=6).\n                    Error message:\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 code:\n                    {cxx_source}\n                    '.format(actual_py2tmp_error_line_number=actual_py2tmp_error_line_number, actual_static_assert_error_line_number=actual_static_assert_error_line_number, 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)
    for line in error_message_lines[:max(actual_py2tmp_error_line_number, actual_static_assert_error_line_number)]:
        if re.search('tmppy::impl', line):
            pytest.fail(('The compilation failed with the expected message, but the error message contained some metaprogramming types in the output (besides Error). Error message:\n%s' + error_message_head), pytrace=False)
def check_error(e, error_message_lines, error_message_head, normalized_error_message_lines):
    for (line_number, line) in enumerate(normalized_error_message_lines):
        match = re.search('tmppy::impl::(.*Error<.*>)', line)
        if match:
            actual_py2tmp_error_line_number = line_number
            actual_py2tmp_error = match.groups()[0]
            if (config.CXX_COMPILER_NAME == 'MSVC'):
                try:
                    replacement_lines = []
                    if (normalized_error_message_lines[(line_number + 1)].strip() == 'with'):
                        for line in itertools.islice(normalized_error_message_lines, (line_number + 3), None):
                            line = line.strip()
                            if (line == ']'):
                                break
                            if line.endswith(','):
                                line = line[:(- 1)]
                            replacement_lines.append(line)
                    for replacement_line in replacement_lines:
                        match = re.search('([A-Za-z0-9_-]*)=(.*)', replacement_line)
                        if (not match):
                            raise Exception(('Failed to parse replacement line: %s' % replacement_line)) from e
                        (type_variable, type_expression) = match.groups()
                        actual_py2tmp_error = re.sub((('\\b' + type_variable) + '\\b'), type_expression, actual_py2tmp_error)
                except Exception:
                    raise Exception('Failed to parse MSVC template type arguments')
            break
    else:
        pytest.fail(textwrap.dedent('                    Expected error {expected_error} but the compiler output did not contain user-facing _py2tmp errors.\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 code:\n                    {cxx_source}\n                    ').format(expected_error=expected_py2tmp_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)
    for (line_number, line) in enumerate(error_message_lines):
        match = re.search(py2tmp_error_message_extraction_regex, line)
        if match:
            actual_static_assert_error_line_number = line_number
            actual_static_assert_error = match.groups()[0]
            break
    else:
        pytest.fail(textwrap.dedent('                    Expected error {expected_error} but the compiler output did not contain static_assert errors.\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 code:\n                    {cxx_source}\n                    ').format(expected_error=expected_py2tmp_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)
    try:
        regex_search_result = re.search(expected_py2tmp_error_regex, actual_py2tmp_error)
    except Exception as e:
        raise Exception(("re.search() failed for regex '%s'" % expected_py2tmp_error_regex)) from e
    if (not regex_search_result):
        pytest.fail(textwrap.dedent('                    The compilation failed as expected, but with a different error type.\n                    Expected _py2tmp error type:    {expected_py2tmp_error_regex}\n                    Error type was:               {actual_py2tmp_error}\n                    Expected static assert error: {expected_py2tmp_error_desc_regex}\n                    Static assert was:            {actual_static_assert_error}\n                    \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 code:\n                    {cxx_source}\n                    '.format(expected_py2tmp_error_regex=expected_py2tmp_error_regex, actual_py2tmp_error=actual_py2tmp_error, expected_py2tmp_error_desc_regex=expected_py2tmp_error_desc_regex, actual_static_assert_error=actual_static_assert_error, 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)
    try:
        regex_search_result = re.search(expected_py2tmp_error_desc_regex, actual_static_assert_error)
    except Exception as e:
        raise Exception(("re.search() failed for regex '%s'" % expected_py2tmp_error_desc_regex)) from e
    if (not regex_search_result):
        pytest.fail(textwrap.dedent('                    The compilation failed as expected, but with a different error message.\n                    Expected _py2tmp error type:    {expected_py2tmp_error_regex}\n                    Error type was:               {actual_py2tmp_error}\n                    Expected static assert error: {expected_py2tmp_error_desc_regex}\n                    Static assert was:            {actual_static_assert_error}\n                    \n                    Error message:\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 code:\n                    {cxx_source}\n                    '.format(expected_py2tmp_error_regex=expected_py2tmp_error_regex, actual_py2tmp_error=actual_py2tmp_error, expected_py2tmp_error_desc_regex=expected_py2tmp_error_desc_regex, actual_static_assert_error=actual_static_assert_error, 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)
    if ((actual_py2tmp_error_line_number > 6) or (actual_static_assert_error_line_number > 6)):
        pytest.fail(textwrap.dedent('                    The compilation failed with the expected message, but the error message contained too many lines before the relevant ones.\n                    The error type was reported on line {actual_py2tmp_error_line_number} of the message (should be <=6).\n                    The static assert was reported on line {actual_static_assert_error_line_number} of the message (should be <=6).\n                    Error message:\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 code:\n                    {cxx_source}\n                    '.format(actual_py2tmp_error_line_number=actual_py2tmp_error_line_number, actual_static_assert_error_line_number=actual_static_assert_error_line_number, 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)
    for line in error_message_lines[:max(actual_py2tmp_error_line_number, actual_static_assert_error_line_number)]:
        if re.search('tmppy::impl', line):
            pytest.fail(('The compilation failed with the expected message, but the error message contained some metaprogramming types in the output (besides Error). Error message:\n%s' + error_message_head), pytrace=False)