Skip to content

Commit

Permalink
F!! Added CrossPlatformReporters, with VSCode (#204)
Browse files Browse the repository at this point in the history
Co-Authored-By: Llewellyn Falco <[email protected]>
Co-Authored-By: Nitsan Avni <[email protected]>
  • Loading branch information
3 people committed Sep 19, 2022
1 parent 46bbcb3 commit e7ee3a9
Show file tree
Hide file tree
Showing 12 changed files with 91 additions and 2 deletions.
2 changes: 2 additions & 0 deletions ApprovalTests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ add_library(${PROJECT_NAME}
reporters/CommandReporter.cpp
reporters/ConvertForCygwin.h
reporters/ConvertForCygwin.cpp
reporters/CrossPlatformReporters.h
reporters/CrossPlatformReporters.cpp
reporters/CustomReporter.h
reporters/CustomReporter.cpp
reporters/DefaultFrontLoadedReporter.h
Expand Down
23 changes: 23 additions & 0 deletions ApprovalTests/reporters/CrossPlatformReporters.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "ApprovalTests/reporters/CrossPlatformReporters.h"

#include "DiffPrograms.h"

namespace ApprovalTests
{
namespace CrossPlatform
{
VisualStudioCodeReporter::VisualStudioCodeReporter()
: GenericDiffReporter(DiffPrograms::CrossPlatform::VS_CODE())
{
}

CrossPlatformDiffReporter::CrossPlatformDiffReporter()
: FirstWorkingReporter({
// begin-snippet: cross_platform_diff_reporters
new VisualStudioCodeReporter(),
// end-snippet
})
{
}
}
}
22 changes: 22 additions & 0 deletions ApprovalTests/reporters/CrossPlatformReporters.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "ApprovalTests/reporters/GenericDiffReporter.h"
#include "ApprovalTests/reporters/FirstWorkingReporter.h"

namespace ApprovalTests
{
namespace CrossPlatform
{
class VisualStudioCodeReporter : public GenericDiffReporter
{
public:
VisualStudioCodeReporter();
};

class CrossPlatformDiffReporter : public FirstWorkingReporter
{
public:
CrossPlatformDiffReporter();
};
}
}
9 changes: 9 additions & 0 deletions ApprovalTests/reporters/DiffPrograms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ namespace ApprovalTests
namespace DiffPrograms
{

namespace CrossPlatform
{
APPROVAL_TESTS_MACROS_ENTRY(
VS_CODE,
DiffInfo("code",
"-d {Received} {Approved}",
Type::TEXT))
}

namespace Mac
{
APPROVAL_TESTS_MACROS_ENTRY(
Expand Down
5 changes: 5 additions & 0 deletions ApprovalTests/reporters/DiffPrograms.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ namespace ApprovalTests
{
namespace DiffPrograms
{
namespace CrossPlatform
{
DiffInfo VS_CODE();
}

namespace Mac
{
DiffInfo DIFF_MERGE();
Expand Down
4 changes: 3 additions & 1 deletion ApprovalTests/reporters/DiffReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@
#include "WindowsReporters.h"
#include "MacReporters.h"
#include "LinuxReporters.h"
#include "CrossPlatformReporters.h"

namespace ApprovalTests
{
DiffReporter::DiffReporter()
: FirstWorkingReporter({new EnvironmentVariableReporter(),
new Mac::MacDiffReporter(),
new Linux::LinuxDiffReporter(),
new Windows::WindowsDiffReporter()})
new Windows::WindowsDiffReporter(),
new CrossPlatform::CrossPlatformDiffReporter()})
{
}
}
3 changes: 3 additions & 0 deletions ApprovalTests/reporters/ReporterFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ApprovalTests/reporters/CIBuildOnlyReporter.h"
#include "ApprovalTests/reporters/ClipboardReporter.h"
#include "ApprovalTests/reporters/CombinationReporter.h"
#include "ApprovalTests/reporters/CrossPlatformReporters.h"
#include "ApprovalTests/reporters/DefaultFrontLoadedReporter.h"
#include "ApprovalTests/reporters/DefaultReporter.h"
#include "ApprovalTests/reporters/DiffReporter.h"
Expand Down Expand Up @@ -87,6 +88,8 @@ namespace ApprovalTests
APPROVAL_TESTS_REGISTER_REPORTER(Windows::KDiff3Reporter);
APPROVAL_TESTS_REGISTER_REPORTER(Windows::VisualStudioCodeReporter);

APPROVAL_TESTS_REGISTER_REPORTER(CrossPlatform::VisualStudioCodeReporter);

return map;
}

Expand Down
6 changes: 6 additions & 0 deletions doc/Reporters.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ new VisualStudioCodeReporter(),
<sup><a href='/ApprovalTests/reporters/WindowsReporters.cpp#L94-L104' title='Snippet source file'>snippet source</a> | <a href='#snippet-windows_diff_reporters' title='Start of snippet'>anchor</a></sup>
<!-- endSnippet -->

## Cross-platform

These are all based on the diff tool being in the [`PATH`](https://en.wikipedia.org/wiki/PATH_(variable)).

snippet: cross_platform_diff_reporters

## Registering a default reporter

At present, the default Reporter is the DiffReporter. Whenever you call Approvals, you have the chance to pass in your own Reporter. However, if you would like to change what the default reporter is when you don't pass in a specific Reporter, you can do this at a global or per-test level, by adding the line:
Expand Down
7 changes: 7 additions & 0 deletions doc/how_tos/SubmitANewReporterToApprovalTests.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ The steps are the same as above, except that in the second step, you will edit:
* [ApprovalTests/reporters/LinuxReporters.h](https://github.com/approvals/ApprovalTests.cpp/blob/master/ApprovalTests/reporters/LinuxReporters.h)
* [ApprovalTests/reporters/LinuxReporters.cpp](https://github.com/approvals/ApprovalTests.cpp/blob/master/ApprovalTests/reporters/LinuxReporters.cpp)

## Adding a new Cross Platform reporter

To add a reporter that will run on all 3 platforms, the steps are the same as above, except that in the second step, you will edit:

* [ApprovalTests/reporters/CrossPlatformReporters.h](https://github.com/approvals/ApprovalTests.cpp/blob/master/ApprovalTests/reporters/CrossPlatformReporters.h)
* [ApprovalTests/reporters/CrossPlatformReporters.cpp](https://github.com/approvals/ApprovalTests.cpp/blob/master/ApprovalTests/reporters/CrossPlatformReporters.cpp)

---

[Back to User Guide](/doc/README.md#top)
7 changes: 6 additions & 1 deletion tests/DocTest_Tests/reporters/CommandLineReporterTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "ApprovalTests/reporters/WindowsReporters.h"
#include "ApprovalTests/reporters/MacReporters.h"
#include "ApprovalTests/reporters/LinuxReporters.h"
#include "ApprovalTests/reporters/CrossPlatformReporters.h"

#include <vector>

Expand Down Expand Up @@ -58,7 +59,11 @@ TEST_CASE("Test Command Lines")
std::make_shared<Linux::SublimeMergeFlatpakReporter>(),
std::make_shared<Linux::SublimeMergeRepositoryPackageReporter>(),
std::make_shared<Linux::SublimeMergeDirectDownloadReporter>(),
std::make_shared<Linux::KDiff3Reporter>()};
std::make_shared<Linux::KDiff3Reporter>(),

// Cross-platform
std::make_shared<CrossPlatform::VisualStudioCodeReporter>()};

for (const auto& reporter : reporters)
{
reporter->useCygwinConversions(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,8 @@ windows: start "" "kdiff3" "a.txt" "b.txt" -m -o "b.txt"
unix : "kdiff3" "a.txt" "b.txt" -m -o "b.txt" &
cygwin : "$(cygpath 'kdiff3')" "$(cygpath -aw 'a.txt')" "$(cygpath -aw 'b.txt')" -m -o "$(cygpath -aw 'b.txt')" &

windows: start "" "code" -d "a.txt" "b.txt"
unix : "code" -d "a.txt" "b.txt" &
cygwin : "$(cygpath 'code')" -d "$(cygpath -aw 'a.txt')" "$(cygpath -aw 'b.txt')" &


Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ AutoApproveIfMissingReporter
AutoApproveReporter
CIBuildOnlyReporter
ClipboardReporter
CrossPlatform::VisualStudioCodeReporter
DefaultFrontLoadedReporter
DefaultReporter
DiffReporter
Expand Down

0 comments on commit e7ee3a9

Please sign in to comment.