<commit_before>#===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===----------------------------------------------------------------------===##
"""Commands used to automate testing gdb pretty printers.

This script is part of a larger framework to test gdb pretty printers. It
runs the program, detects test cases, checks them, and prints results.

See gdb_pretty_printer_test.sh.cpp on how to write a test case.

"""

from __future__ import print_function
import re
import gdb

test_failures = 0


class CheckResult(gdb.Command):

    def __init__(self):
        super(CheckResult, self).__init__(
            "print_and_compare", gdb.COMMAND_DATA)

    def invoke(self, arg, from_tty):
        try:
            # Stack frame is:
            # 0. StopForDebugger
            # 1. ComparePrettyPrintToChars or ComparePrettyPrintToRegex
            # 2. TestCase
            compare_frame = gdb.newest_frame().older()
            testcase_frame = compare_frame.older()
            test_loc = testcase_frame.find_sal()
            # Use interactive commands in the correct context to get the pretty
            # printed version

            value_str = self._get_value_string(compare_frame, testcase_frame)

            # Ignore the convenience variable name and newline
            value = value_str[value_str.find("= ") + 2:-1]
            gdb.newest_frame().select()

            expectation_val = compare_frame.read_var("expectation")
            if "PrettyPrintToRegex" in compare_frame.name():
                check_literal = expectation_val.string()
                test_fails = not re.match(check_literal, value)
            else:
                check_literal_string = expectation_val.string(encoding="utf-8")
                check_literal = check_literal_string.encode("utf-8")
                test_fails = value != check_literal

            if test_fails:
                global test_failures<commit_msg>Fix libc++ pretty printer test for Python 3 after D67238<commit_after>#===----------------------------------------------------------------------===##
#
# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#
#===----------------------------------------------------------------------===##
"""Commands used to automate testing gdb pretty printers.

This script is part of a larger framework to test gdb pretty printers. It
runs the program, detects test cases, checks them, and prints results.

See gdb_pretty_printer_test.sh.cpp on how to write a test case.

"""

from __future__ import print_function
import re
import gdb

test_failures = 0


class CheckResult(gdb.Command):

    def __init__(self):
        super(CheckResult, self).__init__(
            "print_and_compare", gdb.COMMAND_DATA)

    def invoke(self, arg, from_tty):
        try:
            # Stack frame is:
            # 0. StopForDebugger
            # 1. ComparePrettyPrintToChars or ComparePrettyPrintToRegex
            # 2. TestCase
            compare_frame = gdb.newest_frame().older()
            testcase_frame = compare_frame.older()
            test_loc = testcase_frame.find_sal()
            # Use interactive commands in the correct context to get the pretty
            # printed version

            value_str = self._get_value_string(compare_frame, testcase_frame)

            # Ignore the convenience variable name and newline
            value = value_str[value_str.find("= ") + 2:-1]
            gdb.newest_frame().select()

            expectation_val = compare_frame.read_var("expectation")
            if "PrettyPrintToRegex" in compare_frame.name():
                check_literal = expectation_val.string()
                test_fails = not re.match(check_literal, value)
            else:
                check_literal_string = expectation_val.string(encoding="utf-8")
                check_literal = str(check_literal_string.encode("utf-8"))
                test_fails = value != check_literal

            if test_fails:
                global test_failures
{'fraction_non_alphanumeric': 0.14410681399631675, 'fraction_numerical': 0.006906077348066298, 'mean_word_length': 2.017361111111111, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5519022', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1114, 'n_words': 320}