aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-29 12:37:32 -0500
committerJohn Ericson <John.Ericson@Obsidian.Systems>2023-01-29 13:52:57 -0500
commitec0c0efec6d7eed868b424434748b97651e02bcc (patch)
tree29ced9d126d9db8eced4e0ab380a990dbda51885
parent6772e9ed0ac7853cefdeb6b354c81cba531829f2 (diff)
Allow unit test infra to be reused across libs' tests
This allows using Arbitrary "instances" defined in libstore-tests in libexpr-tests, something we will leverage in a moment.
-rw-r--r--.gitignore6
-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.cc2
-rw-r--r--src/libstore/tests/libstore.hh (renamed from src/libstore/tests/libstoretests.hh)0
-rw-r--r--src/libstore/tests/local.mk18
-rw-r--r--src/libstore/tests/path.cc8
-rw-r--r--src/libstore/tests/path.hh15
-rw-r--r--src/libutil/tests/local.mk2
13 files changed, 50 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 8e0db013f..47815fde6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -37,14 +37,14 @@ perl/Makefile.config
/src/libexpr/parser-tab.hh
/src/libexpr/parser-tab.output
/src/libexpr/nix.tbl
-/src/libexpr/tests/libexpr-tests
+/src/libexpr/tests/libnixexpr-tests
# /src/libstore/
*.gen.*
-/src/libstore/tests/libstore-tests
+/src/libstore/tests/libnixstore-tests
# /src/libutil/
-/src/libutil/tests/libutil-tests
+/src/libutil/tests/libnixutil-tests
/src/nix/nix
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..6b766d82a 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 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..0bcd79625 100644
--- a/src/libexpr/tests/value/context.cc
+++ b/src/libexpr/tests/value/context.cc
@@ -1,6 +1,6 @@
#include "value/context.hh"
-#include "libexprtests.hh"
+#include "tests/libexpr.hh"
namespace nix {
diff --git a/src/libstore/tests/libstoretests.hh b/src/libstore/tests/libstore.hh
index 05397659b..05397659b 100644
--- a/src/libstore/tests/libstoretests.hh
+++ b/src/libstore/tests/libstore.hh
diff --git a/src/libstore/tests/local.mk b/src/libstore/tests/local.mk
index a2cf8a0cf..c24712ccf 100644
--- a/src/libstore/tests/local.mk
+++ b/src/libstore/tests/local.mk
@@ -1,6 +1,20 @@
-check: libstore-tests_RUN
+check: libstore-tests-exe_RUN
-programs += libstore-tests
+programs += libstore-tests-exe
+
+libstore-tests-exe_NAME = libnixstore-tests
+
+libstore-tests-exe_DIR := $(d)
+
+libstore-tests-exe_INSTALL_DIR :=
+
+libstore-tests-exe_LIBS = libstore-tests
+
+libstore-tests-exe_LDFLAGS := $(GTEST_LIBS)
+
+libraries += libstore-tests
+
+libstore-tests_NAME = libnixstore-tests
libstore-tests_DIR := $(d)
diff --git a/src/libstore/tests/path.cc b/src/libstore/tests/path.cc
index 8ea252c92..2fc6d7e48 100644
--- a/src/libstore/tests/path.cc
+++ b/src/libstore/tests/path.cc
@@ -7,7 +7,8 @@
#include "path-regex.hh"
#include "store-api.hh"
-#include "libstoretests.hh"
+#include "tests/libstore.hh"
+#include "tests/path.hh"
namespace nix {
@@ -73,11 +74,6 @@ void showValue(const StorePath & p, std::ostream & os) {
namespace rc {
using namespace nix;
-template<>
-struct Arbitrary<StorePath> {
- static Gen<StorePath> arbitrary();
-};
-
Gen<StorePath> Arbitrary<StorePath>::arbitrary()
{
auto len = *gen::inRange<size_t>(1, StorePath::MaxPathLen);
diff --git a/src/libstore/tests/path.hh b/src/libstore/tests/path.hh
new file mode 100644
index 000000000..0ac9bb9f2
--- /dev/null
+++ b/src/libstore/tests/path.hh
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <rapidcheck.h>
+
+#include "path.hh"
+
+namespace rc {
+using namespace nix;
+
+template<>
+struct Arbitrary<StorePath> {
+ static Gen<StorePath> arbitrary();
+};
+
+}
diff --git a/src/libutil/tests/local.mk b/src/libutil/tests/local.mk
index 815e18560..4f2a3f294 100644
--- a/src/libutil/tests/local.mk
+++ b/src/libutil/tests/local.mk
@@ -2,6 +2,8 @@ check: libutil-tests_RUN
programs += libutil-tests
+libutil-tests_NAME := libnixutil-tests
+
libutil-tests_DIR := $(d)
libutil-tests_INSTALL_DIR :=