@@ -79,6 +79,7 @@ namespace testing {
79
79
constexpr inline char kNewMessage [] = " New test error message" ;
80
80
constexpr inline char kMessage [] = " Test error message" ;
81
81
constexpr inline char kFile [] = " test_file.cpp" ;
82
+ constexpr inline char kFunction [] = " foo" ;
82
83
constexpr inline char kEntryPrefix [] = " \n " ;
83
84
constexpr inline int32_t kLine = 42 ;
84
85
@@ -128,7 +129,7 @@ TEST_P(StatusTest, GetValueOrThrowWithErrorStatusOr) {
128
129
TEST_P (StatusTest, MaybeWithLocationPropagatesErrorStatus) {
129
130
absl::Status error_status = absl::InvalidArgumentError (kMessage );
130
131
absl::Status result =
131
- status_internal::MaybeWithLocation (error_status, kFile , kLine );
132
+ status_internal::MaybeWithLocation (error_status, kFile , kLine , kFunction );
132
133
133
134
ASSERT_FALSE (result.ok ());
134
135
EXPECT_EQ (result.code (), error_status.code ());
@@ -137,17 +138,17 @@ TEST_P(StatusTest, MaybeWithLocationPropagatesErrorStatus) {
137
138
if (IsShowCppStacktracesMode ()) {
138
139
EXPECT_NE (result, error_status);
139
140
EXPECT_EQ (GetStatusPropagationTrace (result),
140
- absl::StrCat (kEntryPrefix , " From: " , kFile , " : " , kLine ,
141
- " (error: " , kMessage , " )" ));
141
+ absl::StrCat (kEntryPrefix , " From: " , kFunction , " at " , kFile ,
142
+ " : " , kLine , " (error: " , kMessage , " )" ));
142
143
} else {
143
144
EXPECT_EQ (result, error_status);
144
145
}
145
146
}
146
147
147
148
TEST_P (StatusTest, MaybeWithNewMessageEmptyNewMessage) {
148
149
absl::Status error_status = absl::InvalidArgumentError (kMessage );
149
- absl::Status result =
150
- status_internal::MaybeWithNewMessage ( error_status, kFile , kLine );
150
+ absl::Status result = status_internal::MaybeWithNewMessage (
151
+ error_status, kFile , kLine , kFunction );
151
152
152
153
ASSERT_FALSE (result.ok ());
153
154
EXPECT_EQ (result.code (), error_status.code ());
@@ -156,7 +157,8 @@ TEST_P(StatusTest, MaybeWithNewMessageEmptyNewMessage) {
156
157
if (IsShowCppStacktracesMode ()) {
157
158
EXPECT_NE (result, error_status);
158
159
EXPECT_EQ (GetStatusPropagationTrace (result),
159
- absl::StrCat (kEntryPrefix , " From: " , kFile , " :" , kLine ));
160
+ absl::StrCat (kEntryPrefix , " From: " , kFunction , " at " , kFile ,
161
+ " :" , kLine ));
160
162
} else {
161
163
EXPECT_EQ (result, error_status);
162
164
}
@@ -165,7 +167,7 @@ TEST_P(StatusTest, MaybeWithNewMessageEmptyNewMessage) {
165
167
TEST_P (StatusTest, MaybeWithNewMessageNonEmptyNewMessage) {
166
168
absl::Status error_status = absl::InvalidArgumentError (kMessage );
167
169
absl::Status result = status_internal::MaybeWithNewMessage (
168
- error_status, kFile , kLine , kNewMessage );
170
+ error_status, kFile , kLine , kFunction , kNewMessage );
169
171
170
172
ASSERT_FALSE (result.ok ());
171
173
EXPECT_EQ (result.code (), error_status.code ());
@@ -174,8 +176,8 @@ TEST_P(StatusTest, MaybeWithNewMessageNonEmptyNewMessage) {
174
176
175
177
if (IsShowCppStacktracesMode ()) {
176
178
EXPECT_EQ (GetStatusPropagationTrace (result),
177
- absl::StrCat (kEntryPrefix , " From: " , kFile , " : " , kLine ,
178
- " (error: " , kNewMessage , " )" ));
179
+ absl::StrCat (kEntryPrefix , " From: " , kFunction , " at " , kFile ,
180
+ " : " , kLine , " (error: " , kNewMessage , " )" ));
179
181
}
180
182
}
181
183
@@ -230,10 +232,12 @@ TEST_P(StatusTest, MacroReturnIfErrorWithNestedError) {
230
232
EXPECT_EQ (result.message (), std::string_view (kMessage ));
231
233
232
234
if (IsShowCppStacktracesMode ()) {
233
- auto frame0 = absl::StrCat (kEntryPrefix , " From: " , __FILE__, " :" , errline0,
234
- " (error: " , kMessage , " )" );
235
- auto frame1 = absl::StrCat (kEntryPrefix , " From: " , __FILE__, " :" , errline1);
236
- auto frame2 = absl::StrCat (kEntryPrefix , " From: " , __FILE__, " :" , errline2);
235
+ auto frame0 = absl::StrCat (kEntryPrefix , " From: operator() at " , __FILE__,
236
+ " :" , errline0, " (error: " , kMessage , " )" );
237
+ auto frame1 = absl::StrCat (kEntryPrefix , " From: operator() at " , __FILE__,
238
+ " :" , errline1);
239
+ auto frame2 = absl::StrCat (kEntryPrefix , " From: operator() at " , __FILE__,
240
+ " :" , errline2);
237
241
EXPECT_EQ (GetStatusPropagationTrace (result),
238
242
absl::StrCat (frame0, frame1, frame2));
239
243
}
@@ -254,8 +258,8 @@ TEST_P(StatusTest, MacroReturnIfErrorWithErrorWithNewMessage) {
254
258
255
259
if (IsShowCppStacktracesMode ()) {
256
260
EXPECT_EQ (GetStatusPropagationTrace (result),
257
- absl::StrCat (kEntryPrefix , " From: " , __FILE__, " :" , errline ,
258
- " (error: " , kNewMessage , " )" ));
261
+ absl::StrCat (kEntryPrefix , " From: operator() at " , __FILE__, " :" ,
262
+ errline, " (error: " , kNewMessage , " )" ));
259
263
}
260
264
}
261
265
@@ -302,8 +306,8 @@ TEST_P(StatusTest, MacroAssignOrReturnWithErrorWithNewMessage) {
302
306
303
307
if (IsShowCppStacktracesMode ()) {
304
308
EXPECT_EQ (GetStatusPropagationTrace (result.status ()),
305
- absl::StrCat (kEntryPrefix , " From: " , __FILE__, " :" , errline ,
306
- " (error: " , kNewMessage , " )" ));
309
+ absl::StrCat (kEntryPrefix , " From: operator() at " , __FILE__, " :" ,
310
+ errline, " (error: " , kNewMessage , " )" ));
307
311
}
308
312
}
309
313
@@ -316,8 +320,8 @@ TEST_P(StatusTest, MacroErrorWithLocation) {
316
320
EXPECT_EQ (result.message (), std::string_view (kMessage ));
317
321
if (IsShowCppStacktracesMode ()) {
318
322
EXPECT_EQ (GetStatusPropagationTrace (result),
319
- absl::StrCat (kEntryPrefix , " From: " , __FILE__ , " : " , errline ,
320
- " (error: " , kMessage , " )" ));
323
+ absl::StrCat (kEntryPrefix , " From: " , __FUNCTION__ , " at " ,
324
+ __FILE__, " : " , errline, " (error: " , kMessage , " )" ));
321
325
}
322
326
}
323
327
@@ -356,10 +360,10 @@ TEST_P(StatusTest, MaybeThrowWithErrorPropagationWithNewMessage) {
356
360
//
357
361
std::string expected_prefix = absl::StrCat (
358
362
kNewMessage , " \n\n Status Propagation Trace:" , kEntryPrefix ,
359
- " From: " , __FILE__, " :" , errline0, " (error: " , kMessage , " ) " ,
360
- kEntryPrefix , " From: " , __FILE__, " :" , errline1,
361
- " (error: " , kNewMessage , " )" , kEntryPrefix , " From: " , __FILE__, " : " ,
362
- errline2, " \n\n C++ Stacktrace:\n " );
363
+ " From: operator() at " , __FILE__, " :" , errline0, " (error: " , kMessage ,
364
+ " ) " , kEntryPrefix , " From: operator() at " , __FILE__, " :" , errline1,
365
+ " (error: " , kNewMessage , " )" , kEntryPrefix , " From: operator() at " ,
366
+ __FILE__, " : " , errline2, " \n\n C++ Stacktrace:\n " );
363
367
364
368
EXPECT_THAT (throw_exception, ::testing::ThrowsMessage<std::runtime_error>(
365
369
::testing::StartsWith (expected_prefix)));
0 commit comments