Skip to content

Commit

Permalink
add aborts example
Browse files Browse the repository at this point in the history
Change-Id: I7a799f7b06e8bc8f09bbbe33e624103817d8464e
  • Loading branch information
oliverlee committed Dec 27, 2023
1 parent 1782d62 commit db9f273
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions example/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,13 @@ cc_test(
deps = [":skytest_wrapper"],
)

cc_binary(
name = "aborts",
srcs = ["aborts.cpp"],
features = ["-opt"],
deps = [":skytest_wrapper"],
)

update_targets = [
":minimal_pass_log.update.sh",
":minimal_fail_log.update.sh",
Expand Down
14 changes: 14 additions & 0 deletions example/aborts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "skytest/skytest.hpp"

#include <cassert>

auto main() -> int
{
using namespace ::skytest::literals;
using ::skytest::aborts;
using ::skytest::expect;

static const auto not_zero = [](int value) { assert(value != 0); };

"aborts"_test = [] { return expect(aborts([] { not_zero(0); })); };
}
10 changes: 10 additions & 0 deletions scripts/README.md.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,15 @@ If parameters are defined as a literal-type[^2], C++20 allows use of `param`:

</details>

#### aborts
<details><summary></summary>

Check that abort is called (e.g. in a function precondition)

```cpp:example/aborts.cpp
```

</details>

[^1]: The default printer uses `std::cout` and `skytest::aborts` calls `fork`.
[^2]: https://en.cppreference.com/w/cpp/named_req/LiteralType

0 comments on commit db9f273

Please sign in to comment.