Skip to content

Commit

Permalink
Allow unit test infra to be reused across libs' tests
Browse files Browse the repository at this point in the history
This allows using Arbitrary "instances" defined in libstore-tests in
libexpr-tests, something we will leverage in a moment.
  • Loading branch information
Ericson2314 committed Jan 29, 2023
1 parent 6772e9e commit ec0c0ef
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 21 deletions.
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/tests/error_traces.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "libexprtests.hh"
#include "tests/libexpr.hh"

namespace nix {

Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/tests/json.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "libexprtests.hh"
#include "tests/libexpr.hh"
#include "value-to-json.hh"

namespace nix {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:https://"))
: LibStoreTest()
, state({}, store)
{
}
Expand All @@ -36,7 +37,6 @@ namespace nix {
return state.symbols.create(value);
}

ref<Store> store;
EvalState state;
};

Expand Down
4 changes: 3 additions & 1 deletion src/libexpr/tests/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ check: libexpr-tests_RUN

programs += libexpr-tests

libexpr-tests_NAME := libnixexpr-tests

libexpr-tests_DIR := $(d)

libexpr-tests_INSTALL_DIR :=
Expand All @@ -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
2 changes: 1 addition & 1 deletion src/libexpr/tests/primops.cc
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/tests/trivial.cc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "libexprtests.hh"
#include "tests/libexpr.hh"

namespace nix {
// Testing of trivial expressions
Expand Down
2 changes: 1 addition & 1 deletion src/libexpr/tests/value/context.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "value/context.hh"

#include "libexprtests.hh"
#include "tests/libexpr.hh"

namespace nix {

Expand Down
File renamed without changes.
18 changes: 16 additions & 2 deletions src/libstore/tests/local.mk
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
8 changes: 2 additions & 6 deletions src/libstore/tests/path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/libstore/tests/path.hh
Original file line number Diff line number Diff line change
@@ -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();
};

}
2 changes: 2 additions & 0 deletions src/libutil/tests/local.mk
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ check: libutil-tests_RUN

programs += libutil-tests

libutil-tests_NAME := libnixutil-tests

libutil-tests_DIR := $(d)

libutil-tests_INSTALL_DIR :=
Expand Down

0 comments on commit ec0c0ef

Please sign in to comment.