66
77#include " nix/store/tests/libstore.hh"
88#include " nix/util/tests/characterization.hh"
9+ #include " nix/util/tests/json-characterization.hh"
910
1011namespace nix {
1112
@@ -16,12 +17,30 @@ class ProtoTest : public CharacterizationTest
1617
1718 std::filesystem::path goldenMaster (std::string_view testStem) const override
1819 {
19- return unitTestData / (std::string{ testStem + " .bin " }) ;
20+ return unitTestData / testStem;
2021 }
2122
2223public:
2324 Path storeDir = " /nix/store" ;
2425 StoreDirConfig store{storeDir};
26+
27+ /* *
28+ * Golden test for `T` JSON reading
29+ */
30+ template <typename T>
31+ void readJsonTest (PathView testStem, const T & expected)
32+ {
33+ nix::readJsonTest (*this , testStem, expected);
34+ }
35+
36+ /* *
37+ * Golden test for `T` JSON write
38+ */
39+ template <typename T>
40+ void writeJsonTest (PathView testStem, const T & decoded)
41+ {
42+ nix::writeJsonTest (*this , testStem, decoded);
43+ }
2544};
2645
2746template <class Proto , const char * protocolDir>
@@ -34,7 +53,7 @@ public:
3453 template <typename T>
3554 void readProtoTest (PathView testStem, typename Proto::Version version, T expected)
3655 {
37- CharacterizationTest::readTest (testStem, [&](const auto & encoded) {
56+ CharacterizationTest::readTest (std::string{ testStem + " .bin " } , [&](const auto & encoded) {
3857 T got = ({
3958 StringSource from{encoded};
4059 Proto::template Serialise<T>::read (
@@ -55,7 +74,7 @@ public:
5574 template <typename T>
5675 void writeProtoTest (PathView testStem, typename Proto::Version version, const T & decoded)
5776 {
58- CharacterizationTest::writeTest (testStem, [&]() {
77+ CharacterizationTest::writeTest (std::string{ testStem + " .bin " } , [&]() {
5978 StringSink to;
6079 Proto::template Serialise<T>::write (
6180 this ->store ,
@@ -69,14 +88,25 @@ public:
6988 }
7089};
7190
72- #define VERSIONED_CHARACTERIZATION_TEST (FIXTURE, NAME, STEM, VERSION, VALUE ) \
73- TEST_F (FIXTURE, NAME##_read) \
74- { \
75- readProtoTest (STEM, VERSION, VALUE); \
76- } \
77- TEST_F (FIXTURE, NAME##_write) \
78- { \
79- writeProtoTest (STEM, VERSION, VALUE); \
91+ #define VERSIONED_CHARACTERIZATION_TEST_NO_JSON (FIXTURE, NAME, STEM, VERSION, VALUE ) \
92+ TEST_F (FIXTURE, NAME##_read) \
93+ { \
94+ readProtoTest (STEM, VERSION, VALUE); \
95+ } \
96+ TEST_F (FIXTURE, NAME##_write) \
97+ { \
98+ writeProtoTest (STEM, VERSION, VALUE); \
99+ }
100+
101+ #define VERSIONED_CHARACTERIZATION_TEST (FIXTURE, NAME, STEM, VERSION, VALUE ) \
102+ VERSIONED_CHARACTERIZATION_TEST_NO_JSON (FIXTURE, NAME, STEM, VERSION, VALUE) \
103+ TEST_F (FIXTURE, NAME##_json_read) \
104+ { \
105+ readJsonTest (STEM, VALUE); \
106+ } \
107+ TEST_F (FIXTURE, NAME##_json_write) \
108+ { \
109+ writeJsonTest (STEM, VALUE); \
80110 }
81111
82112} // namespace nix
0 commit comments