Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GTest fails to print non-char basic_string_view #4295

Open
gix opened this issue Jun 21, 2023 · 3 comments · May be fixed by #4624
Open

GTest fails to print non-char basic_string_view #4295

gix opened this issue Jun 21, 2023 · 3 comments · May be fixed by #4624

Comments

@gix
Copy link

gix commented Jun 21, 2023

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

@rabroldan
Copy link

Hi there is it okay if I try this one out?

@XAMeLeOH XAMeLeOH linked a pull request Oct 3, 2024 that will close this issue
@XAMeLeOH
Copy link

XAMeLeOH commented Oct 3, 2024

Here is the example. Compare the output for string_view's as opposed to the stirng's. I replaced the u8 strings 'cause apparently the library itself was compiled without support of u8, so the linker complains about a missing function. Instead I threw in some u and U strings.

I hope that #4624 fixes it

@XAMeLeOH
Copy link

@derekmauro could you please take a look at the proposed fix (#4624)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants