CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
112 lines
4.3 KiB
C++
112 lines
4.3 KiB
C++
#include "lldb/Host/common/DiagnosticsRendering.h"
|
|
#include "lldb/Utility/StreamString.h"
|
|
#include "gtest/gtest.h"
|
|
|
|
using namespace lldb_private;
|
|
using namespace lldb;
|
|
using llvm::StringRef;
|
|
namespace {
|
|
class ErrorDisplayTest : public ::testing::Test {};
|
|
|
|
std::string Render(std::vector<DiagnosticDetail> details) {
|
|
StreamString stream;
|
|
RenderDiagnosticDetails(stream, 0, true, details, /*force_ascii=*/true);
|
|
return stream.GetData();
|
|
}
|
|
} // namespace
|
|
|
|
TEST_F(ErrorDisplayTest, RenderStatus) {
|
|
using SourceLocation = DiagnosticDetail::SourceLocation;
|
|
{
|
|
SourceLocation inline_loc;
|
|
inline_loc.in_user_input = true;
|
|
std::string result =
|
|
Render({DiagnosticDetail{inline_loc, eSeverityError, "foo", ""}});
|
|
ASSERT_TRUE(StringRef(result).contains("error:"));
|
|
ASSERT_TRUE(StringRef(result).contains("foo"));
|
|
}
|
|
|
|
{
|
|
// Test that a single-character token (length=1) renders as just a caret
|
|
// with no underlines.
|
|
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 6, 1, false, true};
|
|
std::string result =
|
|
Render({DiagnosticDetail{loc1, eSeverityError, "X", "X"}});
|
|
llvm::SmallVector<StringRef> lines;
|
|
StringRef(result).split(lines, '\n');
|
|
// 123456
|
|
ASSERT_EQ(lines[0], " ^");
|
|
ASSERT_EQ(lines[1], " error: X");
|
|
}
|
|
{
|
|
// Test that diagnostics on the same column can be handled and all
|
|
// three errors are diagnosed.
|
|
SourceLocation loc1 = {FileSpec{"a.c"}, 13, 5, 0, false, true};
|
|
SourceLocation loc2 = {FileSpec{"a.c"}, 13, 7, 0, false, true};
|
|
SourceLocation loc3 = {FileSpec{"a.c"}, 13, 9, 0, false, true};
|
|
std::string result =
|
|
Render({DiagnosticDetail{loc1, eSeverityError, "1", "1"},
|
|
DiagnosticDetail{loc2, eSeverityError, "2a", "2a"},
|
|
DiagnosticDetail{loc2, eSeverityInfo, "2b", "2b"},
|
|
DiagnosticDetail{loc3, eSeverityError, "3", "3"}});
|
|
llvm::SmallVector<StringRef> lines;
|
|
StringRef(result).split(lines, '\n');
|
|
// 1234567890123
|
|
ASSERT_EQ(lines[0], " ^ ^ ^");
|
|
ASSERT_EQ(lines[1], " | | error: 3");
|
|
ASSERT_EQ(lines[2], " | error: 2a");
|
|
ASSERT_EQ(lines[3], " | note: 2b");
|
|
ASSERT_EQ(lines[4], " error: 1");
|
|
}
|
|
{
|
|
// Test that diagnostics in reverse order are emitted correctly.
|
|
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 20, 0, false, true};
|
|
SourceLocation loc2 = {FileSpec{"a.c"}, 2, 10, 0, false, true};
|
|
std::string result =
|
|
Render({DiagnosticDetail{loc2, eSeverityError, "X", "X"},
|
|
DiagnosticDetail{loc1, eSeverityError, "Y", "Y"}});
|
|
// Unintuitively the later diagnostic appears first in the string:
|
|
// ^ ^
|
|
// | second
|
|
// first
|
|
ASSERT_GT(StringRef(result).find("Y"), StringRef(result).find("X"));
|
|
}
|
|
{
|
|
// Test that diagnostics in reverse order are emitted correctly.
|
|
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 10, 0, false, true};
|
|
SourceLocation loc2 = {FileSpec{"a.c"}, 1, 20, 0, false, true};
|
|
std::string result =
|
|
Render({DiagnosticDetail{loc2, eSeverityError, "X", "X"},
|
|
DiagnosticDetail{loc1, eSeverityError, "Y", "Y"}});
|
|
ASSERT_GT(StringRef(result).find("Y"), StringRef(result).find("X"));
|
|
}
|
|
{
|
|
// Test that range diagnostics are emitted correctly.
|
|
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 1, 3, false, true};
|
|
SourceLocation loc2 = {FileSpec{"a.c"}, 1, 5, 3, false, true};
|
|
std::string result =
|
|
Render({DiagnosticDetail{loc1, eSeverityError, "X", "X"},
|
|
DiagnosticDetail{loc2, eSeverityError, "Y", "Y"}});
|
|
llvm::SmallVector<StringRef> lines;
|
|
StringRef(result).split(lines, '\n');
|
|
// 1234567
|
|
ASSERT_EQ(lines[0], "^~~ ^~~");
|
|
ASSERT_EQ(lines[1], "| error: Y");
|
|
ASSERT_EQ(lines[2], "error: X");
|
|
}
|
|
{
|
|
// Test diagnostics on the same line are emitted correctly.
|
|
SourceLocation loc1 = {FileSpec{"a.c"}, 1, 2, 0, false, true};
|
|
SourceLocation loc2 = {FileSpec{"a.c"}, 1, 6, 0, false, true};
|
|
std::string result =
|
|
Render({DiagnosticDetail{loc1, eSeverityError, "X", "X"},
|
|
DiagnosticDetail{loc2, eSeverityError, "Y", "Y"}});
|
|
llvm::SmallVector<StringRef> lines;
|
|
StringRef(result).split(lines, '\n');
|
|
// 1234567
|
|
ASSERT_EQ(lines[0], " ^ ^");
|
|
ASSERT_EQ(lines[1], " | error: Y");
|
|
ASSERT_EQ(lines[2], " error: X");
|
|
}
|
|
}
|