Skip to content

Commit

Permalink
test: add stacktrace print test with custom backend
Browse files Browse the repository at this point in the history
  • Loading branch information
DNKpp committed Dec 22, 2024
1 parent 2a85784 commit 173835e
Showing 1 changed file with 66 additions and 0 deletions.
66 changes: 66 additions & 0 deletions test/custom-stacktrace-tests/CustomStacktrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,69 @@ TEST_CASE(
}
}
}

TEST_CASE(
"Stacktrace is printable.",
"[stacktrace]")
{
using trompeloeil::_;
using traits_t = stacktrace_traits<CustomBackend>;
const Stacktrace stacktrace{CustomBackend{}};

SECTION("When stacktrace is empty")
{
REQUIRE_CALL(traits_t::emptyMock, Invoke(_))
.RETURN(true);

const auto text = mimicpp::print(stacktrace);
REQUIRE_THAT(
text,
Catch::Matchers::Equals("empty"));
}

SECTION("When stacktrace contains one entry.")
{
REQUIRE_CALL(traits_t::emptyMock, Invoke(_))
.RETURN(false);
REQUIRE_CALL(traits_t::sizeMock, Invoke(_))
.RETURN(1u);
REQUIRE_CALL(traits_t::sourceMock, Invoke(_, 0u))
.RETURN("test.cpp");
REQUIRE_CALL(traits_t::lineMock, Invoke(_, 0u))
.RETURN(1337u);
REQUIRE_CALL(traits_t::descriptionMock, Invoke(_, 0u))
.RETURN("Hello, World!");

const auto text = mimicpp::print(stacktrace);
REQUIRE_THAT(
text,
Catch::Matchers::Equals("test.cpp [1337], Hello, World!\n"));
}

SECTION("When stacktrace contains multiple entries.")
{
REQUIRE_CALL(traits_t::emptyMock, Invoke(_))
.RETURN(false);
REQUIRE_CALL(traits_t::sizeMock, Invoke(_))
.RETURN(2u);
REQUIRE_CALL(traits_t::sourceMock, Invoke(_, 0u))
.RETURN("other-test.cpp");
REQUIRE_CALL(traits_t::lineMock, Invoke(_, 0u))
.RETURN(42u);
REQUIRE_CALL(traits_t::descriptionMock, Invoke(_, 0u))
.RETURN("Hello, mimic++!");
REQUIRE_CALL(traits_t::sourceMock, Invoke(_, 1u))
.RETURN("test.cpp");
REQUIRE_CALL(traits_t::lineMock, Invoke(_, 1u))
.RETURN(1337u);
REQUIRE_CALL(traits_t::descriptionMock, Invoke(_, 1u))
.RETURN("Hello, World!");

const auto text = mimicpp::print(stacktrace);
REQUIRE_THAT(
text,
Catch::Matchers::Equals(
"other-test.cpp [42], Hello, mimic++!\n"
"test.cpp [1337], Hello, World!\n"));
}
}

0 comments on commit 173835e

Please sign in to comment.