Skip to content

Commit 69f7b57

Browse files
committed
More explicit documentation on Runners
1 parent a7c7744 commit 69f7b57

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ __Note:__ Only the tests require being compiled with C++14 support (`-std=c++14`
3333
If you've ever used RSpec or Jasmine, chances are you'll be familiar with C++Spec's syntax. For example, this is a C++Spec version of the first snippet on RSpec's [README](https://github.com/rspec/rspec-core/blob/master/README.md#basic-structure).
3434

3535
```c++
36+
#include "cppspec.hpp"
37+
#include "order.hpp"
38+
3639
describe order_spec("Order", $ {
3740
it("sums the prices of its line items", _ {
3841
Order order();
@@ -50,6 +53,13 @@ describe order_spec("Order", $ {
5053
});
5154
});
5255

56+
57+
int main(){
58+
return CppSpec::Runner(CppSpec::Formatters::verbose)
59+
.add_spec(order_spec)
60+
.exec() ? EXIT_SUCCESS : EXIT_FAILURE;
61+
}
62+
5363
```
5464
5565
## FAQ ##

docs/testing.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Testing
2+
3+
Running tests requires a `Description` object to provide the spec. Each spec is independent.
4+
5+
Tests are added to a `Runner` manually, which is passed a `Formatter` object on instantiation.
6+
7+
Once a spec has been added to a `Runner`, the runner is then executed, returning a `Result` object.
8+
9+
`Result` objects are able to be implicitly casted to `bool`, and can thus be used for returning
10+
directly from the `main` function.
11+
12+
13+
## Formatters
14+
15+
There are a number of `Formatter` subclasses for printing to a terminal, including `Verbose`, `Progress`, and `TAP`. `Progress` prints out as a serious of periods, while `Verbose` prints a
16+
fully RSpec-like list of tests, coloring them to show their status and result.
17+
18+
## Example
19+
20+
Here's an example spec and the associated runner:
21+
22+
```c++
23+
#include <cstdlib>
24+
#include "cppspec.hpp"
25+
26+
describe strcmp_spec("int strcmp ( const char * str1, const char * str2 )", $ {
27+
auto greater_than_zero = [](int i){return i>=0;};
28+
auto less_than_zero = [](int i){return i<0;};
29+
30+
it("returns 0 only when strings are equal", _ {
31+
expect(strcmp("hello", "hello")).to_equal(0);
32+
});
33+
34+
it("returns a negative integer when str1 is less than str2", _ {
35+
expect(strcmp("hello", "world")).to_satisfy(less_than_zero);
36+
expect(strcmp("0123", "1321431")).to_satisfy(less_than_zero);
37+
});
38+
39+
it("returns a positive integer if str1 is greater than str2", _ {
40+
expect(strcmp("yellow", "world")).to_satisfy(greater_than_zero);
41+
expect(strcmp("9", "789")).to_satisfy(greater_than_zero);
42+
});
43+
});
44+
45+
46+
int main(){
47+
return CppSpec::Runner(CppSpec::Formatters::verbose)
48+
.add_spec(strcmp_spec)
49+
.exec() ? EXIT_SUCCESS : EXIT_FAILURE;
50+
}
51+
52+
```

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ pages:
1616
- Befores and Afters: syntax/before_after.md
1717
- Expect: syntax/expect.md
1818
# - Matchers:
19+
- Testing: testing.md
1920

2021
markdown_extensions:
2122
- admonition:

0 commit comments

Comments
 (0)