File: TestBackticksInAlias.py

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (100 lines) | stat: -rw-r--r-- 4,510 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
Test that an alias can contain active backticks
"""


import lldb
from lldbsuite.test.lldbtest import *
import lldbsuite.test.lldbutil as lldbutil


class TestBackticksInAlias(TestBase):
    NO_DEBUG_INFO_TESTCASE = True

    def test_backticks_in_alias(self):
        """Test that an alias can contain active backticks."""
        self.build()
        (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
            self, "break here", lldb.SBFileSpec("main.c")
        )
        interp = self.dbg.GetCommandInterpreter()
        result = lldb.SBCommandReturnObject()
        interp.HandleCommand(
            "command alias _test-argv-cmd expression -Z \`argc\` -- argv", result
        )
        self.assertCommandReturn(result, "Made the alias")
        interp.HandleCommand("_test-argv-cmd", result)
        self.assertCommandReturn(result, "The alias worked")

        # Now try a harder case where we create this using an alias:
        interp.HandleCommand(
            "command alias _test-argv-parray-cmd parray \`argc\` argv", result
        )
        self.assertCommandReturn(result, "Made the alias")
        interp.HandleCommand("_test-argv-parray-cmd", result)
        self.assertFalse(
            result.Succeeded(),
            "CommandAlias::Desugar currently fails if a alias substitutes %N arguments in another alias",
        )

    def test_backticks_in_parsed_cmd_argument(self):
        """break list is a parsed command, use a variable for the breakpoint number
        and make sure that and the direct use of the ID get the same result."""
        self.build()
        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, "break here", lldb.SBFileSpec("main.c")
        )
        # Make a second breakpoint so that if the backtick part -> nothing we'll print too much:
        # It doesn't need to resolve to anything.
        dummy_bkpt = target.BreakpointCreateByName("dont_really_care_if_this_exists")

        bkpt_id = bkpt.GetID()
        self.runCmd(f"expr int $number = {bkpt_id}")
        direct_result = lldb.SBCommandReturnObject()
        backtick_result = lldb.SBCommandReturnObject()
        interp = self.dbg.GetCommandInterpreter()
        interp.HandleCommand(f"break list {bkpt_id}", direct_result)
        self.assertTrue(direct_result.Succeeded(), "Break list with id works")
        interp.HandleCommand("break list `$number`", backtick_result)
        self.assertTrue(direct_result.Succeeded(), "Break list with backtick works")
        self.assertEqual(
            direct_result.GetOutput(), backtick_result.GetOutput(), "Output is the same"
        )

    def test_backticks_in_parsed_cmd_option(self):
        # The script interpreter is a raw command, so try that one:
        self.build()
        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, "break here", lldb.SBFileSpec("main.c")
        )

        self.runCmd(f"expr int $number = 2")
        direct_result = lldb.SBCommandReturnObject()
        backtick_result = lldb.SBCommandReturnObject()
        interp = self.dbg.GetCommandInterpreter()
        interp.HandleCommand(f"memory read --count 2 argv", direct_result)
        self.assertTrue(
            direct_result.Succeeded(), "memory read with direct count works"
        )
        interp.HandleCommand("memory read --count `$number` argv", backtick_result)
        self.assertTrue(direct_result.Succeeded(), "memory read with backtick works")
        self.assertEqual(
            direct_result.GetOutput(), backtick_result.GetOutput(), "Output is the same"
        )

    def test_backticks_in_raw_cmd(self):
        # The script interpreter is a raw command, so try that one:
        self.build()
        target, process, thread, bkpt = lldbutil.run_to_source_breakpoint(
            self, "break here", lldb.SBFileSpec("main.c")
        )
        argc_valobj = thread.frames[0].FindVariable("argc")
        self.assertTrue(argc_valobj.GetError().Success(), "Made argc valobj")
        argc_value = argc_valobj.GetValueAsUnsigned(0)
        self.assertNotEqual(argc_value, 0, "Got a value for argc")
        result = lldb.SBCommandReturnObject()
        interp = self.dbg.GetCommandInterpreter()
        interp.HandleCommand(f"script {argc_value} - `argc`", result)
        self.assertTrue(result.Succeeded(), "Command succeeded")
        fixed_output = result.GetOutput().rstrip()
        self.assertEqual("0", fixed_output, "Substitution worked")