abseil / abseil/abseil-cpp

[Bug]: Status matchers: no support for printing std::wstring

オープン
#1,951 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
主要言語
C++
スター
18.1k
フォーク
3.2k
平均マージ
20時間 36分
マージ済み PR(30日)
1

説明

### Describe the issue

When matching a `StatusOr` with `IsOkAndHolds`, Googletest won't print the actual string contents.

### Steps to reproduce the problem

A Bazel workspace with:

MODULE.bazel:

```python
bazel_dep(name = "rules_cc", version = "0.2.9")
bazel_dep(name = "googletest", version = "1.17.0.bcr.1")
bazel_dep(name = "abseil-cpp", version = "20250814.1")
```

BUILD.bazel:

```python
load("@rules_cc//cc:cc_test.bzl", "cc_test")
cc_test(
name = "test",
srcs = ["test.cc"],
deps = [
"@abseil-cpp//absl/status:status_matchers",
"@abseil-cpp//absl/status:statusor",
"@googletest//:gtest",
"@googletest//:gtest_main",
],
)
```

test.cc:

```c++
#include

#include "absl/status/statusor.h"
#include "absl/status/status_matchers.h"
#include "gtest/gtest.h"

TEST(Test, WString) {
EXPECT_THAT(std::wstring(L"foo"), testing::Eq(L"bar"));
EXPECT_THAT(std::wstring(L"foo"), testing::Eq(std::wstring(L"bar")));
EXPECT_THAT(absl::StatusOr(std::wstring(L"foo")),
absl_testing::IsOkAndHolds(L"bar"));
EXPECT_THAT(absl::StatusOr(std::wstring(L"foo")),
absl_testing::IsOkAndHolds(std::wstring(L"bar")));
}
```

Running the test results in the following output:

```
Executing tests from //:test
-----------------------------------------------------------------------------
Running main() from gmock_main.cc
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from Test
[ RUN ] Test.WString
test.cc:8: Failure
Value of: std::wstring(L"foo")
Expected: is equal to 0x100d23a10 pointing to L"bar"
Actual: L"foo"

test.cc:9: Failure
Value of: std::wstring(L"foo")
Expected: is equal to L"bar"
Actual: L"foo"

test.cc:11: Failure
Value of: absl::StatusOr(std::wstring(L"foo"))
Expected: is OK and has a value that is equal to L"bar"
Actual: 32-byte object <01-00 00-00 00-00 00-00 66-00 00-00 6F-00 00-00 6F-00 00-00 00-00 00-00 68-ED F2-00 01-00 00-03>

test.cc:13: Failure
Value of: absl::StatusOr(std::wstring(L"foo"))
Expected: is OK and has a value that is equal to L"bar"
Actual: 32-byte object <01-00 00-00 00-00 00-00 66-00 00-00 6F-00 00-00 6F-00 00-00 00-00 00-00 00-E9 94-80 01-00 00-03>

[ FAILED ] Test.WString (0 ms)
[----------] 1 test from Test (0 ms total)

[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] Test.WString

1 FAILED TEST
```

Note that the normal string comparison (line 8 and 9) prints as expected, while the StatusOr check results in an unhelpful "Actual" message since apparently Googletest doesn't know how to print `StatusOr`.

### What version of Abseil are you using?

20250814.1

### What operating system and version are you using?

macOS Tahoe

### What compiler and version are you using?

Apple clang version 17.0.0 (clang-1700.3.19.1)
Target: arm64-apple-darwin25.0.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

### What build system are you using?

bazel 8.4.2

### Additional context

_No response_

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。