[Lldb-commits] [PATCH] D150772: Add code snippet line numbers to TestExprDiagnostics output

Timm Bäder via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Wed May 17 07:19:31 PDT 2023


tbaeder updated this revision to Diff 523045.
tbaeder added a comment.

Updated the test and split up the expected output into multiple lines so it's easier to read.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150772/new/

https://reviews.llvm.org/D150772

Files:
  lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py


Index: lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
===================================================================
--- lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
+++ lldb/test/API/commands/expression/diagnostics/TestExprDiagnostics.py
@@ -1,5 +1,5 @@
 """
-Test the diagnostics emitted by our embeded Clang instance that parses expressions.
+Test the diagnostics emitted by our embedded Clang instance that parses expressions.
 """
 
 import lldb
@@ -29,20 +29,21 @@
         self.assertFalse(value.GetError().Success())
         # We should get a nice diagnostic with a caret pointing at the start of
         # the identifier.
-        self.assertIn("\nunknown_identifier\n^\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | unknown_identifier\n      | ^\n", value.GetError().GetCString())
         self.assertIn("<user expression 0>:1:1", value.GetError().GetCString())
 
         # Same as above but with the identifier in the middle.
         value = frame.EvaluateExpression("1 + unknown_identifier  ")
         self.assertFalse(value.GetError().Success())
-        self.assertIn("\n1 + unknown_identifier", value.GetError().GetCString())
-        self.assertIn("\n    ^\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | 1 + unknown_identifier", value.GetError().GetCString())
+        self.assertIn("\n      |     ^\n", value.GetError().GetCString())
 
         # Multiline expressions.
         value = frame.EvaluateExpression("int a = 0;\nfoobar +=1;\na")
         self.assertFalse(value.GetError().Success())
         # We should still get the right line information and caret position.
-        self.assertIn("\nfoobar +=1;\n^\n", value.GetError().GetCString())
+        self.assertIn("\n    2 | foobar +=1;\n", value.GetError().GetCString())
+        self.assertIn("\n      | ^\n", value.GetError().GetCString())
         # It's the second line of the user expression.
         self.assertIn("<user expression 2>:2:1", value.GetError().GetCString())
 
@@ -52,7 +53,8 @@
 
         value = frame.EvaluateExpression("void foo(unknown_type x) {}", top_level_opts)
         self.assertFalse(value.GetError().Success())
-        self.assertIn("\nvoid foo(unknown_type x) {}\n         ^\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | void foo(unknown_type x) {}\n", value.GetError().GetCString())
+        self.assertIn("\n      |          ^\n", value.GetError().GetCString())
         # Top-level expressions might use a different wrapper code, but the file name should still
         # be the same.
         self.assertIn("<user expression 3>:1:10", value.GetError().GetCString())
@@ -60,31 +62,44 @@
         # Multiline top-level expressions.
         value = frame.EvaluateExpression("void x() {}\nvoid foo;", top_level_opts)
         self.assertFalse(value.GetError().Success())
-        self.assertIn("\nvoid foo;\n     ^", value.GetError().GetCString())
+        self.assertIn("\n    2 | void foo;\n", value.GetError().GetCString())
+        self.assertIn("\n      |      ^", value.GetError().GetCString())
         self.assertIn("<user expression 4>:2:6", value.GetError().GetCString())
 
         # Test that we render Clang's 'notes' correctly.
         value = frame.EvaluateExpression("struct SFoo{}; struct SFoo { int x; };", top_level_opts)
         self.assertFalse(value.GetError().Success())
-        self.assertIn("<user expression 5>:1:8: previous definition is here\nstruct SFoo{}; struct SFoo { int x; };\n       ^\n", value.GetError().GetCString())
+        self.assertIn("<user expression 5>:1:8: previous definition is here\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | struct SFoo{}; struct SFoo { int x; };\n", value.GetError().GetCString())
+        self.assertIn("\n      |        ^\n", value.GetError().GetCString())
 
         # Declarations from the debug information currently have no debug information. It's not clear what
         # we should do in this case, but we should at least not print anything that's wrong.
         # In the future our declarations should have valid source locations.
         value = frame.EvaluateExpression("struct FooBar { double x };", top_level_opts)
         self.assertFalse(value.GetError().Success())
-        self.assertIn("error: <user expression 6>:1:8: redefinition of 'FooBar'\nstruct FooBar { double x };\n       ^\n", value.GetError().GetCString())
+        self.assertIn("error: <user expression 6>:1:8: redefinition of 'FooBar'\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | struct FooBar { double x };\n", value.GetError().GetCString())
+        self.assertIn("\n      |        ^\n", value.GetError().GetCString())
 
         value = frame.EvaluateExpression("foo(1, 2)")
         self.assertFalse(value.GetError().Success())
-        self.assertIn("error: <user expression 7>:1:1: no matching function for call to 'foo'\nfoo(1, 2)\n^~~\nnote: candidate function not viable: requires single argument 'x', but 2 arguments were provided\n\n", value.GetError().GetCString())
+        self.assertIn("error: <user expression 7>:1:1: no matching function for call to 'foo'\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | foo(1, 2)\n", value.GetError().GetCString())
+        self.assertIn("\n      | ^~~\n", value.GetError().GetCString())
+        self.assertIn("\nnote: candidate function not viable: requires single argument 'x', but 2 arguments were provided\n\n", value.GetError().GetCString())
 
         # Redefine something that we defined in a user-expression. We should use the previous expression file name
         # for the original decl.
         value = frame.EvaluateExpression("struct Redef { double x; };", top_level_opts)
         value = frame.EvaluateExpression("struct Redef { float y; };", top_level_opts)
         self.assertFalse(value.GetError().Success())
-        self.assertIn("error: <user expression 9>:1:8: redefinition of 'Redef'\nstruct Redef { float y; };\n       ^\n<user expression 8>:1:8: previous definition is here\nstruct Redef { double x; };\n       ^", value.GetError().GetCString())
+        self.assertIn("error: <user expression 9>:1:8: redefinition of 'Redef'\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | struct Redef { float y; };\n", value.GetError().GetCString())
+        self.assertIn("\n      |        ^\n", value.GetError().GetCString())
+        self.assertIn("\n<user expression 8>:1:8: previous definition is here\n", value.GetError().GetCString())
+        self.assertIn("\n    1 | struct Redef { double x; };\n", value.GetError().GetCString())
+        self.assertIn("\n      |        ^\n", value.GetError().GetCString())
 
     @add_test_categories(["objc"])
     def test_source_locations_from_objc_modules(self):


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150772.523045.patch
Type: text/x-patch
Size: 6861 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20230517/1f935328/attachment-0001.bin>


More information about the lldb-commits mailing list