|
14 | 14 |
|
15 | 15 | namespace nix { |
16 | 16 |
|
17 | | -using nlohmann::json; |
| 17 | +using namespace nlohmann; |
18 | 18 |
|
19 | 19 | class DerivationAdvancedAttrsTest : public CharacterizationTest, public LibStoreTest |
20 | 20 | { |
@@ -51,44 +51,44 @@ using BothFixtures = ::testing::Types<DerivationAdvancedAttrsTest, CaDerivationA |
51 | 51 |
|
52 | 52 | TYPED_TEST_SUITE(DerivationAdvancedAttrsBothTest, BothFixtures); |
53 | 53 |
|
54 | | -#define TEST_ATERM_JSON(STEM, NAME) \ |
55 | | - TYPED_TEST(DerivationAdvancedAttrsBothTest, Derivation_##STEM##_from_json) \ |
56 | | - { \ |
57 | | - this->readTest(NAME ".json", [&](const auto & encoded_) { \ |
58 | | - auto encoded = json::parse(encoded_); \ |
59 | | - /* Use DRV file instead of C++ literal as source of truth. */ \ |
60 | | - auto aterm = readFile(this->goldenMaster(NAME ".drv")); \ |
61 | | - auto expected = parseDerivation(*this->store, std::move(aterm), NAME, this->mockXpSettings); \ |
62 | | - Derivation got = Derivation::fromJSON(encoded, this->mockXpSettings); \ |
63 | | - EXPECT_EQ(got, expected); \ |
64 | | - }); \ |
65 | | - } \ |
66 | | - \ |
67 | | - TYPED_TEST(DerivationAdvancedAttrsBothTest, Derivation_##STEM##_to_json) \ |
68 | | - { \ |
69 | | - this->writeTest( \ |
70 | | - NAME ".json", \ |
71 | | - [&]() -> json { \ |
72 | | - /* Use DRV file instead of C++ literal as source of truth. */ \ |
73 | | - auto aterm = readFile(this->goldenMaster(NAME ".drv")); \ |
74 | | - return parseDerivation(*this->store, std::move(aterm), NAME, this->mockXpSettings).toJSON(); \ |
75 | | - }, \ |
76 | | - [](const auto & file) { return json::parse(readFile(file)); }, \ |
77 | | - [](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \ |
78 | | - } \ |
79 | | - \ |
80 | | - TYPED_TEST(DerivationAdvancedAttrsBothTest, Derivation_##STEM##_from_aterm) \ |
81 | | - { \ |
82 | | - this->readTest(NAME ".drv", [&](auto encoded) { \ |
83 | | - /* Use JSON file instead of C++ literal as source of truth. */ \ |
84 | | - auto json = json::parse(readFile(this->goldenMaster(NAME ".json"))); \ |
85 | | - auto expected = Derivation::fromJSON(json, this->mockXpSettings); \ |
86 | | - auto got = parseDerivation(*this->store, std::move(encoded), NAME, this->mockXpSettings); \ |
87 | | - EXPECT_EQ(got.toJSON(), expected.toJSON()); \ |
88 | | - EXPECT_EQ(got, expected); \ |
89 | | - }); \ |
90 | | - } \ |
91 | | - \ |
| 54 | +#define TEST_ATERM_JSON(STEM, NAME) \ |
| 55 | + TYPED_TEST(DerivationAdvancedAttrsBothTest, Derivation_##STEM##_from_json) \ |
| 56 | + { \ |
| 57 | + this->readTest(NAME ".json", [&](const auto & encoded_) { \ |
| 58 | + auto encoded = json::parse(encoded_); \ |
| 59 | + /* Use DRV file instead of C++ literal as source of truth. */ \ |
| 60 | + auto aterm = readFile(this->goldenMaster(NAME ".drv")); \ |
| 61 | + auto expected = parseDerivation(*this->store, std::move(aterm), NAME, this->mockXpSettings); \ |
| 62 | + Derivation got = adl_serializer<Derivation>::from_json(encoded, this->mockXpSettings); \ |
| 63 | + EXPECT_EQ(got, expected); \ |
| 64 | + }); \ |
| 65 | + } \ |
| 66 | + \ |
| 67 | + TYPED_TEST(DerivationAdvancedAttrsBothTest, Derivation_##STEM##_to_json) \ |
| 68 | + { \ |
| 69 | + this->writeTest( \ |
| 70 | + NAME ".json", \ |
| 71 | + [&]() -> json { \ |
| 72 | + /* Use DRV file instead of C++ literal as source of truth. */ \ |
| 73 | + auto aterm = readFile(this->goldenMaster(NAME ".drv")); \ |
| 74 | + return parseDerivation(*this->store, std::move(aterm), NAME, this->mockXpSettings); \ |
| 75 | + }, \ |
| 76 | + [](const auto & file) { return json::parse(readFile(file)); }, \ |
| 77 | + [](const auto & file, const auto & got) { return writeFile(file, got.dump(2) + "\n"); }); \ |
| 78 | + } \ |
| 79 | + \ |
| 80 | + TYPED_TEST(DerivationAdvancedAttrsBothTest, Derivation_##STEM##_from_aterm) \ |
| 81 | + { \ |
| 82 | + this->readTest(NAME ".drv", [&](auto encoded) { \ |
| 83 | + /* Use JSON file instead of C++ literal as source of truth. */ \ |
| 84 | + auto j = json::parse(readFile(this->goldenMaster(NAME ".json"))); \ |
| 85 | + auto expected = adl_serializer<Derivation>::from_json(j, this->mockXpSettings); \ |
| 86 | + auto got = parseDerivation(*this->store, std::move(encoded), NAME, this->mockXpSettings); \ |
| 87 | + EXPECT_EQ(static_cast<json>(got), static_cast<json>(expected)); \ |
| 88 | + EXPECT_EQ(got, expected); \ |
| 89 | + }); \ |
| 90 | + } \ |
| 91 | + \ |
92 | 92 | /* No corresponding write test, because we need to read the drv to write the json file */ |
93 | 93 |
|
94 | 94 | TEST_ATERM_JSON(advancedAttributes, "advanced-attributes-defaults"); |
|
0 commit comments