Skip to content

Commit 32b9ed1

Browse files
committed
fixup! fix tests+reword diagnostics
1 parent 4dfc852 commit 32b9ed1

File tree

3 files changed

+62
-30
lines changed

3 files changed

+62
-30
lines changed

lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
#include "Plugins/LanguageRuntime/ObjC/ObjCLanguageRuntime.h"
9898
#include "Plugins/Platform/MacOSX/PlatformDarwin.h"
9999
#include "lldb/Utility/XcodeSDK.h"
100+
#include "lldb/lldb-enumerations.h"
100101

101102
#include <cctype>
102103
#include <memory>
@@ -550,6 +551,7 @@ static void SetupLangOpts(CompilerInstance &compiler,
550551
lldb_private::Language::GetNameForLanguageType(language));
551552

552553
lldb::LanguageType language_for_note = language;
554+
llvm::StringRef language_fallback_reason;
553555

554556
LangOptions &lang_opts = compiler.getLangOpts();
555557

@@ -564,14 +566,20 @@ static void SetupLangOpts(CompilerInstance &compiler,
564566
// family language, because the expression parser uses features of C++ to
565567
// capture values.
566568
lang_opts.CPlusPlus = true;
569+
567570
language_for_note = lldb::eLanguageTypeC_plus_plus;
571+
language_fallback_reason =
572+
"Expression evaluation in pure C not supported. ";
568573
break;
569574
case lldb::eLanguageTypeObjC:
570575
lang_opts.ObjC = true;
571576
// FIXME: the following language option is a temporary workaround,
572577
// to "ask for ObjC, get ObjC++" (see comment above).
573578
lang_opts.CPlusPlus = true;
579+
574580
language_for_note = lldb::eLanguageTypeObjC_plus_plus;
581+
language_fallback_reason =
582+
"Expression evaluation in pure Objective-C not supported. ";
575583

576584
// Clang now sets as default C++14 as the default standard (with
577585
// GNU extensions), so we do the same here to avoid mismatches that
@@ -613,26 +621,18 @@ static void SetupLangOpts(CompilerInstance &compiler,
613621
lang_opts.CPlusPlus = true;
614622
lang_opts.CPlusPlus11 = true;
615623
compiler.getHeaderSearchOpts().UseLibcxx = true;
624+
625+
language_for_note = lldb::eLanguageTypeObjC_plus_plus;
626+
language_fallback_reason = "Using default language. ";
616627
break;
617628
}
618629

619-
if (language_for_note != language)
620-
diagnostic_manager.AddDiagnostic(
621-
llvm::formatv(
622-
"Requested expression evaluation in '{0}' is not supported. Used "
623-
"'{1}' instead.",
624-
lldb_private::Language::GetDisplayNameForLanguageType(language),
625-
lldb_private::Language::GetDisplayNameForLanguageType(
626-
language_for_note))
627-
.str(),
628-
lldb::Severity::eSeverityInfo, DiagnosticOrigin::eDiagnosticOriginLLDB);
629-
else
630-
diagnostic_manager.AddDiagnostic(
631-
llvm::formatv(
632-
"Requested expression evaluation as '{0}'.",
633-
lldb_private::Language::GetDisplayNameForLanguageType(language))
634-
.str(),
635-
lldb::Severity::eSeverityInfo, DiagnosticOrigin::eDiagnosticOriginLLDB);
630+
diagnostic_manager.AddDiagnostic(
631+
llvm::formatv("{0}Ran expression as '{1}'.", language_fallback_reason,
632+
lldb_private::Language::GetDisplayNameForLanguageType(
633+
language_for_note))
634+
.str(),
635+
lldb::Severity::eSeverityInfo, DiagnosticOrigin::eDiagnosticOriginLLDB);
636636

637637
lang_opts.Bool = true;
638638
lang_opts.WChar = true;

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,12 @@ def check_error(diags):
215215

216216
details = diags.GetValueForKey("details")
217217

218-
# Detail 1/2: undeclared 'a'
218+
# Detail 1/3: note: requested expression language
219219
diag = details.GetItemAtIndex(0)
220+
self.assertEqual(str(diag.GetValueForKey("severity")), "note")
221+
222+
# Detail 2/3: undeclared 'a'
223+
diag = details.GetItemAtIndex(1)
220224

221225
severity = diag.GetValueForKey("severity")
222226
message = diag.GetValueForKey("message")
@@ -234,8 +238,8 @@ def check_error(diags):
234238
self.assertFalse(hidden.GetBooleanValue())
235239
self.assertTrue(in_user_input.GetBooleanValue())
236240

237-
# Detail 1/2: undeclared 'b'
238-
diag = details.GetItemAtIndex(1)
241+
# Detail 3/3: undeclared 'b'
242+
diag = details.GetItemAtIndex(2)
239243
message = diag.GetValueForKey("message")
240244
self.assertIn("undeclared identifier 'b'", str(message))
241245

lldb/test/API/python_api/interpreter/TestCommandInterpreterAPI.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,15 @@ def test_get_transcript(self):
156156
self.assertEqual(transcript[0]["error"], "")
157157

158158
# (lldb) an-unknown-command
159-
self.assertEqual(transcript[1],
159+
self.assertEqual(
160+
transcript[1],
160161
{
161162
"command": "an-unknown-command",
162163
# Unresolved commands don't have "commandName"/"commandArguments"
163164
"output": "",
164165
"error": "error: 'an-unknown-command' is not a valid command.\n",
165-
})
166+
},
167+
)
166168

