Skip to content

Similar to Jest Snapshot, but implemented in C++.

License

Notifications You must be signed in to change notification settings

Dup4/snapshot-cpp

Repository files navigation

snapshot-cpp

Clang Format Test codecov GitHub release

Similar to Jest Snapshot, but implemented in C++.

Feature

  • SNAPSHOT(content)
  • SNAPSHOT_INLINE(content)
  • SNAPSHOT_DIFF(before_content, after_content) required git binary.
  • Support Linux and macOS.

Integration

CMake

FetchContent_Declare(
    snapshot
    QUIET
    GIT_REPOSITORY https://github.com/Dup4/snapshot-cpp.git
    GIT_TAG v{x.y.z} # Where `x.y.z` is the release version you want to use.
)

Bazel

git_repository(
    name = "snapshot",
    remote = "https://github.com/Dup4/snapshot-cpp.git",
    tag = "v{x.y.z}",  # Where `x.y.z` is the release version you want to use.
)

Usage

const std::string tmp = "snapshot-cpp";
const std::string tmp_diff = tmp + "-diff";

EXPECT_EQ(tmp, SNAPSHOT_INLINE(tmp));
// EXPECT_EQ(tmp, std::string("snapshot-cpp"));

SNAPSHOT(tmp);
// // /home/Dup4/snapshot-cpp/test/snapshot_test.cc.TestBody.58.0
// std::string("snapshot-cpp")

SNAPSHOT_DIFF(tmp, tmp_diff);
// // /home/Dup4/snapshot-cpp/test/snapshot_test.cc.TestBody.59.0
// // before
// std::string("snapshot-cpp")
// // after
// std::string("snapshot-cpp-diff")
// // diff
// diff --git a/tmp/snapshot_test.cc.TestBody.59.0.snap.before b/tmp/snapshot_test.cc.TestBody.59.0.snap.after
// index aeb786e..3982900 100644
// --- a/tmp/snapshot_test.cc.TestBody.59.0.snap.before
// +++ b/tmp/snapshot_test.cc.TestBody.59.0.snap.after
// @@ -1 +1 @@
// -std::string("snapshot-cpp")
// \ No newline at end of file
// +std::string("snapshot-cpp-diff")
// \ No newline at end of file

License

MIT License © 2022 - PRESENT Dup4