Skip to content

Commit

Permalink
version 2.1.0 is up with the events
Browse files Browse the repository at this point in the history
  • Loading branch information
Dariush Hasapour committed Apr 27, 2020
1 parent 992f02e commit 8dec640
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
60 changes: 56 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ cmake .. && make

```c++
// lizard/tests/sample_tester.hpp
#ifndef SAMPLE_TESTER_HPP
#define SAMPLE_TESTER_HPP
#pragma once

#include "lizard/lizard.hpp"

Expand All @@ -45,10 +44,63 @@ TESTER(sample_tester,
IS_EQUAL(2 / 2, 1);
});
)

#endif
```

Event handlers
---
You can set some event handlers to catch up with the testing procedures, The list of events is as follow:

| Event | Description | Callback Signature |
|-------|-------------|--------------------|
| `onbefore` | Get called before starting any `spec` unit (right at the begining of the test unit.) -- suitable to loading resources before test unit. | `std::function<void()>` |
| `onafter` | Get called after `spec`s are done (right at the terminating the test unit / regardless of the termination status.) -- suitable to releasing resources at the end of test unit. | `std::function<void()>` |
| `onskip` | Gets invoked when a spec gets `skip`ped, The callback function's arguments are the `name` of the spec that has been skipped and the `skip` exception | `std::function<void(const std::string&, const std::exception&)>` |
| `onfail` | Gets invoked when a spec gets `fail`ed, The callback function's arguments are the `name` of the spec that has been failed and the `fail` exception | `std::function<void(const std::string&, const std::exception&)>` |
| `onprespec` | Get invoked right before a `spec` get started. The callback function's arguments are the `name` of the spec is going to get executed -- suitable to loading resources at the start of each `spec`. | `std::function<void(const std::string&)>` |
| `onpostspec` | Get invoked right after a `spec` get *finished* / *skipped* / *failed*. The callback function's arguments are the `name` of the spec dealt with -- suitable to releasing resources at the end of each `spec`. | `std::function<void(const std::string&)>` |

```c++
// lizard/tests/sample_tester.hpp
#pragma once

#include <iostream>
#include "lizard/lizard.hpp"

TESTER(sample_tester,

onbefore([]() {
std::cout << std::endl << "BEFORE ANY SPEC GOT STARTED!" << std::endl;
});

onbefore([]() {
std::cout << std::endl << "AFETR ALL SPECs GOT FINISHED!" << std::endl;
});

onskip([](auto name, auto err) {
std::cout << std::endl << "SKIPPED: " << name << " WITH MESSAGE: " << err.what() << std::endl;
});

onfail([](auto name, auto err) {
std::cout << std::endl << "FAILED: " << name << " WITH MESSAGE: " << err.what() << std::endl;
});

onprespec([](auto name) {
std::cout << std::endl << "STARTING SPEC: " << name << std::endl;
});

onpostspec([](auto name) {
std::cout << std::endl << "FINISHED SPEC: " << name << std::endl;
});

spec(sum, []() {
IS_EQUAL(1 + 2, 3);
});

spec(multiply, []() {
SKIP_WITH_MESSAGE("SKIP WITH MESSAGE");
});
)
```

Prerequisites
---
Expand Down
2 changes: 1 addition & 1 deletion lizard/lizard.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#define LIZARD_VERSION "2.0.2"
#define LIZARD_VERSION "2.1.0"

#include <string>
#include <vector>
Expand Down

0 comments on commit 8dec640

Please sign in to comment.