Skip to content

Commit 39d6b6c

Browse files
committed
[lldb][NFC] Migrate several tests to expect_expr
expect_expr is the stricter and safer way of testing these expressions.
1 parent 00c74d0 commit 39d6b6c

File tree

21 files changed

+70
-175
lines changed

21 files changed

+70
-175
lines changed

lldb/packages/Python/lldbsuite/test/commands/expression/anonymous-struct/TestCallUserAnonTypedef.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ def test(self):
4141
)
4242

4343
self.runCmd("run", RUN_SUCCEEDED)
44-
self.expect("expr multiply(&s)", substrs=['$0 = 1'])
44+
self.expect_expr("multiply(&s)", result_type="double", result_value="1")

lldb/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallBuiltinFunction.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@ def test(self):
3434

3535
self.runCmd("run", RUN_SUCCEEDED)
3636

37-
interp = self.dbg.GetCommandInterpreter()
38-
result = lldb.SBCommandReturnObject()
39-
4037
# Test different builtin functions.
4138

4239
self.expect_expr("__builtin_isinf(0.0f)", result_type="int", result_value="0")

lldb/packages/Python/lldbsuite/test/commands/expression/call-function/TestCallUserDefinedFunction.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,15 @@ def test(self):
3939
self.runCmd("run", RUN_SUCCEEDED)
4040

4141
# Test recursive function call.
42-
self.expect("expr fib(5)", substrs=['$0 = 5'])
42+
self.expect_expr("fib(5)", result_type="unsigned int", result_value="5")
4343

4444
# Test function with more than one paramter
45-
self.expect("expr add(4,8)", substrs=['$1 = 12'])
45+
self.expect_expr("add(4, 8)", result_type="int", result_value="12")
4646

4747
# Test nesting function calls in function paramters
48-
self.expect("expr add(add(5,2),add(3,4))", substrs=['$2 = 14'])
49-
self.expect("expr add(add(5,2),fib(5))", substrs=['$3 = 12'])
48+
self.expect_expr("add(add(5,2),add(3,4))", result_type="int", result_value="14")
49+
self.expect_expr("add(add(5,2),fib(5))", result_type="int", result_value="12")
5050

5151
# Test function with pointer paramter
52-
self.expect(
53-
"exp stringCompare((const char*) \"Hello world\")",
54-
substrs=['$4 = true'])
55-
self.expect(
56-
"exp stringCompare((const char*) \"Hellworld\")",
57-
substrs=['$5 = false'])
52+
self.expect_expr('stringCompare((const char*) \"Hello world\")', result_type="bool", result_value="true")
53+
self.expect_expr('stringCompare((const char*) \"Hellworld\")', result_type="bool", result_value="false")

lldb/packages/Python/lldbsuite/test/commands/expression/call-overridden-method/TestCallOverriddenMethod.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ def test_call_on_base(self):
4040

4141
# Test call to method in base class (this should always work as the base
4242
# class method is never an override).
43-
self.expect("expr b->foo()", substrs=["= 2"])
43+
self.expect_expr("b->foo()", result_type="int", result_value="2")
4444

4545
# Test calling the base class.
46-
self.expect("expr realbase.foo()", substrs=["= 1"])
46+
self.expect_expr("realbase.foo()", result_type="int", result_value="1")
4747

4848
@skipIfLinux # Returns wrong result code on some platforms.
4949
def test_call_on_derived(self):
@@ -61,7 +61,7 @@ def test_call_on_derived(self):
6161
# Test call to overridden method in derived class (this will fail if the
6262
# overrides table is not correctly set up, as Derived::foo will be assigned
6363
# a vtable entry that does not exist in the compiled program).
64-
self.expect("expr d.foo()", substrs=["= 2"])
64+
self.expect_expr("d.foo()", result_type="int", result_value="2")
6565

6666
@skipIf(oslist=["linux"], archs=["aarch64"])
6767
@expectedFailureAll(oslist=["windows"], bugnumber="llvm.org/pr43707")
@@ -78,5 +78,5 @@ def test_call_on_temporary(self):
7878
self.runCmd("run", RUN_SUCCEEDED)
7979

8080
# Test with locally constructed instances.
81-
self.expect("expr Base().foo()", substrs=["= 1"])
82-
self.expect("expr Derived().foo()", substrs=["= 2"])
81+
self.expect_expr("Base().foo()", result_type="int", result_value="1")
82+
self.expect_expr("Derived().foo()", result_type="int", result_value="2")

lldb/packages/Python/lldbsuite/test/commands/expression/class_template_specialization_empty_pack/TestClassTemplateSpecializationParametersHandling.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,4 @@ def test_class_template_specialization(self):
1919

2020
lldbutil.run_to_source_breakpoint(self, '// break here',
2121
lldb.SBFileSpec("main.cpp", False))
22-
23-
self.expect("expr -u 0 -- b.foo()", substrs=['$0 = 1'])
22+
self.expect_expr("b.foo()", result_type="int", result_value="1")

