diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 19:57:41 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-22 20:02:19 -0700 |
commit | c3d2579ad8d7eb33059aa8fdbaf5b564411a57f2 (patch) | |
tree | 1570cda0676fdcf4171a69a7fe313c1b89a52b0c /vendor/bandit/specs/reporters/xunit_reporter.spec.cpp | |
parent | 986b7742bf244b4073ecca0723615f70be8a1ab6 (diff) | |
parent | 4e9b9c402ed95bf9a17fd6d795bc49bb4128a6fa (diff) |
Merge branch 'upstream' into debian-cmake-fixes
Diffstat (limited to 'vendor/bandit/specs/reporters/xunit_reporter.spec.cpp')
-rw-r--r-- | vendor/bandit/specs/reporters/xunit_reporter.spec.cpp | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/vendor/bandit/specs/reporters/xunit_reporter.spec.cpp b/vendor/bandit/specs/reporters/xunit_reporter.spec.cpp new file mode 100644 index 00000000..07f0c3b7 --- /dev/null +++ b/vendor/bandit/specs/reporters/xunit_reporter.spec.cpp @@ -0,0 +1,161 @@ +#include <specs/specs.h> +namespace bd = bandit::detail; + +go_bandit([](){ + + describe("xunit_reporter:", [&](){ + std::unique_ptr<std::stringstream> stm; + bd::default_failure_formatter formatter; + std::unique_ptr<bd::xunit_reporter> reporter; + + auto output = [&](){ return stm->str(); }; + + before_each([&](){ + stm = std::unique_ptr<std::stringstream>(new std::stringstream()); + reporter = std::unique_ptr<bd::xunit_reporter>(new bd::xunit_reporter(*stm, formatter)); + }); + + describe("an empty test run", [&](){ + + before_each([&](){ + reporter->test_run_starting(); + reporter->test_run_complete(); + }); + + it("adds a header to the output", [&](){ + AssertThat(output(), StartsWith("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n")); + }); + + it("outputs an empty test report", [&](){ + AssertThat(output(), Contains( + "<testsuite name=\"bandit\" tests=\"0\" errors=\"0\" failures=\"0\">\n" + "</testsuite>\n")); + }); + + }); + + describe("a test run with one, successful, test", [&](){ + + before_each([&](){ + reporter->test_run_starting(); + reporter->context_starting("my context"); + reporter->it_starting("my test"); + reporter->it_succeeded("my test"); + reporter->context_ended("my context"); + reporter->test_run_complete(); + }); + + it("outputs info about the successful test", [&](){ + AssertThat(output(), Contains( + "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"0\">\n" + "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n" + "\t</testcase>\n" + "</testsuite>\n")); + }); + }); + + describe("a test run with one, failing test", [&](){ + + before_each([&](){ + reporter->test_run_starting(); + reporter->context_starting("my context"); + reporter->it_starting("my test"); + + bd::assertion_exception exception("assertion failed!", "some_file", 123); + reporter->it_failed("my test", exception); + + reporter->context_ended("my context"); + reporter->test_run_complete(); + + }); + + it("outputs the failing test", [&](){ + AssertThat(output(), Contains( + "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"1\">\n" + "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n" + "\t\t<failure message=\"some_file:123: assertion failed!\" />\n" + "\t</testcase>\n" + "</testsuite>\n")); + }); + + }); + + describe("a test run with one test with an unknown error", [&](){ + + before_each([&](){ + reporter->test_run_starting(); + reporter->context_starting("my context"); + reporter->it_starting("my test"); + + reporter->it_unknown_error("my test"); + + reporter->context_ended("my context"); + reporter->test_run_complete(); + }); + + it("outputs the erroneous test", [&](){ + AssertThat(output(), Contains( + "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"1\">\n" + "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n" + "\t\t<failure message=\"Unknown exception\" />\n" + "\t</testcase>\n" + "</testsuite>\n")); + }); + + }); + + describe("a test run with one test failing with characters that need escaping", [&](){ + + before_each([&](){ + reporter->test_run_starting(); + reporter->context_starting("my context & < > \\ \""); + reporter->it_starting("my test & < > \\ \""); + + bd::assertion_exception exception("assertion failed & < > \\ \"", "some_file", 123); + reporter->it_failed("my test & < > \\ \"", exception); + + reporter->context_ended("my context & < > \\ \""); + reporter->test_run_complete(); + }); + + it("outputs the escaped characters", [&](){ + AssertThat(output(), Contains( + "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"1\">\n" + "\t<testcase classname=\"my context & < > ' "\" name=\"my test & < > ' "\" time=\"0\">\n" + "\t\t<failure message=\"some_file:123: assertion failed & < > ' "\" />\n" + "\t</testcase>\n" + "</testsuite>\n")); + }); + + }); + + describe("a context with a skipped test", [&](){ + + before_each([&](){ + reporter->test_run_starting(); + reporter->context_starting("my context"); + + reporter->it_starting("my test"); + reporter->it_succeeded("my test"); + reporter->it_skip("my skipped test"); + + reporter->context_ended("my context"); + reporter->test_run_complete(); + }); + + it("outputs info about the skipped test", [&](){ + AssertThat(output(), Contains( + "<testsuite name=\"bandit\" tests=\"1\" errors=\"0\" failures=\"0\" skipped=\"1\">\n" + "\t<testcase classname=\"my context\" name=\"my test\" time=\"0\">\n" + "\t</testcase>\n" + "\t<testcase classname=\"my context\" name=\"my skipped test\" time=\"0\">\n" + "\t\t<skipped />\n" + "\t</testcase>\n" + "</testsuite>\n")); + }); + + }); + + }); + +}); |