]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/abbreviation/TestAbbreviations.py
Vendor import of lldb trunk r256945:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / abbreviation / TestAbbreviations.py
1 """
2 Test some lldb command abbreviations and aliases for proper resolution.
3 """
4
5 from __future__ import print_function
6
7
8
9 import os, time
10 import lldb
11 from lldbsuite.test.lldbtest import *
12 import lldbsuite.test.lldbutil as lldbutil
13
14 class AbbreviationsTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     @expectedFlakeyFreeBSD("llvm.org/pr22611 thread race condition breaks prompt setting")
19     @no_debug_info_test
20     def test_command_abbreviations_and_aliases (self):
21         command_interpreter = self.dbg.GetCommandInterpreter()
22         self.assertTrue(command_interpreter, VALID_COMMAND_INTERPRETER)
23         result = lldb.SBCommandReturnObject()
24
25         # Check that abbreviations are expanded to the full command.
26         command_interpreter.ResolveCommand("ap script", result)
27         self.assertTrue(result.Succeeded())
28         self.assertEqual("apropos script", result.GetOutput())
29
30         command_interpreter.ResolveCommand("h", result)
31         self.assertTrue(result.Succeeded())
32         self.assertEqual("help", result.GetOutput())
33
34         # Check resolution of abbreviations for multi-word commands.
35         command_interpreter.ResolveCommand("lo li", result)
36         self.assertTrue(result.Succeeded())
37         self.assertEqual("log list", result.GetOutput())
38
39         command_interpreter.ResolveCommand("br s", result)
40         self.assertTrue(result.Succeeded())
41         self.assertEqual("breakpoint set", result.GetOutput())
42
43         # Try an ambiguous abbreviation.
44         # "pl" could be "platform" or "plugin".
45         command_interpreter.ResolveCommand("pl", result)
46         self.assertFalse(result.Succeeded())
47         self.assertTrue(result.GetError().startswith("Ambiguous command"))
48
49         # Make sure an unabbreviated command is not mangled.
50         command_interpreter.ResolveCommand("breakpoint set --name main --line 123", result)
51         self.assertTrue(result.Succeeded())
52         self.assertEqual("breakpoint set --name main --line 123", result.GetOutput())
53
54         # Create some aliases.
55         self.runCmd("com a alias com al")
56         self.runCmd("alias gurp help")
57
58         # Check that an alias is replaced with the actual command
59         command_interpreter.ResolveCommand("gurp target create", result)
60         self.assertTrue(result.Succeeded())
61         self.assertEqual("help target create", result.GetOutput())
62
63         # Delete the alias and make sure it no longer has an effect.
64         self.runCmd("com u gurp")
65         command_interpreter.ResolveCommand("gurp", result)
66         self.assertFalse(result.Succeeded())
67
68         # Check aliases with text replacement.
69         self.runCmd("alias pltty process launch -s -o %1 -e %1")
70         command_interpreter.ResolveCommand("pltty /dev/tty0", result)
71         self.assertTrue(result.Succeeded())
72         self.assertEqual("process launch -s -o /dev/tty0 -e /dev/tty0", result.GetOutput())
73
74         self.runCmd("alias xyzzy breakpoint set -n %1 -l %2")
75         command_interpreter.ResolveCommand("xyzzy main 123", result)
76         self.assertTrue(result.Succeeded())
77         self.assertEqual("breakpoint set -n main -l 123", result.GetOutput().strip())
78
79         # And again, without enough parameters.
80         command_interpreter.ResolveCommand("xyzzy main", result)
81         self.assertFalse(result.Succeeded())
82
83         # Check a command that wants the raw input.
84         command_interpreter.ResolveCommand(r'''sc print("\n\n\tHello!\n")''', result)
85         self.assertTrue(result.Succeeded())
86         self.assertEqual(r'''script print("\n\n\tHello!\n")''', result.GetOutput())
87
88         # Prompt changing stuff should be tested, but this doesn't seem like the
89         # right test to do it in.  It has nothing to do with aliases or abbreviations.
90         #self.runCmd("com sou ./change_prompt.lldb")
91         #self.expect("settings show prompt",
92         #            startstr = 'prompt (string) = "[with-three-trailing-spaces]   "')
93         #self.runCmd("settings clear prompt")
94         #self.expect("settings show prompt",
95         #            startstr = 'prompt (string) = "(lldb) "')
96         #self.runCmd("se se prompt 'Sycamore> '")
97         #self.expect("se sh prompt",
98         #            startstr = 'prompt (string) = "Sycamore> "')
99         #self.runCmd("se cl prompt")
100         #self.expect("set sh prompt",
101         #            startstr = 'prompt (string) = "(lldb) "')