Add some tests for basic operations

This commit is contained in:
Jeremy Rifkin 2025-02-01 17:02:26 -06:00
parent 3cb7ef4ec5
commit 8a54330db4
No known key found for this signature in database
GPG Key ID: 19AA8270105E8EB4

View File

@ -199,4 +199,60 @@ TEST(FormatterTest, Filtering) {
); );
} }
TEST(FormatterTest, MoveSemantics) {
auto formatter = cpptrace::formatter{}
.set_filter([] (const cpptrace::stacktrace_frame& frame) -> bool {
return frame.filename.find("foo.cpp") != std::string::npos;
});
auto formatter2 = std::move(formatter);
auto res = split(formatter2.format(make_test_stacktrace()), "\n");
EXPECT_THAT(
res,
ElementsAre(
"Stack trace (most recent call first):",
"#0 0x0000000000000001 in foo() at foo.cpp:20:30",
"#2 0x0000000000000003 in main at foo.cpp:40:25"
)
);
cpptrace::formatter formatter3;
formatter3 = std::move(formatter);
auto res2 = split(formatter2.format(make_test_stacktrace()), "\n");
EXPECT_THAT(
res2,
ElementsAre(
"Stack trace (most recent call first):",
"#0 0x0000000000000001 in foo() at foo.cpp:20:30",
"#2 0x0000000000000003 in main at foo.cpp:40:25"
)
);
}
TEST(FormatterTest, CopySemantics) {
auto formatter = cpptrace::formatter{}
.set_filter([] (const cpptrace::stacktrace_frame& frame) -> bool {
return frame.filename.find("foo.cpp") != std::string::npos;
});
auto formatter2 = formatter;
auto res = split(formatter2.format(make_test_stacktrace()), "\n");
EXPECT_THAT(
res,
ElementsAre(
"Stack trace (most recent call first):",
"#0 0x0000000000000001 in foo() at foo.cpp:20:30",
"#2 0x0000000000000003 in main at foo.cpp:40:25"
)
);
cpptrace::formatter formatter3;
formatter3 = formatter;
auto res2 = split(formatter2.format(make_test_stacktrace()), "\n");
EXPECT_THAT(
res2,
ElementsAre(
"Stack trace (most recent call first):",
"#0 0x0000000000000001 in foo() at foo.cpp:20:30",
"#2 0x0000000000000003 in main at foo.cpp:40:25"
)
);
}
} }