google/googletest

GTest fails to print non-char basic_string_view

Open

#4,295 opened on Jun 21, 2023

View on GitHub
 (5 comments) (0 reactions) (0 assignees)C++ (38,603 stars) (10,772 forks)batch import
help wanted

Description

Describe the issue

This could be seen as a bug or a feature request. GTest fails to print std::basic_string_view<T> for any non-char T (e.g. wstring_view or u8string_view) which is a bit surprising since it does print anything else (wchar_t const*, char8_t const*, char16_t const*, char32_t const*, wstring, u8string, u16string, u32string).

There's also no good way to inject custom printers for this since adding them to either the std or testing::internal namespaces quickly introduces ODR-violations.

Steps to reproduce the problem

TEST(StringViewTest, Print)
{
    EXPECT_EQ("a"sv, ""sv);
    EXPECT_EQ(L"w"sv, L""sv);
    EXPECT_EQ(u8"u"sv, u8""sv);

    EXPECT_EQ("a"s, ""s);
    EXPECT_EQ(L"w"s, L""s);
    EXPECT_EQ(u8"u"s, u8""s);
}

which gives:

    #1 - Expected equality of these values:
  "a"sv
    Which is: "a"
  ""sv
    Which is: ""
#2 - Expected equality of these values:
  L"w"sv
    Which is: { L'w' (119, 0x77) }
  L""sv
    Which is: {}
#3 - Expected equality of these values:
  u8"u"sv
    Which is: { U+0075 }
  u8""sv
    Which is: {}
#4 - Expected equality of these values:
  "a"s
    Which is: "a"
  ""s
    Which is: ""
#5 - Expected equality of these values:
  L"w"s
    Which is: L"w"
  L""s
    Which is: L""
#6 - Expected equality of these values:
  u8"u"s
    Which is: u8"u"
  u8""s
    Which is: u8""

What version of GoogleTest are you using?

1.13.0

What operating system and version are you using?

Doesn't matter.

What compiler and version are you using?

Doesn't matter.

What build system are you using?

Doesn't matter.

Additional context

No response

Contributor guide