Skip to content

Commit 23d784d

Browse files
claremacraeisidore
andcommitted
d Document new features
Co-Authored-By: Llewellyn Falco <[email protected]>
1 parent a1a9b1e commit 23d784d

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

doc/Features.md

+60
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,70 @@ To change this file edit the source file and then re-run the generation using ei
1313
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1414
**Contents**
1515

16+
- [Blocking Reporter](#blocking-reporter)
17+
- [Machine Blockers](#machine-blockers)
18+
- [Front Loaded Reporters](#front-loaded-reporters)
1619
- [Using sub-directories for approved files](#using-sub-directories-for-approved-files)
1720

1821
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1922

23+
## Blocking Reporter
24+
25+
Blocking reporters are a simple class, designed for use with FrontLoadedReporters, to prevent launching of reporters in certain environments.
26+
27+
<!-- snippet: do_not_report_on_ci -->
28+
```cpp
29+
// main.cpp
30+
auto frontLoadedReportDisposer = Approvals::useAsFrontLoadedReporter(
31+
BlockingReporter::onMachinesNotNamed("MyCIMachineName") );
32+
```
33+
<sup>[snippet source](/examples/googletest_existing_main/main.cpp#L19-L23)</sup>
34+
<!-- endsnippet -->
35+
36+
## Machine Blockers
37+
38+
Sometimes you will want tests to only run on certain machines. Machine blockers are a great way to do this.
39+
40+
<!-- snippet: machine_specific_test_runner -->
41+
```cpp
42+
TEST_CASE("Only run this test on John's machine")
43+
{
44+
auto blocker = MachineBlocker::onMachinesNotNamed("JOHNS_MACHINE");
45+
if ( blocker.isBlockingOnThisMachine() )
46+
{
47+
return;
48+
}
49+
// Write tests here that depend on John's environment.
50+
REQUIRE(SystemUtils::getMachineName() == "JOHNS_MACHINE");
51+
}
52+
```
53+
<sup>[snippet source](/ApprovalTests_Catch2_Tests/utilities/MachineBlockerTests.cpp#L21-L32)</sup>
54+
<!-- endsnippet -->
55+
56+
## Front Loaded Reporters
57+
58+
Other times, you will want to run the tests on all machines, but only report if certain conditions are true. Front loaded reporters allow a mechanism to jump in front of the standard Reporter path, and divert early.
59+
60+
Here is an example of not launching any reporters of you are on the CI machine.
61+
62+
<!-- snippet: do_not_report_on_ci -->
63+
```cpp
64+
// main.cpp
65+
auto frontLoadedReportDisposer = Approvals::useAsFrontLoadedReporter(
66+
BlockingReporter::onMachinesNotNamed("MyCIMachineName") );
67+
```
68+
<sup>[snippet source](/examples/googletest_existing_main/main.cpp#L19-L23)</sup>
69+
<!-- endsnippet -->
70+
71+
Once you have added that, even calling approvals with a specific Reporter will not launch it on the CI system (but will for all other systems). For example:
72+
73+
<!-- snippet: basic_approval_with_reporter -->
74+
```cpp
75+
Approvals::verify("text to be verified", Windows::AraxisMergeReporter());
76+
```
77+
<sup>[snippet source](/examples/googletest_existing_main/GoogleTestApprovalsTests.cpp#L11-L13)</sup>
78+
<!-- endsnippet -->
79+
2080
## Using sub-directories for approved files
2181

2282
If you have a lot of approval files, you might want to put them in a subdirectory, to prevent them cluttering up your source files. You can do this at a global or per-test level, by adding the line:

doc/Features.source.md

+27
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,37 @@
88
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
99
**Contents**
1010

11+
- [Blocking Reporter](#blocking-reporter)
12+
- [Machine Blockers](#machine-blockers)
13+
- [Front Loaded Reporters](#front-loaded-reporters)
1114
- [Using sub-directories for approved files](#using-sub-directories-for-approved-files)
1215

1316
<!-- END doctoc generated TOC please keep comment here to allow auto update -->
1417

18+
## Blocking Reporter
19+
20+
Blocking reporters are a simple class, designed for use with FrontLoadedReporters, to prevent launching of reporters in certain environments.
21+
22+
snippet: do_not_report_on_ci
23+
24+
## Machine Blockers
25+
26+
Sometimes you will want tests to only run on certain machines. Machine blockers are a great way to do this.
27+
28+
snippet: machine_specific_test_runner
29+
30+
## Front Loaded Reporters
31+
32+
Other times, you will want to run the tests on all machines, but only report if certain conditions are true. Front loaded reporters allow a mechanism to jump in front of the standard Reporter path, and divert early.
33+
34+
Here is an example of not launching any reporters of you are on the CI machine.
35+
36+
snippet: do_not_report_on_ci
37+
38+
Once you have added that, even calling approvals with a specific Reporter will not launch it on the CI system (but will for all other systems). For example:
39+
40+
snippet: basic_approval_with_reporter
41+
1542
## Using sub-directories for approved files
1643

1744
If you have a lot of approval files, you might want to put them in a subdirectory, to prevent them cluttering up your source files. You can do this at a global or per-test level, by adding the line:

examples/googletest_existing_main/GoogleTestApprovalsTests.cpp

+7
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ TEST(GoogleTestApprovalsTests, TestStreamableObject)
55
{
66
Approvals::verify(42);
77
}
8+
9+
TEST(GoogleTestApprovalsTests, SpecificReporter)
10+
{
11+
// startcode basic_approval_with_reporter
12+
Approvals::verify("text to be verified", Windows::AraxisMergeReporter());
13+
// endcode
14+
}

0 commit comments

Comments
 (0)