lldb/packages/Python/lldbsuite/test/commands/expression/entry-bp/TestExprEntryBP.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,4 @@ def test_expr_entry_bp(self):
2626
entry_bp = target.BreakpointCreateBySBAddress(entry)
2727
self.assertTrue(entry_bp.IsValid(), "Can't set a breakpoint on the module entry point")
2828

29-
result = target.EvaluateExpression("sum(7, 1)")
30-
self.assertTrue(result.IsValid(), "Can't evaluate expression")
31-
self.assertEqual(8, result.GetValueAsSigned())
32-
29+
self.expect_expr("sum(7, 1)", result_type="int", result_value="8")

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/basic/TestImportStdModule.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def test(self):
2222
# Activate importing of std module.
2323
self.runCmd("settings set target.import-std-module true")
2424
# Calling some normal std functions that return non-template types.
25-
self.expect("expr std::abs(-42)", substrs=['(int) $0 = 42'])
26-
self.expect("expr std::div(2, 1).quot", substrs=['(int) $1 = 2'])
25+
self.expect_expr("std::abs(-42)", result_type="int", result_value="42")
26+
self.expect_expr("std::div(2, 1).quot", result_type="int", result_value="2")
2727
# Using types from std.
28-
self.expect("expr (std::size_t)33U", substrs=['(size_t) $2 = 33'])
28+
self.expect_expr("(std::size_t)33U", result_type="size_t", result_value="33")
2929
# Calling templated functions that return non-template types.
30-
self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",
31-
substrs=["(char) $3 = 'a'"])
30+
self.expect_expr("char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",
31+
result_type="char", result_value="'a'")
3232

3333
@add_test_categories(["libc++"])
3434
@skipIf(compiler=no_match("clang"))

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/conflicts/TestStdModuleWithConflicts.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ def test(self):
2525
"// Set break point at this line.", lldb.SBFileSpec("main.cpp"))
2626

2727
self.runCmd("settings set target.import-std-module true")
28-
self.expect("expr std::abs(-42)", substrs=['(int) $0 = 42'])
29-
self.expect("expr std::div(2, 1).quot", substrs=['(int) $1 = 2'])
30-
self.expect("expr (std::size_t)33U", substrs=['(size_t) $2 = 33'])
28+
self.expect_expr("std::abs(-42)", result_type="int", result_value="42")
29+
self.expect_expr("std::div(2, 1).quot", result_type="int", result_value="2")
30+
self.expect_expr("(std::size_t)33U", result_type="size_t", result_value="33")
3131
self.expect("expr char char_a = 'b'; char char_b = 'a'; std::swap(char_a, char_b); char_a",
3232
substrs=["(char) $3 = 'a'"])

lldb/packages/Python/lldbsuite/test/commands/expression/import-std-module/deque-basic/TestBasicDeque.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ def test(self):
2020

2121
self.runCmd("settings set target.import-std-module true")
2222

23-
self.expect("expr (size_t)a.size()", substrs=['(size_t) $0 = 3'])
24-
self.expect("expr (int)a.front()", substrs=['(int) $1 = 3'])
25-
self.expect("expr (int)a.back()", substrs=['(int) $2 = 2'])
23+
self.expect_expr("(size_t)a.size()", result_type="size_t", result_value="3")
24+
self.expect_expr("(int)a.front()", result_type="int", result_value="3")
25+
self.expect_expr("(int)a.back()", result_type="int", result_value="2")
2626

2727
self.expect("expr std::sort(a.begin(), a.end())")
28-
self.expect("expr (int)a.front()", substrs=['(int) $3 = 1'])
29-
self.expect("expr (int)a.back()", substrs=['(int) $4 = 3'])
28+
self.expect_expr("(int)a.front()", result_type="int", result_value="1")
29+
self.expect_expr("(int)a.back()", result_type="int", result_value="3")
3030

3131
self.expect("expr std::reverse(a.begin(), a.end())")
32-
self.expect("expr (int)a.front()", substrs=['(int) $5 = 3'])
33-
self.expect("expr (int)a.back()", substrs=['(int) $6 = 1'])
32+
self.expect_expr("(int)a.front()", result_type="int", result_value="3")
33+
self.expect_expr("(int)a.back()", result_type="int", result_value="1")
3434

35-
self.expect("expr (int)(*a.begin())", substrs=['(int) $7 = 3'])
36-
self.expect("expr (int)(*a.rbegin())", substrs=['(int) $8 = 1'])
35+
self.expect_expr("(int)(*a.begin())", result_type="int", result_value="3")
36+
self.expect_expr("(int)(*a.rbegin())", result_type="int", result_value="1")
3737

lldb/packages/Python/lldbsuite/test/commands/expression/inline-namespace/TestInlineNamespace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test(self):
2020

2121
# The 'A::B::f' function must be found via 'A::f' as 'B' is an inline
2222
# namespace.
23-
self.expect("expr A::f()", substrs=['$0 = 3'])
23+
self.expect_expr("A::f()", result_type="int", result_value="3")
2424
# But we should still find the function when we pretend the inline
2525
# namespace is not inline.
26-
self.expect("expr A::B::f()", substrs=['$1 = 3'])
26+
self.expect_expr("A::B::f()", result_type="int", result_value="3")

0 commit comments

Comments
 (0)