<commit_before>"""
Test some lldb command abbreviations.
"""

import os, time
import unittest2
import lldb
from lldbtest import *

class AbbreviationsTestCase(TestBase):
    
    mydir = os.path.join("functionalities", "abbreviation")

    def test_nonrunning_command_abbreviations (self):
        self.expect("ap script",
                    startstr = "The following commands may relate to 'script':",
                    substrs = ['breakpoint command add',
                               'breakpoint command list',
                               'breakpoint list',
                               'command alias',
                               'expression',
                               'script'])

        self.runCmd("com a alias com al")
        self.runCmd("alias gurp help")
        self.expect("gurp target create",
                    substrs = ['Syntax: target create <cmd-options> <filename>'])
        self.runCmd("com u gurp")
        self.expect("gurp",
                    COMMAND_FAILED_AS_EXPECTED, error = True,
                    substrs = ["error: 'gurp' is not a valid command."])

        # Only one matching command: execute it.
        self.expect("h",
                    startstr = "The following is a list of built-in, permanent debugger commands:")

        # Several matching commands: list them and error out.
        self.expect("t",
                    COMMAND_FAILED_AS_EXPECTED, error = True,
                    substrs = ["Ambiguous command 't'. Possible matches:",
                               "target", "thread", "type"])

        self.expect("com sou ./change_prompt.lldb",
                    patterns = ["Executing commands in '.*change_prompt.lldb'"])

        self.expect("settings show prompt",
                    startstr = 'prompt (string) = "[with-three-trailing-spaces]   "')


        self.runCmd("settings clear prompt")
        self.expect("settings show prompt",
                    startstr = 'prompt (string) = "(lldb) "')


        self.expect("lo li",
                    startstr = "Logging categories for ")

        self.runCmd("se se prompt Sycamore> ")
        self.expect("se sh prompt",
                    startstr = 'prompt (string) = "Sycamore> "')

        self.runCmd("se cl prompt")
        self.expect("set sh prompt",
                    startstr = 'prompt (string) = "(lldb) "')

        # We don't want to display the stdout if not in TraceOn() mode.
        if not self.TraceOn():
            self.HideStdout()

        self.runCmd (r'''sc print "\n\n\tHello!\n"''')


    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
    @dsym_test
    def test_with_dsym (self):
        self.buildDsym ()
        self.running_abbreviations ()

    @dwarf_test
    def test_with_dwarf (self):
        self.buildDwarf ()
        self.running_abbreviations ()

    def running_abbreviations (self):
        exe = os.path.join (os.getcwd(), "a.out")
        self.expect("fil " + exe,
                    patterns = [ "Current executable set to .*a.out.*" ])

        self.expect("_regexp-b product",
                    substrs = [ "Breakpoint created: 1: name = 'product', locations = 1" ])

        self.expect("br s -n sum",
                    startstr = "Breakpoint created: 2: name = 'sum', locations = 1")

        self.expect("br s -f main.cpp -l 32",
                    startstr = "Breakpoint created: 3: file ='main.cpp', line = 32, locations = 1")
<commit_msg>Make a test scenario stronger, since, by default, the setting interpreter.expand-regex-aliases is false.<commit_after>"""
Test some lldb command abbreviations.
"""

import os, time
import unittest2
import lldb
from lldbtest import *

class AbbreviationsTestCase(TestBase):
    
    mydir = os.path.join("functionalities", "abbreviation")

    def test_nonrunning_command_abbreviations (self):
        self.expect("ap script",
                    startstr = "The following commands may relate to 'script':",
                    substrs = ['breakpoint command add',
                               'breakpoint command list',
                               'breakpoint list',
                               'command alias',
                               'expression',
                               'script'])

        self.runCmd("com a alias com al")
        self.runCmd("alias gurp help")
        self.expect("gurp target create",
                    substrs = ['Syntax: target create <cmd-options> <filename>'])
        self.runCmd("com u gurp")
        self.expect("gurp",
                    COMMAND_FAILED_AS_EXPECTED, error = True,
                    substrs = ["error: 'gurp' is not a valid command."])

        # Only one matching command: execute it.
        self.expect("h",
                    startstr = "The following is a list of built-in, permanent debugger commands:")

        # Several matching commands: list them and error out.
        self.expect("t",
                    COMMAND_FAILED_AS_EXPECTED, error = True,
                    substrs = ["Ambiguous command 't'. Possible matches:",
                               "target", "thread", "type"])

        self.expect("com sou ./change_prompt.lldb",
                    patterns = ["Executing commands in '.*change_prompt.lldb'"])

        self.expect("settings show prompt",
                    startstr = 'prompt (string) = "[with-three-trailing-spaces]   "')


        self.runCmd("settings clear prompt")
        self.expect("settings show prompt",
                    startstr = 'prompt (string) = "(lldb) "')


        self.expect("lo li",
                    startstr = "Logging categories for ")

        self.runCmd("se se prompt Sycamore> ")
        self.expect("se sh prompt",
                    startstr = 'prompt (string) = "Sycamore> "')

        self.runCmd("se cl prompt")
        self.expect("set sh prompt",
                    startstr = 'prompt (string) = "(lldb) "')

        # We don't want to display the stdout if not in TraceOn() mode.
        if not self.TraceOn():
            self.HideStdout()

        self.runCmd (r'''sc print "\n\n\tHello!\n"''')


    @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin")
    @dsym_test
    def test_with_dsym (self):
        self.buildDsym ()
        self.running_abbreviations ()

    @dwarf_test
    def test_with_dwarf (self):
        self.buildDwarf ()
        self.running_abbreviations ()

    def running_abbreviations (self):
        exe = os.path.join (os.getcwd(), "a.out")
        self.expect("fil " + exe,
                    patterns = [ "Current executable set to .*a.out.*" ])

        # By default, the setting interpreter.expand-regex-aliases is false.
        self.expect("_regexp-b product", matching=False,
                    substrs = [ "breakpoint set --name 'product'" ])

        self.expect("br s -n sum",
                    startstr = "Breakpoint created: 2: name = 'sum', locations = 1")

        self.expect("br s -f main.cpp -l 32",
                    startstr = "Breakpoint created: 3: file ='main.cpp', line = 32, locations = 1")

{'fraction_non_alphanumeric': 0.11927252220499084, 'fraction_numerical': 0.0031016495136049625, 'mean_word_length': 1.8139627132090441, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, 'https://': 0, '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': '3397907', 'n_tokens_mistral': 2059, 'n_tokens_neox': 1910, 'n_words': 533}