aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorRobert Hensing <roberth@users.noreply.github.com>2023-01-30 18:54:53 +0100
committerGitHub <noreply@github.com>2023-01-30 18:54:53 +0100
commitc9b9260f348299aad70ea2010db6e291ee1e8114 (patch)
tree7c380cb7a6a04fc95d4397e35ba69dd53c235b0d /src/libexpr
parenta31d7d4e5e5eeeb7ca12ca798dc383045e5be1a1 (diff)
parent560142fec0debefe7f983e60663dc3db4bdd79a9 (diff)
Merge pull request #7713 from obsidiansystems/more-rapid-check
Add more property tests
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/tests/error_traces.cc2
-rw-r--r--src/libexpr/tests/json.cc2
-rw-r--r--src/libexpr/tests/libexpr.hh (renamed from src/libexpr/tests/libexprtests.hh)8
-rw-r--r--src/libexpr/tests/local.mk4
-rw-r--r--src/libexpr/tests/primops.cc2
-rw-r--r--src/libexpr/tests/trivial.cc2
-rw-r--r--src/libexpr/tests/value/context.cc59
-rw-r--r--src/libexpr/tests/value/context.hh30
-rw-r--r--src/libexpr/value/context.hh17
9 files changed, 110 insertions, 16 deletions
diff --git a/src/libexpr/tests/error_traces.cc b/src/libexpr/tests/error_traces.cc
index 5e2213f69..24e95ac39 100644
--- a/src/libexpr/tests/error_traces.cc
+++ b/src/libexpr/tests/error_traces.cc
@@ -1,7 +1,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include "libexprtests.hh"
+#include "tests/libexpr.hh"
namespace nix {
diff --git a/src/libexpr/tests/json.cc b/src/libexpr/tests/json.cc
index f1ea1b197..411bc0ac3 100644
--- a/src/libexpr/tests/json.cc
+++ b/src/libexpr/tests/json.cc
@@ -1,4 +1,4 @@
-#include "libexprtests.hh"
+#include "tests/libexpr.hh"
#include "value-to-json.hh"
namespace nix {
diff --git a/src/libexpr/tests/libexprtests.hh b/src/libexpr/tests/libexpr.hh
index 03e468fbb..8534d9567 100644
--- a/src/libexpr/tests/libexprtests.hh
+++ b/src/libexpr/tests/libexpr.hh
@@ -7,18 +7,19 @@
#include "eval-inline.hh"
#include "store-api.hh"
+#include "tests/libstore.hh"
namespace nix {
- class LibExprTest : public ::testing::Test {
+ class LibExprTest : public LibStoreTest {
public:
static void SetUpTestSuite() {
- initLibStore();
+ LibStoreTest::SetUpTestSuite();
initGC();
}
protected:
LibExprTest()
- : store(openStore("dummy://"))
+ : LibStoreTest()
, state({}, store)
{
}
@@ -36,7 +37,6 @@ namespace nix {
return state.symbols.create(value);
}
- ref<Store> store;
EvalState state;
};
diff --git a/src/libexpr/tests/local.mk b/src/libexpr/tests/local.mk
index e483575a4..3e5504f71 100644
--- a/src/libexpr/tests/local.mk
+++ b/src/libexpr/tests/local.mk
@@ -2,6 +2,8 @@ check: libexpr-tests_RUN
programs += libexpr-tests
+libexpr-tests_NAME := libnixexpr-tests
+
libexpr-tests_DIR := $(d)
libexpr-tests_INSTALL_DIR :=
@@ -12,6 +14,6 @@ libexpr-tests_SOURCES := \
libexpr-tests_CXXFLAGS += -I src/libexpr -I src/libutil -I src/libstore -I src/libexpr/tests
-libexpr-tests_LIBS = libexpr libutil libstore libfetchers
+libexpr-tests_LIBS = libstore-tests libutils-tests libexpr libutil libstore libfetchers
libexpr-tests_LDFLAGS := $(GTEST_LIBS) -lgmock
diff --git a/src/libexpr/tests/primops.cc b/src/libexpr/tests/primops.cc
index 9cdcf64a1..e1d3ac503 100644
--- a/src/libexpr/tests/primops.cc
+++ b/src/libexpr/tests/primops.cc
@@ -1,7 +1,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>
-#include "libexprtests.hh"
+#include "tests/libexpr.hh"
namespace nix {
class CaptureLogger : public Logger
diff --git a/src/libexpr/tests/trivial.cc b/src/libexpr/tests/trivial.cc
index 8ce276e52..171727ac7 100644
--- a/src/libexpr/tests/trivial.cc
+++ b/src/libexpr/tests/trivial.cc
@@ -1,4 +1,4 @@
-#include "libexprtests.hh"
+#include "tests/libexpr.hh"
namespace nix {
// Testing of trivial expressions
diff --git a/src/libexpr/tests/value/context.cc b/src/libexpr/tests/value/context.cc
index d5c9d3bce..083359b7a 100644
--- a/src/libexpr/tests/value/context.cc
+++ b/src/libexpr/tests/value/context.cc
@@ -1,6 +1,10 @@
-#include "value/context.hh"
+#include <nlohmann/json.hpp>
+#include <gtest/gtest.h>
+#include <rapidcheck/gtest.h>
-#include "libexprtests.hh"
+#include "tests/path.hh"
+#include "tests/libexpr.hh"
+#include "tests/value/context.hh"
namespace nix {
@@ -70,3 +74,54 @@ TEST_F(NixStringContextElemTest, built) {
}
}
+
+namespace rc {
+using namespace nix;
+
+Gen<NixStringContextElem::Opaque> Arbitrary<NixStringContextElem::Opaque>::arbitrary()
+{
+ return gen::just(NixStringContextElem::Opaque {
+ .path = *gen::arbitrary<StorePath>(),
+ });
+}
+
+Gen<NixStringContextElem::DrvDeep> Arbitrary<NixStringContextElem::DrvDeep>::arbitrary()
+{
+ return gen::just(NixStringContextElem::DrvDeep {
+ .drvPath = *gen::arbitrary<StorePath>(),
+ });
+}
+
+Gen<NixStringContextElem::Built> Arbitrary<NixStringContextElem::Built>::arbitrary()
+{
+ return gen::just(NixStringContextElem::Built {
+ .drvPath = *gen::arbitrary<StorePath>(),
+ .output = (*gen::arbitrary<StorePathName>()).name,
+ });
+}
+
+Gen<NixStringContextElem> Arbitrary<NixStringContextElem>::arbitrary()
+{
+ switch (*gen::inRange<uint8_t>(0, 2)) {
+ case 0:
+ return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::Opaque>());
+ case 1:
+ return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::DrvDeep>());
+ default:
+ return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::Built>());
+ }
+}
+
+}
+
+namespace nix {
+
+RC_GTEST_FIXTURE_PROP(
+ NixStringContextElemTest,
+ prop_round_rip,
+ (const NixStringContextElem & o))
+{
+ RC_ASSERT(o == NixStringContextElem::parse(store(), o.to_string(store())));
+}
+
+}
diff --git a/src/libexpr/tests/value/context.hh b/src/libexpr/tests/value/context.hh
new file mode 100644
index 000000000..54d21760e
--- /dev/null
+++ b/src/libexpr/tests/value/context.hh
@@ -0,0 +1,30 @@
+#pragma once
+
+#include <rapidcheck/gen/Arbitrary.h>
+
+#include <value/context.hh>
+
+namespace rc {
+using namespace nix;
+
+template<>
+struct Arbitrary<NixStringContextElem::Opaque> {
+ static Gen<NixStringContextElem::Opaque> arbitrary();
+};
+
+template<>
+struct Arbitrary<NixStringContextElem::Built> {
+ static Gen<NixStringContextElem::Built> arbitrary();
+};
+
+template<>
+struct Arbitrary<NixStringContextElem::DrvDeep> {
+ static Gen<NixStringContextElem::DrvDeep> arbitrary();
+};
+
+template<>
+struct Arbitrary<NixStringContextElem> {
+ static Gen<NixStringContextElem> arbitrary();
+};
+
+}
diff --git a/src/libexpr/value/context.hh b/src/libexpr/value/context.hh
index d8008c436..721563cba 100644
--- a/src/libexpr/value/context.hh
+++ b/src/libexpr/value/context.hh
@@ -1,9 +1,10 @@
#pragma once
#include "util.hh"
+#include "comparator.hh"
#include "path.hh"
-#include <optional>
+#include <variant>
#include <nlohmann/json_fwd.hpp>
@@ -31,7 +32,9 @@ class Store;
Encoded as just the path: ‘<path>’.
*/
struct NixStringContextElem_Opaque {
- StorePath path;
+ StorePath path;
+
+ GENERATE_CMP(NixStringContextElem_Opaque, me->path);
};
/* Path to a derivation and its entire build closure.
@@ -43,7 +46,9 @@ struct NixStringContextElem_Opaque {
Encoded in the form ‘=<drvPath>’.
*/
struct NixStringContextElem_DrvDeep {
- StorePath drvPath;
+ StorePath drvPath;
+
+ GENERATE_CMP(NixStringContextElem_DrvDeep, me->drvPath);
};
/* Derivation output.
@@ -51,8 +56,10 @@ struct NixStringContextElem_DrvDeep {
Encoded in the form ‘!<output>!<drvPath>’.
*/
struct NixStringContextElem_Built {
- StorePath drvPath;
- std::string output;
+ StorePath drvPath;
+ std::string output;
+
+ GENERATE_CMP(NixStringContextElem_Built, me->drvPath, me->output);
};
using _NixStringContextElem_Raw = std::variant<