Skip to content

Commit

Permalink
d Add docs for doctest integration - see #11
Browse files Browse the repository at this point in the history
Co-Authored-By: Llewellyn Falco <[email protected]>
  • Loading branch information
claremacrae and isidore committed Jul 29, 2019
1 parent 1807399 commit 43a29d7
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 17 deletions.
4 changes: 2 additions & 2 deletions ApprovalTests_DocTest_Tests/main.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// startcode doctest_main
// begin-snippet: doctest_main
// main.cpp:
#define APPROVALS_DOCTEST // This tells Approval Tests to provide a main() - only do this in one cpp file
#include "ApprovalTests.hpp"
// endcode
// end-snippet
14 changes: 3 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Currently working in Mac/Linux/Windows with
* [Catch2](https://github.com/catchorg/Catch2)
* [Okra](https://github.com/JayBazuzi/Okra) & C++ 11
* [GoogleTest](https://github.com/google/googletest)
* [doctest](https://github.com/onqtam/doctest)



Expand All @@ -73,22 +74,13 @@ For catch (1 and 2), it's these two lines:
<sup>[snippet source](/ApprovalTests_Catch2_Tests/main.cpp#L6-L10)</sup>
<!-- endsnippet -->
For Google Test, it's these:
<!-- snippet: googletest_main -->
```cpp
// main.cpp:
#define APPROVALS_GOOGLETEST // This tells Approval Tests to provide a main() - only do this in one cpp file
#include "ApprovalTests.hpp"
```
<sup>[snippet source](/ApprovalTests_GoogleTest_Tests/main.cpp#L2-L6)</sup>
<!-- endsnippet -->

For all other test files, you need:
``` cpp
#include "ApprovalTests.hpp"
```

For other frameworks, check out our [Getting Started](/doc/GettingStarted.md#top) page.

## Examples
ApprovalTests uses ApprovalTests to test ApprovalTests (it's turtles all the way down).
[Checkout our own tests](https://github.com/approvals/ApprovalTests.cpp/tree/master/ApprovalTests_Catch2_Tests) to see how we do it.
Expand Down
18 changes: 18 additions & 0 deletions doc/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ To change this file edit the source file and then run MarkdownSnippets.
* [Introduction](#introduction)
* [Catch 1 and 2](#catch-1-and-2)
* [Google Test](#google-test)
* [doctest](#doctest)
* [Choosing a testing framework](#choosing-a-testing-framework)
<!-- endtoc -->


Expand All @@ -36,6 +38,22 @@ See [Getting Started With Catch 1 and 2](/doc/UsingCatch.md#getting-started-with

See [Getting Started With Google Test](/doc/UsingGoogleTests.md#getting-started-with-google-test)

## doctest

See [Getting Started With doctest](/doc/UsingDoctest.md#getting-started-with-doctest)

## Choosing a testing framework

If you are already using one of the above testing frameworks, that is the one you should use.

If not, Approval Tests works well with all the above. Here are factors to consider.

| Framework | Ease of setup | IDE Integration | Compile and link time |
| --- | --- | --- | --- |
| Catch | Very easy (single-header). [StarterProject](https://github.com/approvals/ApprovalTests.Cpp.StarterProject) | Widely supported | Not bad - has options to speed up |
| doctest | Very easy (single-header) | Unknown | Fast |
| Google Test | Difficult (requires | Very widely supported | Fast |

---

[Back to User Guide](/doc/README.md#top)
49 changes: 49 additions & 0 deletions doc/UsingDoctest.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!--
GENERATED FILE - DO NOT EDIT
This file was generated by [MarkdownSnippets](https://github.com/SimonCropp/MarkdownSnippets).
Source File: /doc/mdsource/UsingDoctest.source.md
To change this file edit the source file and then run MarkdownSnippets.
-->

<a id="top"></a>

# Using Approval Tests With doctest


<!-- toc -->
## Contents

* [Getting Started With doctest](#getting-started-with-doctest)
* [New Project](#new-project)
<!-- endtoc -->




## Getting Started With doctest

The [doctest](https://github.com/onqtam/doctest) test framework works fairly well with Approval Tests.

Doctest is similar to Catch, but claims to give faster compilation times.

### New Project

Create a file `main.cpp` and add just the following two lines:

<!-- snippet: doctest_main -->
```cpp
// main.cpp:
#define APPROVALS_DOCTEST // This tells Approval Tests to provide a main() - only do this in one cpp file
#include "ApprovalTests.hpp"
```
<sup>[snippet source](/ApprovalTests_DocTest_Tests/main.cpp#L1-L5)</sup>
<!-- endsnippet -->
**Note**: currently, ApprovalTests overrides any `--reporter` command-line argument supplied.
This is needed for ApprovalTests to function with doctest. The ApprovalTests reporter works like doctest's `console` reporter. This means that it is not possible to run ApprovalTests with the doctest test framework, and use reporters such as `xml`.
We currently do not have a better workaround.
---
[Back to User Guide](/doc/README.md#top)
16 changes: 16 additions & 0 deletions doc/mdsource/GettingStarted.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,22 @@ See [Getting Started With Catch 1 and 2](/doc/UsingCatch.md#getting-started-with

See [Getting Started With Google Test](/doc/UsingGoogleTests.md#getting-started-with-google-test)

## doctest

See [Getting Started With doctest](/doc/UsingDoctest.md#getting-started-with-doctest)

## Choosing a testing framework

If you are already using one of the above testing frameworks, that is the one you should use.

If not, Approval Tests works well with all the above. Here are factors to consider.

| Framework | Ease of setup | IDE Integration | Compile and link time |
| --- | --- | --- | --- |
| Catch | Very easy (single-header). [StarterProject](https://github.com/approvals/ApprovalTests.Cpp.StarterProject) | Widely supported | Not bad - has options to speed up |
| doctest | Very easy (single-header) | Unknown | Fast |
| Google Test | Difficult (requires | Very widely supported | Fast |

---

[Back to User Guide](/doc/README.md#top)
29 changes: 29 additions & 0 deletions doc/mdsource/UsingDoctest.source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<a id="top"></a>

# Using Approval Tests With doctest


toc



## Getting Started With doctest

The [doctest](https://github.com/onqtam/doctest) test framework works fairly well with Approval Tests.

Doctest is similar to Catch, but claims to give faster compilation times.

### New Project

Create a file `main.cpp` and add just the following two lines:

snippet: doctest_main

**Note**: currently, ApprovalTests overrides any `--reporter` command-line argument supplied.
This is needed for ApprovalTests to function with doctest. The ApprovalTests reporter works like doctest's `console` reporter. This means that it is not possible to run ApprovalTests with the doctest test framework, and use reporters such as `xml`.

We currently do not have a better workaround.

---

[Back to User Guide](/doc/README.md#top)
7 changes: 3 additions & 4 deletions mdsource/README.source.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Currently working in Mac/Linux/Windows with
* [Catch2](https://github.com/catchorg/Catch2)
* [Okra](https://github.com/JayBazuzi/Okra) & C++ 11
* [GoogleTest](https://github.com/google/googletest)
* [doctest](https://github.com/onqtam/doctest)



Expand All @@ -49,15 +50,13 @@ For catch (1 and 2), it's these two lines:

snippet: catch_2_main

For Google Test, it's these:

snippet: googletest_main

For all other test files, you need:
``` cpp
#include "ApprovalTests.hpp"
```

For other frameworks, check out our [Getting Started](/doc/GettingStarted.md#top) page.

## Examples
ApprovalTests uses ApprovalTests to test ApprovalTests (it's turtles all the way down).
[Checkout our own tests](https://github.com/approvals/ApprovalTests.cpp/tree/master/ApprovalTests_Catch2_Tests) to see how we do it.
Expand Down

0 comments on commit 43a29d7

Please sign in to comment.