167169
# (lldb) br s -f main.c -l <line>
168170
self.assertEqual(transcript[2]["command"], "br s -f main.c -l %d" % self.line)
@@ -175,14 +177,17 @@ def test_get_transcript(self):
175177
self.assertEqual(transcript[2]["error"], "")
176178

177179
# (lldb) p a
178-
self.assertEqual(transcript[3],
180+
self.assertEqual(
181+
transcript[3],
179182
{
180183
"command": "p a",
181184
"commandName": "dwim-print",
182185
"commandArguments": "-- a",
183186
"output": "",
184-
"error": "error: <user expression 0>:1:1: use of undeclared identifier 'a'\n 1 | a\n | ^\n",
185-
})
187+
"error": "note: Using default language. Ran expression as 'Objective C++'.\n"
188+
"error: <user expression 0>:1:1: use of undeclared identifier 'a'\n 1 | a\n | ^\n",
189+
},
190+
)
186191

187192
# (lldb) statistics dump
188193
self.assertEqual(transcript[4]["command"], "statistics dump")
@@ -203,7 +208,10 @@ def test_save_transcript_setting_default(self):
203208
self.assertTrue(ci, VALID_COMMAND_INTERPRETER)
204209

205210
# The setting's default value should be "false"
206-
self.runCmd("settings show interpreter.save-transcript", "interpreter.save-transcript (boolean) = false\n")
211+
self.runCmd(
212+
"settings show interpreter.save-transcript",
213+
"interpreter.save-transcript (boolean) = false\n",
214+
)
207215

208216
def test_save_transcript_setting_off(self):
209217
ci = self.dbg.GetCommandInterpreter()
@@ -250,17 +258,37 @@ def test_get_transcript_returns_copy(self):
250258
structured_data_1 = ci.GetTranscript()
251259
self.assertTrue(structured_data_1.IsValid())
252260
self.assertEqual(structured_data_1.GetSize(), 1)
253-
self.assertEqual(structured_data_1.GetItemAtIndex(0).GetValueForKey("command").GetStringValue(100), "version")
261+
self.assertEqual(
262+
structured_data_1.GetItemAtIndex(0)
263+
.GetValueForKey("command")
264+
.GetStringValue(100),
265+
"version",
266+
)
254267

255268
# Run some more commands and get the transcript as structured data again
256269
self.runCmd("help")
257270
structured_data_2 = ci.GetTranscript()
258271
self.assertTrue(structured_data_2.IsValid())
259272
self.assertEqual(structured_data_2.GetSize(), 2)
260-
self.assertEqual(structured_data_2.GetItemAtIndex(0).GetValueForKey("command").GetStringValue(100), "version")
261-
self.assertEqual(structured_data_2.GetItemAtIndex(1).GetValueForKey("command").GetStringValue(100), "help")
273+
self.assertEqual(
274+
structured_data_2.GetItemAtIndex(0)
275+
.GetValueForKey("command")
276+
.GetStringValue(100),
277+
"version",
278+
)
279+
self.assertEqual(
280+
structured_data_2.GetItemAtIndex(1)
281+
.GetValueForKey("command")
282+
.GetStringValue(100),
283+
"help",
284+
)
262285

263286
# Now, the first structured data should remain unchanged
264287
self.assertTrue(structured_data_1.IsValid())
265288
self.assertEqual(structured_data_1.GetSize(), 1)
266-
self.assertEqual(structured_data_1.GetItemAtIndex(0).GetValueForKey("command").GetStringValue(100), "version")
289+
self.assertEqual(
290+
structured_data_1.GetItemAtIndex(0)
291+
.GetValueForKey("command")
292+
.GetStringValue(100),
293+
"version",
294+
)

0 commit comments

Comments
 (0)