google/googletest

GTest fails to print non-char basic_string_view

已關閉

#4,295 建立於 2023年6月21日

 (6 則留言) (0 個反應) (0 位負責人)C++ (10,772 個分叉)batch import
help wanted

倉庫指標

星標
 (38,603 顆星)
PR 合併指標
 (平均合併 7天 8小時) (30 天內合併 1 個 PR)

描述

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

貢獻者指南