Skip to content

Commit 1eeeab8

Browse files
authored
[lldb][test] Modernize assertEqual(value, bool) (llvm#82526)
Any time we see the pattern `assertEqual(value, bool)`, we can replace that with `assert<bool>(value)`. Likewise for `assertNotEqual`. Technically this relaxes the test a bit, as we may want to make sure `value` is either `True` or `False`, and not something that implicitly converts to a bool. For example, `assertEqual("foo", True)` will fail, but `assertTrue("foo")` will not. In most cases, this distinction is not important. There are two such places that this patch does **not** transform, since it seems intentional that we want the result to be a bool: * https://github.com/llvm/llvm-project/blob/5daf2001a1e4d71ce1273a1e7e31cf6e6ac37c10/lldb/test/API/python_api/sbstructureddata/TestStructuredDataAPI.py#L90 * https://github.com/llvm/llvm-project/blob/5daf2001a1e4d71ce1273a1e7e31cf6e6ac37c10/lldb/test/API/commands/settings/TestSettings.py#L940 Followup to 9c24688. I patched `teyit` with a `visit_assertEqual` node handler to generate this.
1 parent 0d12628 commit 1eeeab8

File tree

19 files changed

+95
-114
lines changed

19 files changed

+95
-114
lines changed

lldb/test/API/commands/expression/call-throws/TestCallThatThrows.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def call_function(self):
4646

4747
value = frame.EvaluateExpression("[my_class callMeIThrow]", options)
4848
self.assertTrue(value.IsValid())
49-
self.assertEqual(value.GetError().Success(), False)
49+
self.assertFalse(value.GetError().Success())
5050

5151
self.check_after_call()
5252

lldb/test/API/commands/expression/dont_allow_jit/TestAllowJIT.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def expr_options_test(self):
5454
# First make sure we can call the function with the default option set.
5555
options = lldb.SBExpressionOptions()
5656
# Check that the default is to allow JIT:
57-
self.assertEqual(options.GetAllowJIT(), True, "Default is true")
57+
self.assertTrue(options.GetAllowJIT(), "Default is true")
5858

5959
# Now use the options:
6060
result = frame.EvaluateExpression("call_me(10)", options)
@@ -64,9 +64,7 @@ def expr_options_test(self):
6464
# Now disallow JIT and make sure it fails:
6565
options.SetAllowJIT(False)
6666
# Check that we got the right value:
67-
self.assertEqual(
68-
options.GetAllowJIT(), False, "Got False after setting to False"
69-
)
67+
self.assertFalse(options.GetAllowJIT(), "Got False after setting to False")
7068

7169
# Again use it and ensure we fail:
7270
result = frame.EvaluateExpression("call_me(10)", options)
@@ -79,7 +77,7 @@ def expr_options_test(self):
7977

8078
# Finally set the allow JIT value back to true and make sure that works:
8179
options.SetAllowJIT(True)
82-
self.assertEqual(options.GetAllowJIT(), True, "Set back to True correctly")
80+
self.assertTrue(options.GetAllowJIT(), "Set back to True correctly")
8381

8482
# And again, make sure this works:
8583
result = frame.EvaluateExpression("call_me(10)", options)

lldb/test/API/commands/statistics/basic/TestStats.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,13 @@ def test_enable_disable(self):
3535
)
3636

3737
def verify_key_in_dict(self, key, d, description):
38-
self.assertEqual(
39-
key in d,
40-
True,
41-
'make sure key "%s" is in dictionary %s' % (key, description),
38+
self.assertIn(
39+
key, d, 'make sure key "%s" is in dictionary %s' % (key, description)
4240
)
4341

4442
def verify_key_not_in_dict(self, key, d, description):
45-
self.assertEqual(
46-
key in d,
47-
False,
48-
'make sure key "%s" is in dictionary %s' % (key, description),
43+
self.assertNotIn(
44+
key, d, 'make sure key "%s" is in dictionary %s' % (key, description)
4945
)
5046

5147
def verify_keys(self, dict, description, keys_exist, keys_missing=None):
@@ -120,9 +116,7 @@ def test_expressions_frame_var_counts(self):
120116
self.verify_success_fail_count(stats, "frameVariable", 1, 0)
121117

122118
# Test that "stopCount" is available when the process has run
123-
self.assertEqual(
124-
"stopCount" in stats, True, 'ensure "stopCount" is in target JSON'
125-
)
119+
self.assertIn("stopCount", stats, 'ensure "stopCount" is in target JSON')
126120
self.assertGreater(
127121
stats["stopCount"], 0, 'make sure "stopCount" is greater than zero'
128122
)
@@ -484,9 +478,9 @@ def test_dsym_binary_has_symfile_in_stats(self):
484478
exe = self.getBuildArtifact(exe_name)
485479
dsym = self.getBuildArtifact(exe_name + ".dSYM")
486480
# Make sure the executable file exists after building.
487-
self.assertEqual(os.path.exists(exe), True)
481+
self.assertTrue(os.path.exists(exe))
488482
# Make sure the dSYM file exists after building.
489-
self.assertEqual(os.path.isdir(dsym), True)
483+
self.assertTrue(os.path.isdir(dsym))
490484

491485
# Create the target
492486
target = self.createTestTarget(file_path=exe)
@@ -532,9 +526,9 @@ def test_no_dsym_binary_has_symfile_identifiers_in_stats(self):
532526
exe = self.getBuildArtifact(exe_name)
533527
dsym = self.getBuildArtifact(exe_name + ".dSYM")
534528
# Make sure the executable file exists after building.
535-
self.assertEqual(os.path.exists(exe), True)
529+
self.assertTrue(os.path.exists(exe))
536530
# Make sure the dSYM file doesn't exist after building.
537-
self.assertEqual(os.path.isdir(dsym), False)
531+
self.assertFalse(os.path.isdir(dsym))
538532

539533
# Create the target
540534
target = self.createTestTarget(file_path=exe)
@@ -585,11 +579,11 @@ def test_had_frame_variable_errors(self):
585579
dsym = self.getBuildArtifact(exe_name + ".dSYM")
586580
main_obj = self.getBuildArtifact("main.o")
587581
# Make sure the executable file exists after building.
588-
self.assertEqual(os.path.exists(exe), True)
582+
self.assertTrue(os.path.exists(exe))
589583
# Make sure the dSYM file doesn't exist after building.
590-
self.assertEqual(os.path.isdir(dsym), False)
584+
self.assertFalse(os.path.isdir(dsym))
591585
# Make sure the main.o object file exists after building.
592-
self.assertEqual(os.path.exists(main_obj), True)
586+
self.assertTrue(os.path.exists(main_obj))
593587

594588
# Delete the main.o file that contains the debug info so we force an
595589
# error when we run to main and try to get variables
@@ -604,7 +598,7 @@ def test_had_frame_variable_errors(self):
604598

605599
# Make sure we have "debugInfoHadVariableErrors" variable that is set to
606600
# false before failing to get local variables due to missing .o file.
607-
self.assertEqual(exe_stats["debugInfoHadVariableErrors"], False)
601+
self.assertFalse(exe_stats["debugInfoHadVariableErrors"])
608602

609603
# Verify that the top level statistic that aggregates the number of
610604
# modules with debugInfoHadVariableErrors is zero
@@ -624,7 +618,7 @@ def test_had_frame_variable_errors(self):
624618

625619
# Make sure we have "hadFrameVariableErrors" variable that is set to
626620
# true after failing to get local variables due to missing .o file.
627-
self.assertEqual(exe_stats["debugInfoHadVariableErrors"], True)
621+
self.assertTrue(exe_stats["debugInfoHadVariableErrors"])
628622

629623
# Verify that the top level statistic that aggregates the number of
630624
# modules with debugInfoHadVariableErrors is greater than zero

lldb/test/API/commands/trace/TestTraceSave.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,11 @@ def testSaveTrace(self):
179179
res = lldb.SBCommandReturnObject()
180180

181181
ci.HandleCommand("thread trace dump instructions -c 10 --forwards", res)
182-
self.assertEqual(res.Succeeded(), True)
182+
self.assertTrue(res.Succeeded())
183183
first_ten_instructions = res.GetOutput()
184184

185185
ci.HandleCommand("thread trace dump instructions -c 10", res)
186-
self.assertEqual(res.Succeeded(), True)
186+
self.assertTrue(res.Succeeded())
187187
last_ten_instructions = res.GetOutput()
188188

189189
# Now, save the trace to <trace_copy_dir>
@@ -203,11 +203,11 @@ def testSaveTrace(self):
203203

204204
# Compare with instructions saved at the first time
205205
ci.HandleCommand("thread trace dump instructions -c 10 --forwards", res)
206-
self.assertEqual(res.Succeeded(), True)
206+
self.assertTrue(res.Succeeded())
207207
self.assertEqual(res.GetOutput(), first_ten_instructions)
208208

209209
ci.HandleCommand("thread trace dump instructions -c 10", res)
210-
self.assertEqual(res.Succeeded(), True)
210+
self.assertTrue(res.Succeeded())
211211
self.assertEqual(res.GetOutput(), last_ten_instructions)
212212

213213
def testSaveKernelTrace(self):

lldb/test/API/functionalities/breakpoint/address_breakpoints/TestBadAddressBreakpoints.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def address_breakpoints(self):
4040
bkpt = target.BreakpointCreateByAddress(illegal_address)
4141
# Verify that breakpoint is not resolved.
4242
for bp_loc in bkpt:
43-
self.assertEqual(bp_loc.IsResolved(), False)
43+
self.assertFalse(bp_loc.IsResolved())
4444
else:
4545
self.fail(
4646
"Could not find an illegal address at which to set a bad breakpoint."

lldb/test/API/functionalities/breakpoint/breakpoint_command/TestBreakpointCommand.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,9 @@ def verify_source_map_deduce_statistics(self, target, expected_count):
572572
res = target.GetStatistics().GetAsJSON(stream)
573573
self.assertTrue(res.Success())
574574
debug_stats = json.loads(stream.GetData())
575-
self.assertEqual(
576-
"targets" in debug_stats,
577-
True,
575+
self.assertIn(
576+
"targets",
577+
debug_stats,
578578
'Make sure the "targets" key in in target.GetStatistics()',
579579
)
580580
target_stats = debug_stats["targets"][0]
@@ -659,9 +659,9 @@ def test_breakpoint_statistics_hitcount(self):
659659
res = target.GetStatistics().GetAsJSON(stream)
660660
self.assertTrue(res.Success())
661661
debug_stats = json.loads(stream.GetData())
662-
self.assertEqual(
663-
"targets" in debug_stats,
664-
True,
662+
self.assertIn(
663+
"targets",
664+
debug_stats,
665665
'Make sure the "targets" key in in target.GetStatistics()',
666666
)
667667
target_stats = debug_stats["targets"][0]

lldb/test/API/functionalities/breakpoint/breakpoint_names/TestBreakpointNames.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def do_check_configuring_names(self):
389389
)
390390

391391
def check_permission_results(self, bp_name):
392-
self.assertEqual(bp_name.GetAllowDelete(), False, "Didn't set allow delete.")
392+
self.assertFalse(bp_name.GetAllowDelete(), "Didn't set allow delete.")
393393
protected_bkpt = self.target.BreakpointCreateByLocation(self.main_file_spec, 10)
394394
protected_id = protected_bkpt.GetID()
395395

@@ -402,14 +402,11 @@ def check_permission_results(self, bp_name):
402402
self.assertSuccess(success, "Couldn't add this name to the breakpoint")
403403

404404
self.target.DisableAllBreakpoints()
405-
self.assertEqual(
406-
protected_bkpt.IsEnabled(),
407-
True,
408-
"Didnt' keep breakpoint from being disabled",
405+
self.assertTrue(
406+
protected_bkpt.IsEnabled(), "Didnt' keep breakpoint from being disabled"
409407
)
410-
self.assertEqual(
408+
self.assertFalse(
411409
unprotected_bkpt.IsEnabled(),
412-
False,
413410
"Protected too many breakpoints from disabling.",
414411
)
415412

@@ -418,14 +415,11 @@ def check_permission_results(self, bp_name):
418415
result = lldb.SBCommandReturnObject()
419416
self.dbg.GetCommandInterpreter().HandleCommand("break disable", result)
420417
self.assertTrue(result.Succeeded())
421-
self.assertEqual(
422-
protected_bkpt.IsEnabled(),
423-
True,
424-
"Didnt' keep breakpoint from being disabled",
418+
self.assertTrue(
419+
protected_bkpt.IsEnabled(), "Didnt' keep breakpoint from being disabled"
425420
)
426-
self.assertEqual(
421+
self.assertFalse(
427422
unprotected_bkpt.IsEnabled(),
428-
False,
429423
"Protected too many breakpoints from disabling.",
430424
)
431425

lldb/test/API/functionalities/gdb_remote_client/TestJLink6Armv7RegisterDefinition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def QListThreadsInStopReply(self):
198198
error = lldb.SBError()
199199
data = lldb.SBData()
200200
data.SetData(error, val, lldb.eByteOrderBig, 4)
201-
self.assertEqual(r1_valobj.SetData(data, error), True)
201+
self.assertTrue(r1_valobj.SetData(data, error))
202202
self.assertSuccess(error)
203203

204204
r1_valobj = process.GetThreadAtIndex(0).GetFrameAtIndex(0).FindRegister("r1")

lldb/test/API/functionalities/module_cache/simple_exe/TestModuleCacheSimple.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,16 @@ def test(self):
6666
# get a different creation and modification time for the file since some
6767
# OSs store the modification time in seconds since Jan 1, 1970.
6868
os.remove(exe)
69-
self.assertEqual(
70-
os.path.exists(exe),
71-
False,
72-
"make sure we were able to remove the executable",
69+
self.assertFalse(
70+
os.path.exists(exe), "make sure we were able to remove the executable"
7371
)
7472
time.sleep(2)
7573
# Now rebuild the binary so it has a different content which should
7674
# update the UUID to make the cache miss when it tries to load the
7775
# symbol table from the binary at the same path.
7876
self.build(dictionary={"CFLAGS_EXTRAS": "-DEXTRA_FUNCTION"})
79-
self.assertEqual(
80-
os.path.exists(exe), True, "make sure executable exists after rebuild"
77+
self.assertTrue(
78+
os.path.exists(exe), "make sure executable exists after rebuild"
8179
)
8280
# Make sure the modification time has changed or this test will fail.
8381
exe_mtime_2 = os.path.getmtime(exe)
@@ -99,9 +97,8 @@ def test(self):
9997
main_module = target.GetModuleAtIndex(0)
10098
self.assertTrue(main_module.IsValid())
10199
main_module.GetNumSymbols()
102-
self.assertEqual(
100+
self.assertTrue(
103101
os.path.exists(symtab_cache_path),
104-
True,
105102
'make sure "symtab" cache files exists after cache is updated',
106103
)
107104
symtab_mtime_2 = os.path.getmtime(symtab_cache_path)

lldb/test/API/functionalities/stats_api/TestStatisticsAPI.py

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,47 +33,47 @@ def test_stats_api(self):
3333
stream = lldb.SBStream()
3434
res = stats.GetAsJSON(stream)
3535
debug_stats = json.loads(stream.GetData())
36-
self.assertEqual(
37-
"targets" in debug_stats,
38-
True,
36+
self.assertIn(
37+
"targets",
38+
debug_stats,
3939
'Make sure the "targets" key in in target.GetStatistics()',
4040
)
41-
self.assertEqual(
42-
"modules" in debug_stats,
43-
True,
41+
self.assertIn(
42+
"modules",
43+
debug_stats,
4444
'Make sure the "modules" key in in target.GetStatistics()',
4545
)
4646
stats_json = debug_stats["targets"][0]
47-
self.assertEqual(
48-
"expressionEvaluation" in stats_json,
49-
True,
47+
self.assertIn(
48+
"expressionEvaluation",
49+
stats_json,
5050
'Make sure the "expressionEvaluation" key in in target.GetStatistics()["targets"][0]',
5151
)
52-
self.assertEqual(
53-
"frameVariable" in stats_json,
54-
True,
52+
self.assertIn(
53+
"frameVariable",
54+
stats_json,
5555
'Make sure the "frameVariable" key in in target.GetStatistics()["targets"][0]',
5656
)
5757
expressionEvaluation = stats_json["expressionEvaluation"]
58-
self.assertEqual(
59-
"successes" in expressionEvaluation,
60-
True,
58+
self.assertIn(
59+
"successes",
60+
expressionEvaluation,
6161
'Make sure the "successes" key in in "expressionEvaluation" dictionary"',
6262
)
63-
self.assertEqual(
64-
"failures" in expressionEvaluation,
65-
True,
63+
self.assertIn(
64+
"failures",
65+
expressionEvaluation,
6666
'Make sure the "failures" key in in "expressionEvaluation" dictionary"',
6767
)
6868
frameVariable = stats_json["frameVariable"]
69-
self.assertEqual(
70-
"successes" in frameVariable,
71-
True,
69+
self.assertIn(
70+
"successes",
71+
frameVariable,
7272
'Make sure the "successes" key in in "frameVariable" dictionary"',
7373
)
74-
self.assertEqual(
75-
"failures" in frameVariable,
76-
True,
74+
self.assertIn(
75+
"failures",
76+
frameVariable,
7777
'Make sure the "failures" key in in "frameVariable" dictionary"',
7878
)
7979

lldb/test/API/functionalities/thread/backtrace_limit/TestBacktraceLimit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ def test_backtrace_depth(self):
2323
interp.HandleCommand(
2424
"settings set target.process.thread.max-backtrace-depth 30", result
2525
)
26-
self.assertEqual(True, result.Succeeded())
26+
self.assertTrue(result.Succeeded())
2727
self.assertEqual(30, thread.GetNumFrames())

lldb/test/API/macosx/arm-corefile-regctx/TestArmMachoCorefileRegctx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def test_armv7_corefile(self):
2828
target = self.dbg.CreateTarget("")
2929
err = lldb.SBError()
3030
process = target.LoadCore(self.corefile)
31-
self.assertEqual(process.IsValid(), True)
31+
self.assertTrue(process.IsValid())
3232
thread = process.GetSelectedThread()
3333
frame = thread.GetSelectedFrame()
3434

@@ -51,7 +51,7 @@ def test_arm64_corefile(self):
5151
target = self.dbg.CreateTarget("")
5252
err = lldb.SBError()
5353
process = target.LoadCore(self.corefile)
54-
self.assertEqual(process.IsValid(), True)
54+
self.assertTrue(process.IsValid())
5555
thread = process.GetSelectedThread()
5656
frame = thread.GetSelectedFrame()
5757

lldb/test/API/macosx/lc-note/addrable-bits/TestAddrableBitsCorefile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_lc_note_addrable_bits(self):
2929
(target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
3030
self, "break here", lldb.SBFileSpec("main.c")
3131
)
32-
self.assertEqual(process.IsValid(), True)
32+
self.assertTrue(process.IsValid())
3333

3434
found_main = False
3535
for f in thread.frames:

0 commit comments

Comments
 (0)