Skip to content

Commit ca78783

Browse files
authored
Merge branch 'master' into expr-slim
2 parents 1db9336 + c43ea09 commit ca78783

23 files changed

+443
-270
lines changed

src/libexpr-tests/primops.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ class ToStringPrimOpTest : public PrimOpTest,
642642

643643
TEST_P(ToStringPrimOpTest, toString)
644644
{
645-
const auto [input, output] = GetParam();
645+
const auto & [input, output] = GetParam();
646646
auto v = eval(input);
647647
ASSERT_THAT(v, IsStringEq(output));
648648
}
@@ -798,7 +798,7 @@ class CompareVersionsPrimOpTest : public PrimOpTest,
798798

799799
TEST_P(CompareVersionsPrimOpTest, compareVersions)
800800
{
801-
auto [expression, expectation] = GetParam();
801+
const auto & [expression, expectation] = GetParam();
802802
auto v = eval(expression);
803803
ASSERT_THAT(v, IsIntEq(expectation));
804804
}
@@ -834,7 +834,7 @@ class ParseDrvNamePrimOpTest
834834

835835
TEST_P(ParseDrvNamePrimOpTest, parseDrvName)
836836
{
837-
auto [input, expectedName, expectedVersion] = GetParam();
837+
const auto & [input, expectedName, expectedVersion] = GetParam();
838838
const auto expr = fmt("builtins.parseDrvName \"%1%\"", input);
839839
auto v = eval(expr);
840840
ASSERT_THAT(v, IsAttrsOfSize(2));

src/libfetchers-tests/public-key.cc

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#include <gtest/gtest.h>
22
#include "nix/fetchers/fetchers.hh"
33
#include "nix/util/json-utils.hh"
4-
#include <nlohmann/json.hpp>
5-
#include "nix/util/tests/characterization.hh"
4+
#include "nix/util/tests/json-characterization.hh"
65

76
namespace nix {
87

98
using nlohmann::json;
109

11-
class PublicKeyTest : public CharacterizationTest
10+
class PublicKeyTest : public JsonCharacterizationTest<fetchers::PublicKey>,
11+
public ::testing::WithParamInterface<std::pair<std::string_view, fetchers::PublicKey>>
1212
{
1313
std::filesystem::path unitTestData = getUnitTestData() / "public-key";
1414

@@ -19,30 +19,35 @@ class PublicKeyTest : public CharacterizationTest
1919
}
2020
};
2121

22-
#define TEST_JSON(FIXTURE, NAME, VAL) \
23-
TEST_F(FIXTURE, PublicKey_##NAME##_from_json) \
24-
{ \
25-
readTest(#NAME ".json", [&](const auto & encoded_) { \
26-
fetchers::PublicKey expected{VAL}; \
27-
fetchers::PublicKey got = nlohmann::json::parse(encoded_); \
28-
ASSERT_EQ(got, expected); \
29-
}); \
30-
} \
31-
\
32-
TEST_F(FIXTURE, PublicKey_##NAME##_to_json) \
33-
{ \
34-
writeTest( \
35-
#NAME ".json", \
36-
[&]() -> json { return nlohmann::json(fetchers::PublicKey{VAL}); }, \
37-
[](const auto & file) { return json::parse(readFile(file)); }, \
38-
[](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \
39-
}
40-
41-
TEST_JSON(PublicKeyTest, simple, (fetchers::PublicKey{.type = "ssh-rsa", .key = "ABCDE"}))
22+
TEST_P(PublicKeyTest, from_json)
23+
{
24+
const auto & [name, expected] = GetParam();
25+
readJsonTest(name, expected);
26+
}
4227

43-
TEST_JSON(PublicKeyTest, defaultType, fetchers::PublicKey{.key = "ABCDE"})
28+
TEST_P(PublicKeyTest, to_json)
29+
{
30+
const auto & [name, value] = GetParam();
31+
writeJsonTest(name, value);
32+
}
4433

45-
#undef TEST_JSON
34+
INSTANTIATE_TEST_SUITE_P(
35+
PublicKeyJSON,
36+
PublicKeyTest,
37+
::testing::Values(
38+
std::pair{
39+
"simple",
40+
fetchers::PublicKey{
41+
.type = "ssh-rsa",
42+
.key = "ABCDE",
43+
},
44+
},
45+
std::pair{
46+
"defaultType",
47+
fetchers::PublicKey{
48+
.key = "ABCDE",
49+
},
50+
}));
4651

4752
TEST_F(PublicKeyTest, PublicKey_noRoundTrip_from_json)
4853
{

src/libstore-tests/derivation.cc

Lines changed: 176 additions & 137 deletions
Large diffs are not rendered by default.

src/libstore-tests/http-binary-cache-store.cc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,20 @@ TEST(HttpBinaryCacheStore, constructConfigNoTrailingSlash)
1818
EXPECT_EQ(config.cacheUri.to_string(), "https://foo.bar.baz/a/b");
1919
}
2020

21+
TEST(HttpBinaryCacheStore, constructConfigWithParams)
22+
{
23+
StoreConfig::Params params{{"compression", "xz"}};
24+
HttpBinaryCacheStoreConfig config{"https", "foo.bar.baz/a/b/", params};
25+
EXPECT_EQ(config.cacheUri.to_string(), "https://foo.bar.baz/a/b");
26+
EXPECT_EQ(config.getReference().params, params);
27+
}
28+
29+
TEST(HttpBinaryCacheStore, constructConfigWithParamsAndUrlWithParams)
30+
{
31+
StoreConfig::Params params{{"compression", "xz"}};
32+
HttpBinaryCacheStoreConfig config{"https", "foo.bar.baz/a/b?some-param=some-value", params};
33+
EXPECT_EQ(config.cacheUri.to_string(), "https://foo.bar.baz/a/b?some-param=some-value");
34+
EXPECT_EQ(config.getReference().params, params);
35+
}
36+
2137
} // namespace nix

src/libstore-tests/outputs-spec.cc

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
#include <rapidcheck/gtest.h>
44

55
#include "nix/store/tests/outputs-spec.hh"
6-
7-
#include "nix/util/tests/characterization.hh"
6+
#include "nix/util/tests/json-characterization.hh"
87

98
namespace nix {
109

11-
class OutputsSpecTest : public CharacterizationTest
10+
class OutputsSpecTest : public virtual CharacterizationTest
1211
{
1312
std::filesystem::path unitTestData = getUnitTestData() / "outputs-spec";
1413

@@ -20,7 +19,7 @@ class OutputsSpecTest : public CharacterizationTest
2019
}
2120
};
2221

23-
class ExtendedOutputsSpecTest : public CharacterizationTest
22+
class ExtendedOutputsSpecTest : public virtual CharacterizationTest
2423
{
2524
std::filesystem::path unitTestData = getUnitTestData() / "outputs-spec" / "extended";
2625

@@ -214,40 +213,49 @@ TEST_F(ExtendedOutputsSpecTest, many_carrot)
214213
ASSERT_EQ(std::string{prefix} + expected.to_string(), "foo^bar^bin,out");
215214
}
216215

217-
#define TEST_JSON(FIXTURE, TYPE, NAME, VAL) \
218-
static const TYPE FIXTURE##_##NAME = VAL; \
219-
\
220-
TEST_F(FIXTURE, NAME##_from_json) \
221-
{ \
222-
using namespace nlohmann; \
223-
\
224-
readTest(#NAME ".json", [&](const auto & encoded_) { \
225-
auto encoded = json::parse(encoded_); \
226-
TYPE got = adl_serializer<TYPE>::from_json(encoded); \
227-
ASSERT_EQ(got, FIXTURE##_##NAME); \
228-
}); \
229-
} \
230-
\
231-
TEST_F(FIXTURE, NAME##_to_json) \
232-
{ \
233-
using namespace nlohmann; \
234-
\
235-
writeTest( \
236-
#NAME ".json", \
237-
[&]() -> json { return static_cast<json>(FIXTURE##_##NAME); }, \
238-
[](const auto & file) { return json::parse(readFile(file)); }, \
239-
[](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \
216+
#define MAKE_TEST_P(FIXTURE, TYPE) \
217+
TEST_P(FIXTURE, from_json) \
218+
{ \
219+
const auto & [name, value] = GetParam(); \
220+
readJsonTest(name, value); \
221+
} \
222+
\
223+
TEST_P(FIXTURE, to_json) \
224+
{ \
225+
const auto & [name, value] = GetParam(); \
226+
writeJsonTest(name, value); \
240227
}
241228

242-
TEST_JSON(OutputsSpecTest, OutputsSpec, all, OutputsSpec::All{})
243-
TEST_JSON(OutputsSpecTest, OutputsSpec, name, OutputsSpec::Names{"a"})
244-
TEST_JSON(OutputsSpecTest, OutputsSpec, names, (OutputsSpec::Names{"a", "b"}))
245-
246-
TEST_JSON(ExtendedOutputsSpecTest, ExtendedOutputsSpec, def, ExtendedOutputsSpec::Default{})
247-
TEST_JSON(ExtendedOutputsSpecTest, ExtendedOutputsSpec, all, ExtendedOutputsSpec::Explicit{OutputsSpec::All{}})
248-
TEST_JSON(ExtendedOutputsSpecTest, ExtendedOutputsSpec, name, ExtendedOutputsSpec::Explicit{OutputsSpec::Names{"a"}})
249-
TEST_JSON(
250-
ExtendedOutputsSpecTest, ExtendedOutputsSpec, names, (ExtendedOutputsSpec::Explicit{OutputsSpec::Names{"a", "b"}}))
229+
struct OutputsSpecJsonTest : OutputsSpecTest,
230+
JsonCharacterizationTest<OutputsSpec>,
231+
::testing::WithParamInterface<std::pair<std::string_view, OutputsSpec>>
232+
{};
233+
234+
MAKE_TEST_P(OutputsSpecJsonTest, OutputsSpec);
235+
236+
INSTANTIATE_TEST_SUITE_P(
237+
OutputsSpecJSON,
238+
OutputsSpecJsonTest,
239+
::testing::Values(
240+
std::pair{"all", OutputsSpec{OutputsSpec::All{}}},
241+
std::pair{"name", OutputsSpec{OutputsSpec::Names{"a"}}},
242+
std::pair{"names", OutputsSpec{OutputsSpec::Names{"a", "b"}}}));
243+
244+
struct ExtendedOutputsSpecJsonTest : ExtendedOutputsSpecTest,
245+
JsonCharacterizationTest<ExtendedOutputsSpec>,
246+
::testing::WithParamInterface<std::pair<std::string_view, ExtendedOutputsSpec>>
247+
{};
248+
249+
MAKE_TEST_P(ExtendedOutputsSpecJsonTest, ExtendedOutputsSpec);
250+
251+
INSTANTIATE_TEST_SUITE_P(
252+
ExtendedOutputsSpecJSON,
253+
ExtendedOutputsSpecJsonTest,
254+
::testing::Values(
255+
std::pair{"def", ExtendedOutputsSpec{ExtendedOutputsSpec::Default{}}},
256+
std::pair{"all", ExtendedOutputsSpec{ExtendedOutputsSpec::Explicit{OutputsSpec::All{}}}},
257+
std::pair{"name", ExtendedOutputsSpec{ExtendedOutputsSpec::Explicit{OutputsSpec::Names{"a"}}}},
258+
std::pair{"names", ExtendedOutputsSpec{ExtendedOutputsSpec::Explicit{OutputsSpec::Names{"a", "b"}}}}));
251259

252260
#undef TEST_JSON
253261

src/libstore-tests/path.cc

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "nix/store/path-regex.hh"
88
#include "nix/store/store-api.hh"
99

10-
#include "nix/util/tests/characterization.hh"
10+
#include "nix/util/tests/json-characterization.hh"
1111
#include "nix/store/tests/libstore.hh"
1212
#include "nix/store/tests/path.hh"
1313

@@ -16,7 +16,7 @@ namespace nix {
1616
#define STORE_DIR "/nix/store/"
1717
#define HASH_PART "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q"
1818

19-
class StorePathTest : public CharacterizationTest, public LibStoreTest
19+
class StorePathTest : public virtual CharacterizationTest, public LibStoreTest
2020
{
2121
std::filesystem::path unitTestData = getUnitTestData() / "store-path";
2222

@@ -149,27 +149,30 @@ RC_GTEST_FIXTURE_PROP(StorePathTest, prop_check_regex_eq_parse, ())
149149

150150
using nlohmann::json;
151151

152-
#define TEST_JSON(FIXTURE, NAME, VAL) \
153-
static const StorePath NAME = VAL; \
154-
\
155-
TEST_F(FIXTURE, NAME##_from_json) \
156-
{ \
157-
readTest(#NAME ".json", [&](const auto & encoded_) { \
158-
auto encoded = json::parse(encoded_); \
159-
StorePath got = static_cast<StorePath>(encoded); \
160-
ASSERT_EQ(got, NAME); \
161-
}); \
162-
} \
163-
\
164-
TEST_F(FIXTURE, NAME##_to_json) \
165-
{ \
166-
writeTest( \
167-
#NAME ".json", \
168-
[&]() -> json { return static_cast<json>(NAME); }, \
169-
[](const auto & file) { return json::parse(readFile(file)); }, \
170-
[](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \
171-
}
152+
struct StorePathJsonTest : StorePathTest,
153+
JsonCharacterizationTest<StorePath>,
154+
::testing::WithParamInterface<std::pair<std::string_view, StorePath>>
155+
{};
156+
157+
TEST_P(StorePathJsonTest, from_json)
158+
{
159+
auto & [name, expected] = GetParam();
160+
readJsonTest(name, expected);
161+
}
162+
163+
TEST_P(StorePathJsonTest, to_json)
164+
{
165+
auto & [name, value] = GetParam();
166+
writeJsonTest(name, value);
167+
}
172168

173-
TEST_JSON(StorePathTest, simple, StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"});
169+
INSTANTIATE_TEST_SUITE_P(
170+
StorePathJSON,
171+
StorePathJsonTest,
172+
::testing::Values(
173+
std::pair{
174+
"simple",
175+
StorePath{"g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-foo.drv"},
176+
}));
174177

175178
} // namespace nix

0 commit comments

Comments
 (0)