Move tests to separate directories, and document
Today, with the tests inside a `tests` intermingled with the corresponding library's source code, we have a few problems: - We have to be careful that wildcards don't end up with tests being built as part of Nix proper, or test headers being installed as part of Nix proper. - Tests in libraries but not executables is not right: - It means each executable runs the previous unit tests again, because it needs the libraries. - It doesn't work right on Windows, which doesn't want you to load a DLL just for the side global variable . It could be made to work with the dlopen equivalent, but that's gross! This reorg solves these problems. There is a remaining problem which is that sibbling headers (like `hash.hh` the test header vs `hash.hh` the main `libnixutil` header) end up shadowing each other. This PR doesn't solve that. That is left as future work for a future PR. Co-authored-by: Valentin Gagarin <valentin.gagarin@tweag.io> (cherry picked from commit 91b6833686a6a6d9eac7f3f66393ec89ef1d3b57) (cherry picked from commit a61e42adb528b3d40ce43e07c79368d779a8b624)
This commit is contained in:
parent
30dcc19d1f
commit
f7f37035c8
61 changed files with 386 additions and 293 deletions
6
.gitignore
vendored
6
.gitignore
vendored
|
@ -41,14 +41,14 @@ perl/Makefile.config
|
||||||
/src/libexpr/parser-tab.hh
|
/src/libexpr/parser-tab.hh
|
||||||
/src/libexpr/parser-tab.output
|
/src/libexpr/parser-tab.output
|
||||||
/src/libexpr/nix.tbl
|
/src/libexpr/nix.tbl
|
||||||
/src/libexpr/tests/libnixexpr-tests
|
/tests/unit/libexpr/libnixexpr-tests
|
||||||
|
|
||||||
# /src/libstore/
|
# /src/libstore/
|
||||||
*.gen.*
|
*.gen.*
|
||||||
/src/libstore/tests/libnixstore-tests
|
/tests/unit/libstore/libnixstore-tests
|
||||||
|
|
||||||
# /src/libutil/
|
# /src/libutil/
|
||||||
/src/libutil/tests/libnixutil-tests
|
/tests/unit/libutil/libnixutil-tests
|
||||||
|
|
||||||
/src/nix/nix
|
/src/nix/nix
|
||||||
|
|
||||||
|
|
9
Makefile
9
Makefile
|
@ -23,9 +23,12 @@ makefiles = \
|
||||||
|
|
||||||
ifeq ($(tests), yes)
|
ifeq ($(tests), yes)
|
||||||
makefiles += \
|
makefiles += \
|
||||||
src/libutil/tests/local.mk \
|
tests/unit/libutil/local.mk \
|
||||||
src/libstore/tests/local.mk \
|
tests/unit/libutil-support/local.mk \
|
||||||
src/libexpr/tests/local.mk \
|
tests/unit/libstore/local.mk \
|
||||||
|
tests/unit/libstore-support/local.mk \
|
||||||
|
tests/unit/libexpr/local.mk \
|
||||||
|
tests/unit/libexpr-support/local.mk \
|
||||||
tests/functional/local.mk \
|
tests/functional/local.mk \
|
||||||
tests/functional/ca/local.mk \
|
tests/functional/ca/local.mk \
|
||||||
tests/functional/dyn-drv/local.mk \
|
tests/functional/dyn-drv/local.mk \
|
||||||
|
|
|
@ -39,17 +39,21 @@ INPUT = \
|
||||||
src/libcmd \
|
src/libcmd \
|
||||||
src/libexpr \
|
src/libexpr \
|
||||||
src/libexpr/flake \
|
src/libexpr/flake \
|
||||||
src/libexpr/tests \
|
tests/unit/libexpr \
|
||||||
src/libexpr/tests/value \
|
tests/unit/libexpr/value \
|
||||||
|
tests/unit/libexpr/test \
|
||||||
|
tests/unit/libexpr/test/value \
|
||||||
src/libexpr/value \
|
src/libexpr/value \
|
||||||
src/libfetchers \
|
src/libfetchers \
|
||||||
src/libmain \
|
src/libmain \
|
||||||
src/libstore \
|
src/libstore \
|
||||||
src/libstore/build \
|
src/libstore/build \
|
||||||
src/libstore/builtins \
|
src/libstore/builtins \
|
||||||
src/libstore/tests \
|
tests/unit/libstore \
|
||||||
|
tests/unit/libstore/test \
|
||||||
src/libutil \
|
src/libutil \
|
||||||
src/libutil/tests \
|
tests/unit/libutil \
|
||||||
|
tests/unit/libutil/test \
|
||||||
src/nix \
|
src/nix \
|
||||||
src/nix-env \
|
src/nix-env \
|
||||||
src/nix-store
|
src/nix-store
|
||||||
|
|
|
@ -3,13 +3,25 @@
|
||||||
## Unit-tests
|
## Unit-tests
|
||||||
|
|
||||||
The unit-tests for each Nix library (`libexpr`, `libstore`, etc..) are defined
|
The unit-tests for each Nix library (`libexpr`, `libstore`, etc..) are defined
|
||||||
under `src/{library_name}/tests` using the
|
under `tests/unit/{library_name}/tests` using the
|
||||||
[googletest](https://google.github.io/googletest/) and
|
[googletest](https://google.github.io/googletest/) and
|
||||||
[rapidcheck](https://github.com/emil-e/rapidcheck) frameworks.
|
[rapidcheck](https://github.com/emil-e/rapidcheck) frameworks.
|
||||||
|
|
||||||
You can run the whole testsuite with `make check`, or the tests for a specific component with `make libfoo-tests_RUN`.
|
You can run the whole testsuite with `make check`, or the tests for a specific component with `make libfoo-tests_RUN`.
|
||||||
Finer-grained filtering is also possible using the [--gtest_filter](https://google.github.io/googletest/advanced.html#running-a-subset-of-the-tests) command-line option, or the `GTEST_FILTER` environment variable.
|
Finer-grained filtering is also possible using the [--gtest_filter](https://google.github.io/googletest/advanced.html#running-a-subset-of-the-tests) command-line option, or the `GTEST_FILTER` environment variable.
|
||||||
|
|
||||||
|
### Unit test support libraries
|
||||||
|
|
||||||
|
There are headers and code which are not just used to test the library in question, but also downstream libraries.
|
||||||
|
For example, we do [property testing] with the [rapidcheck] library.
|
||||||
|
This requires writing `Arbitrary` "instances", which are used to describe how to generate values of a given type for the sake of running property tests.
|
||||||
|
Because types contain other types, `Arbitrary` "instances" for some type are not just useful for testing that type, but also any other type that contains it.
|
||||||
|
Downstream types frequently contain upstream types, so it is very important that we share arbitrary instances so that downstream libraries' property tests can also use them.
|
||||||
|
|
||||||
|
It is important that these testing libraries don't contain any actual tests themselves.
|
||||||
|
On some platforms they would be run as part of every test executable that uses them, which is redundant.
|
||||||
|
On other platforms they wouldn't be run at all.
|
||||||
|
|
||||||
## Functional tests
|
## Functional tests
|
||||||
|
|
||||||
The functional tests reside under the `tests/functional` directory and are listed in `tests/functional/local.mk`.
|
The functional tests reside under the `tests/functional` directory and are listed in `tests/functional/local.mk`.
|
||||||
|
|
|
@ -73,6 +73,7 @@
|
||||||
./precompiled-headers.h
|
./precompiled-headers.h
|
||||||
./src
|
./src
|
||||||
./tests/functional
|
./tests/functional
|
||||||
|
./tests/unit
|
||||||
./COPYING
|
./COPYING
|
||||||
./scripts/local.mk
|
./scripts/local.mk
|
||||||
(fileset.fileFilter (f: lib.strings.hasPrefix "nix-profile" f.name) ./scripts)
|
(fileset.fileFilter (f: lib.strings.hasPrefix "nix-profile" f.name) ./scripts)
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
check: libexpr-tests_RUN
|
|
||||||
|
|
||||||
programs += libexpr-tests
|
|
||||||
|
|
||||||
libexpr-tests_NAME := libnixexpr-tests
|
|
||||||
|
|
||||||
libexpr-tests_DIR := $(d)
|
|
||||||
|
|
||||||
libexpr-tests_INSTALL_DIR :=
|
|
||||||
|
|
||||||
libexpr-tests_SOURCES := \
|
|
||||||
$(wildcard $(d)/*.cc) \
|
|
||||||
$(wildcard $(d)/value/*.cc)
|
|
||||||
|
|
||||||
libexpr-tests_CXXFLAGS += -I src/libexpr -I src/libutil -I src/libstore -I src/libexpr/tests -I src/libfetchers
|
|
||||||
|
|
||||||
libexpr-tests_LIBS = libstore-tests libutils-tests libexpr libutil libstore libfetchers
|
|
||||||
|
|
||||||
libexpr-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS) -lgmock
|
|
|
@ -1,29 +0,0 @@
|
||||||
check: libstore-tests-exe_RUN
|
|
||||||
|
|
||||||
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)
|
|
||||||
|
|
||||||
libstore-tests_INSTALL_DIR :=
|
|
||||||
|
|
||||||
libstore-tests_SOURCES := $(wildcard $(d)/*.cc)
|
|
||||||
|
|
||||||
libstore-tests_CXXFLAGS += -I src/libstore -I src/libutil
|
|
||||||
|
|
||||||
libstore-tests_LIBS = libutil-tests libstore libutil
|
|
||||||
|
|
||||||
libstore-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS)
|
|
|
@ -1,29 +0,0 @@
|
||||||
check: libutil-tests_RUN
|
|
||||||
|
|
||||||
programs += libutil-tests
|
|
||||||
|
|
||||||
libutil-tests-exe_NAME = libnixutil-tests
|
|
||||||
|
|
||||||
libutil-tests-exe_DIR := $(d)
|
|
||||||
|
|
||||||
libutil-tests-exe_INSTALL_DIR :=
|
|
||||||
|
|
||||||
libutil-tests-exe_LIBS = libutil-tests
|
|
||||||
|
|
||||||
libutil-tests-exe_LDFLAGS := $(GTEST_LIBS)
|
|
||||||
|
|
||||||
libraries += libutil-tests
|
|
||||||
|
|
||||||
libutil-tests_NAME = libnixutil-tests
|
|
||||||
|
|
||||||
libutil-tests_DIR := $(d)
|
|
||||||
|
|
||||||
libutil-tests_INSTALL_DIR :=
|
|
||||||
|
|
||||||
libutil-tests_SOURCES := $(wildcard $(d)/*.cc)
|
|
||||||
|
|
||||||
libutil-tests_CXXFLAGS += -I src/libutil
|
|
||||||
|
|
||||||
libutil-tests_LIBS = libutil
|
|
||||||
|
|
||||||
libutil-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS)
|
|
19
tests/unit/libexpr-support/local.mk
Normal file
19
tests/unit/libexpr-support/local.mk
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
libraries += libexpr-test-support
|
||||||
|
|
||||||
|
libexpr-test-support_NAME = libnixexpr-test-support
|
||||||
|
|
||||||
|
libexpr-test-support_DIR := $(d)
|
||||||
|
|
||||||
|
libexpr-test-support_INSTALL_DIR :=
|
||||||
|
|
||||||
|
libexpr-test-support_SOURCES := \
|
||||||
|
$(wildcard $(d)/tests/*.cc) \
|
||||||
|
$(wildcard $(d)/tests/value/*.cc)
|
||||||
|
|
||||||
|
libexpr-test-support_CXXFLAGS += $(libexpr-tests_EXTRA_INCLUDES)
|
||||||
|
|
||||||
|
libexpr-test-support_LIBS = \
|
||||||
|
libstore-test-support libutil-test-support \
|
||||||
|
libexpr libstore libutil
|
||||||
|
|
||||||
|
libexpr-test-support_LDFLAGS := -lrapidcheck
|
30
tests/unit/libexpr-support/tests/value/context.cc
Normal file
30
tests/unit/libexpr-support/tests/value/context.cc
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
#include <rapidcheck.h>
|
||||||
|
|
||||||
|
#include "tests/path.hh"
|
||||||
|
#include "tests/value/context.hh"
|
||||||
|
|
||||||
|
namespace rc {
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
Gen<NixStringContextElem::DrvDeep> Arbitrary<NixStringContextElem::DrvDeep>::arbitrary()
|
||||||
|
{
|
||||||
|
return gen::just(NixStringContextElem::DrvDeep {
|
||||||
|
.drvPath = *gen::arbitrary<StorePath>(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Gen<NixStringContextElem> Arbitrary<NixStringContextElem>::arbitrary()
|
||||||
|
{
|
||||||
|
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<NixStringContextElem::Raw>)) {
|
||||||
|
case 0:
|
||||||
|
return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::Opaque>());
|
||||||
|
case 1:
|
||||||
|
return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::DrvDeep>());
|
||||||
|
case 2:
|
||||||
|
return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::Built>());
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <rapidcheck/gen/Arbitrary.h>
|
#include <rapidcheck/gen/Arbitrary.h>
|
||||||
|
|
||||||
#include <value/context.hh>
|
#include "value/context.hh"
|
||||||
|
|
||||||
namespace rc {
|
namespace rc {
|
||||||
using namespace nix;
|
using namespace nix;
|
32
tests/unit/libexpr/local.mk
Normal file
32
tests/unit/libexpr/local.mk
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
check: libexpr-tests_RUN
|
||||||
|
|
||||||
|
programs += libexpr-tests
|
||||||
|
|
||||||
|
libexpr-tests_NAME := libnixexpr-tests
|
||||||
|
|
||||||
|
libexpr-tests_ENV := _NIX_TEST_UNIT_DATA=$(d)/data
|
||||||
|
|
||||||
|
libexpr-tests_DIR := $(d)
|
||||||
|
|
||||||
|
libexpr-tests_INSTALL_DIR :=
|
||||||
|
|
||||||
|
libexpr-tests_SOURCES := \
|
||||||
|
$(wildcard $(d)/*.cc) \
|
||||||
|
$(wildcard $(d)/value/*.cc)
|
||||||
|
|
||||||
|
libexpr-tests_EXTRA_INCLUDES = \
|
||||||
|
-I tests/unit/libexpr-support \
|
||||||
|
-I tests/unit/libstore-support \
|
||||||
|
-I tests/unit/libutil-support \
|
||||||
|
-I src/libexpr \
|
||||||
|
-I src/libfetchers \
|
||||||
|
-I src/libstore \
|
||||||
|
-I src/libutil
|
||||||
|
|
||||||
|
libexpr-tests_CXXFLAGS += $(libexpr-tests_EXTRA_INCLUDES)
|
||||||
|
|
||||||
|
libexpr-tests_LIBS = \
|
||||||
|
libexpr-test-support libstore-test-support libutils-test-support \
|
||||||
|
libexpr libfetchers libstore libutil
|
||||||
|
|
||||||
|
libexpr-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS) -lgmock
|
|
@ -117,36 +117,6 @@ TEST(NixStringContextElemTest, built_built_xp) {
|
||||||
NixStringContextElem::parse("!foo!bar!g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x.drv"), MissingExperimentalFeature);
|
NixStringContextElem::parse("!foo!bar!g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x.drv"), MissingExperimentalFeature);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace rc {
|
|
||||||
using namespace nix;
|
|
||||||
|
|
||||||
Gen<NixStringContextElem::DrvDeep> Arbitrary<NixStringContextElem::DrvDeep>::arbitrary()
|
|
||||||
{
|
|
||||||
return gen::just(NixStringContextElem::DrvDeep {
|
|
||||||
.drvPath = *gen::arbitrary<StorePath>(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Gen<NixStringContextElem> Arbitrary<NixStringContextElem>::arbitrary()
|
|
||||||
{
|
|
||||||
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<NixStringContextElem::Raw>)) {
|
|
||||||
case 0:
|
|
||||||
return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::Opaque>());
|
|
||||||
case 1:
|
|
||||||
return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::DrvDeep>());
|
|
||||||
case 2:
|
|
||||||
return gen::just<NixStringContextElem>(*gen::arbitrary<NixStringContextElem::Built>());
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
#ifndef COVERAGE
|
#ifndef COVERAGE
|
||||||
|
|
||||||
RC_GTEST_PROP(
|
RC_GTEST_PROP(
|
17
tests/unit/libstore-support/local.mk
Normal file
17
tests/unit/libstore-support/local.mk
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
libraries += libstore-test-support
|
||||||
|
|
||||||
|
libstore-test-support_NAME = libnixstore-test-support
|
||||||
|
|
||||||
|
libstore-test-support_DIR := $(d)
|
||||||
|
|
||||||
|
libstore-test-support_INSTALL_DIR :=
|
||||||
|
|
||||||
|
libstore-test-support_SOURCES := $(wildcard $(d)/tests/*.cc)
|
||||||
|
|
||||||
|
libstore-test-support_CXXFLAGS += $(libstore-tests_EXTRA_INCLUDES)
|
||||||
|
|
||||||
|
libstore-test-support_LIBS = \
|
||||||
|
libutil-test-support \
|
||||||
|
libstore libutil
|
||||||
|
|
||||||
|
libstore-test-support_LDFLAGS := -lrapidcheck
|
57
tests/unit/libstore-support/tests/derived-path.cc
Normal file
57
tests/unit/libstore-support/tests/derived-path.cc
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
#include <rapidcheck.h>
|
||||||
|
|
||||||
|
#include "tests/derived-path.hh"
|
||||||
|
|
||||||
|
namespace rc {
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
Gen<DerivedPath::Opaque> Arbitrary<DerivedPath::Opaque>::arbitrary()
|
||||||
|
{
|
||||||
|
return gen::just(DerivedPath::Opaque {
|
||||||
|
.path = *gen::arbitrary<StorePath>(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Gen<SingleDerivedPath::Built> Arbitrary<SingleDerivedPath::Built>::arbitrary()
|
||||||
|
{
|
||||||
|
return gen::just(SingleDerivedPath::Built {
|
||||||
|
.drvPath = make_ref<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath>()),
|
||||||
|
.output = (*gen::arbitrary<StorePathName>()).name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Gen<DerivedPath::Built> Arbitrary<DerivedPath::Built>::arbitrary()
|
||||||
|
{
|
||||||
|
return gen::just(DerivedPath::Built {
|
||||||
|
.drvPath = make_ref<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath>()),
|
||||||
|
.outputs = *gen::arbitrary<OutputsSpec>(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Gen<SingleDerivedPath> Arbitrary<SingleDerivedPath>::arbitrary()
|
||||||
|
{
|
||||||
|
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<SingleDerivedPath::Raw>)) {
|
||||||
|
case 0:
|
||||||
|
return gen::just<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath::Opaque>());
|
||||||
|
case 1:
|
||||||
|
return gen::just<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath::Built>());
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Gen<DerivedPath> Arbitrary<DerivedPath>::arbitrary()
|
||||||
|
{
|
||||||
|
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<DerivedPath::Raw>)) {
|
||||||
|
case 0:
|
||||||
|
return gen::just<DerivedPath>(*gen::arbitrary<DerivedPath::Opaque>());
|
||||||
|
case 1:
|
||||||
|
return gen::just<DerivedPath>(*gen::arbitrary<DerivedPath::Built>());
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
24
tests/unit/libstore-support/tests/outputs-spec.cc
Normal file
24
tests/unit/libstore-support/tests/outputs-spec.cc
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
#include "tests/outputs-spec.hh"
|
||||||
|
|
||||||
|
#include <rapidcheck.h>
|
||||||
|
|
||||||
|
namespace rc {
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
Gen<OutputsSpec> Arbitrary<OutputsSpec>::arbitrary()
|
||||||
|
{
|
||||||
|
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<OutputsSpec::Raw>)) {
|
||||||
|
case 0:
|
||||||
|
return gen::just((OutputsSpec) OutputsSpec::All { });
|
||||||
|
case 1:
|
||||||
|
return gen::just((OutputsSpec) OutputsSpec::Names {
|
||||||
|
*gen::nonEmpty(gen::container<StringSet>(gen::map(
|
||||||
|
gen::arbitrary<StorePathName>(),
|
||||||
|
[](StorePathName n) { return n.name; }))),
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
#include <outputs-spec.hh>
|
#include <outputs-spec.hh>
|
||||||
|
|
||||||
#include <tests/path.hh>
|
#include "tests/path.hh"
|
||||||
|
|
||||||
namespace rc {
|
namespace rc {
|
||||||
using namespace nix;
|
using namespace nix;
|
82
tests/unit/libstore-support/tests/path.cc
Normal file
82
tests/unit/libstore-support/tests/path.cc
Normal file
|
@ -0,0 +1,82 @@
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
#include <rapidcheck.h>
|
||||||
|
|
||||||
|
#include "path-regex.hh"
|
||||||
|
#include "store-api.hh"
|
||||||
|
|
||||||
|
#include "tests/hash.hh"
|
||||||
|
#include "tests/path.hh"
|
||||||
|
|
||||||
|
namespace nix {
|
||||||
|
|
||||||
|
void showValue(const StorePath & p, std::ostream & os)
|
||||||
|
{
|
||||||
|
os << p.to_string();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace rc {
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
Gen<StorePathName> Arbitrary<StorePathName>::arbitrary()
|
||||||
|
{
|
||||||
|
auto len = *gen::inRange<size_t>(
|
||||||
|
1,
|
||||||
|
StorePath::MaxPathLen - StorePath::HashLen);
|
||||||
|
|
||||||
|
std::string pre;
|
||||||
|
pre.reserve(len);
|
||||||
|
|
||||||
|
for (size_t c = 0; c < len; ++c) {
|
||||||
|
switch (auto i = *gen::inRange<uint8_t>(0, 10 + 2 * 26 + 6)) {
|
||||||
|
case 0 ... 9:
|
||||||
|
pre += '0' + i;
|
||||||
|
case 10 ... 35:
|
||||||
|
pre += 'A' + (i - 10);
|
||||||
|
break;
|
||||||
|
case 36 ... 61:
|
||||||
|
pre += 'a' + (i - 36);
|
||||||
|
break;
|
||||||
|
case 62:
|
||||||
|
pre += '+';
|
||||||
|
break;
|
||||||
|
case 63:
|
||||||
|
pre += '-';
|
||||||
|
break;
|
||||||
|
case 64:
|
||||||
|
// names aren't permitted to start with a period,
|
||||||
|
// so just fall through to the next case here
|
||||||
|
if (c != 0) {
|
||||||
|
pre += '.';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 65:
|
||||||
|
pre += '_';
|
||||||
|
break;
|
||||||
|
case 66:
|
||||||
|
pre += '?';
|
||||||
|
break;
|
||||||
|
case 67:
|
||||||
|
pre += '=';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return gen::just(StorePathName {
|
||||||
|
.name = std::move(pre),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Gen<StorePath> Arbitrary<StorePath>::arbitrary()
|
||||||
|
{
|
||||||
|
return gen::just(StorePath {
|
||||||
|
*gen::arbitrary<Hash>(),
|
||||||
|
(*gen::arbitrary<StorePathName>()).name,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace rc
|
|
@ -11,6 +11,9 @@ struct StorePathName {
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// For rapidcheck
|
||||||
|
void showValue(const StorePath & p, std::ostream & os);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace rc {
|
namespace rc {
|
|
@ -1,64 +1,11 @@
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <rapidcheck/gtest.h>
|
#include <rapidcheck/gtest.h>
|
||||||
|
|
||||||
#include "tests/derived-path.hh"
|
#include "tests/derived-path.hh"
|
||||||
#include "tests/libstore.hh"
|
#include "tests/libstore.hh"
|
||||||
|
|
||||||
namespace rc {
|
|
||||||
using namespace nix;
|
|
||||||
|
|
||||||
Gen<DerivedPath::Opaque> Arbitrary<DerivedPath::Opaque>::arbitrary()
|
|
||||||
{
|
|
||||||
return gen::just(DerivedPath::Opaque {
|
|
||||||
.path = *gen::arbitrary<StorePath>(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Gen<SingleDerivedPath::Built> Arbitrary<SingleDerivedPath::Built>::arbitrary()
|
|
||||||
{
|
|
||||||
return gen::just(SingleDerivedPath::Built {
|
|
||||||
.drvPath = make_ref<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath>()),
|
|
||||||
.output = (*gen::arbitrary<StorePathName>()).name,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Gen<DerivedPath::Built> Arbitrary<DerivedPath::Built>::arbitrary()
|
|
||||||
{
|
|
||||||
return gen::just(DerivedPath::Built {
|
|
||||||
.drvPath = make_ref<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath>()),
|
|
||||||
.outputs = *gen::arbitrary<OutputsSpec>(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Gen<SingleDerivedPath> Arbitrary<SingleDerivedPath>::arbitrary()
|
|
||||||
{
|
|
||||||
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<SingleDerivedPath::Raw>)) {
|
|
||||||
case 0:
|
|
||||||
return gen::just<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath::Opaque>());
|
|
||||||
case 1:
|
|
||||||
return gen::just<SingleDerivedPath>(*gen::arbitrary<SingleDerivedPath::Built>());
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Gen<DerivedPath> Arbitrary<DerivedPath>::arbitrary()
|
|
||||||
{
|
|
||||||
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<DerivedPath::Raw>)) {
|
|
||||||
case 0:
|
|
||||||
return gen::just<DerivedPath>(*gen::arbitrary<DerivedPath::Opaque>());
|
|
||||||
case 1:
|
|
||||||
return gen::just<DerivedPath>(*gen::arbitrary<DerivedPath::Built>());
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
class DerivedPathTest : public LibStoreTest
|
class DerivedPathTest : public LibStoreTest
|
27
tests/unit/libstore/local.mk
Normal file
27
tests/unit/libstore/local.mk
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
check: libstore-tests_RUN
|
||||||
|
|
||||||
|
programs += libstore-tests
|
||||||
|
|
||||||
|
libstore-tests_NAME = libnixstore-tests
|
||||||
|
|
||||||
|
libstore-tests_ENV := _NIX_TEST_UNIT_DATA=$(d)/data
|
||||||
|
|
||||||
|
libstore-tests_DIR := $(d)
|
||||||
|
|
||||||
|
libstore-tests_INSTALL_DIR :=
|
||||||
|
|
||||||
|
libstore-tests_SOURCES := $(wildcard $(d)/*.cc)
|
||||||
|
|
||||||
|
libstore-tests_EXTRA_INCLUDES = \
|
||||||
|
-I tests/unit/libstore-support \
|
||||||
|
-I tests/unit/libutil-support \
|
||||||
|
-I src/libstore \
|
||||||
|
-I src/libutil
|
||||||
|
|
||||||
|
libstore-tests_CXXFLAGS += $(libstore-tests_EXTRA_INCLUDES)
|
||||||
|
|
||||||
|
libstore-tests_LIBS = \
|
||||||
|
libstore-test-support libutil-test-support \
|
||||||
|
libstore libutil
|
||||||
|
|
||||||
|
libstore-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS)
|
|
@ -137,7 +137,7 @@ TEST(machines, getMachinesWithIncorrectFormat) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(machines, getMachinesWithCorrectFileReference) {
|
TEST(machines, getMachinesWithCorrectFileReference) {
|
||||||
auto path = absPath("src/libstore/tests/test-data/machines.valid");
|
auto path = absPath("tests/unit/libstore/test-data/machines.valid");
|
||||||
ASSERT_TRUE(pathExists(path));
|
ASSERT_TRUE(pathExists(path));
|
||||||
|
|
||||||
settings.builders = std::string("@") + path;
|
settings.builders = std::string("@") + path;
|
||||||
|
@ -164,6 +164,6 @@ TEST(machines, getMachinesWithIncorrectFileReference) {
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(machines, getMachinesWithCorrectFileReferenceToIncorrectFile) {
|
TEST(machines, getMachinesWithCorrectFileReferenceToIncorrectFile) {
|
||||||
settings.builders = std::string("@") + absPath("src/libstore/tests/test-data/machines.bad_format");
|
settings.builders = std::string("@") + absPath("tests/unit/libstore/test-data/machines.bad_format");
|
||||||
EXPECT_THROW(getMachines(), FormatError);
|
EXPECT_THROW(getMachines(), FormatError);
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
#include "outputs-spec.hh"
|
#include "tests/outputs-spec.hh"
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
@ -199,31 +199,6 @@ TEST_JSON(ExtendedOutputsSpec, names, R"(["a","b"])", (ExtendedOutputsSpec::Expl
|
||||||
|
|
||||||
#undef TEST_JSON
|
#undef TEST_JSON
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace rc {
|
|
||||||
using namespace nix;
|
|
||||||
|
|
||||||
Gen<OutputsSpec> Arbitrary<OutputsSpec>::arbitrary()
|
|
||||||
{
|
|
||||||
switch (*gen::inRange<uint8_t>(0, std::variant_size_v<OutputsSpec::Raw>)) {
|
|
||||||
case 0:
|
|
||||||
return gen::just((OutputsSpec) OutputsSpec::All { });
|
|
||||||
case 1:
|
|
||||||
return gen::just((OutputsSpec) OutputsSpec::Names {
|
|
||||||
*gen::nonEmpty(gen::container<StringSet>(gen::map(
|
|
||||||
gen::arbitrary<StorePathName>(),
|
|
||||||
[](StorePathName n) { return n.name; }))),
|
|
||||||
});
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
#ifndef COVERAGE
|
#ifndef COVERAGE
|
||||||
|
|
||||||
RC_GTEST_PROP(
|
RC_GTEST_PROP(
|
|
@ -66,79 +66,6 @@ TEST_DO_PARSE(equals_sign, "foo=foo")
|
||||||
|
|
||||||
#undef TEST_DO_PARSE
|
#undef TEST_DO_PARSE
|
||||||
|
|
||||||
// For rapidcheck
|
|
||||||
void showValue(const StorePath & p, std::ostream & os) {
|
|
||||||
os << p.to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace rc {
|
|
||||||
using namespace nix;
|
|
||||||
|
|
||||||
Gen<StorePathName> Arbitrary<StorePathName>::arbitrary()
|
|
||||||
{
|
|
||||||
auto len = *gen::inRange<size_t>(
|
|
||||||
1,
|
|
||||||
StorePath::MaxPathLen - std::string_view { HASH_PART }.size());
|
|
||||||
|
|
||||||
std::string pre;
|
|
||||||
pre.reserve(len);
|
|
||||||
|
|
||||||
for (size_t c = 0; c < len; ++c) {
|
|
||||||
switch (auto i = *gen::inRange<uint8_t>(0, 10 + 2 * 26 + 6)) {
|
|
||||||
case 0 ... 9:
|
|
||||||
pre += '0' + i;
|
|
||||||
case 10 ... 35:
|
|
||||||
pre += 'A' + (i - 10);
|
|
||||||
break;
|
|
||||||
case 36 ... 61:
|
|
||||||
pre += 'a' + (i - 36);
|
|
||||||
break;
|
|
||||||
case 62:
|
|
||||||
pre += '+';
|
|
||||||
break;
|
|
||||||
case 63:
|
|
||||||
pre += '-';
|
|
||||||
break;
|
|
||||||
case 64:
|
|
||||||
// names aren't permitted to start with a period,
|
|
||||||
// so just fall through to the next case here
|
|
||||||
if (c != 0) {
|
|
||||||
pre += '.';
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 65:
|
|
||||||
pre += '_';
|
|
||||||
break;
|
|
||||||
case 66:
|
|
||||||
pre += '?';
|
|
||||||
break;
|
|
||||||
case 67:
|
|
||||||
pre += '=';
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return gen::just(StorePathName {
|
|
||||||
.name = std::move(pre),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
Gen<StorePath> Arbitrary<StorePath>::arbitrary()
|
|
||||||
{
|
|
||||||
return gen::just(StorePath {
|
|
||||||
*gen::arbitrary<Hash>(),
|
|
||||||
(*gen::arbitrary<StorePathName>()).name,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace rc
|
|
||||||
|
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
#ifndef COVERAGE
|
#ifndef COVERAGE
|
||||||
|
|
||||||
RC_GTEST_FIXTURE_PROP(
|
RC_GTEST_FIXTURE_PROP(
|
15
tests/unit/libutil-support/local.mk
Normal file
15
tests/unit/libutil-support/local.mk
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
libraries += libutil-test-support
|
||||||
|
|
||||||
|
libutil-test-support_NAME = libnixutil-test-support
|
||||||
|
|
||||||
|
libutil-test-support_DIR := $(d)
|
||||||
|
|
||||||
|
libutil-test-support_INSTALL_DIR :=
|
||||||
|
|
||||||
|
libutil-test-support_SOURCES := $(wildcard $(d)/tests/*.cc)
|
||||||
|
|
||||||
|
libutil-test-support_CXXFLAGS += $(libutil-tests_EXTRA_INCLUDES)
|
||||||
|
|
||||||
|
libutil-test-support_LIBS = libutil
|
||||||
|
|
||||||
|
libutil-test-support_LDFLAGS := -lrapidcheck
|
20
tests/unit/libutil-support/tests/hash.cc
Normal file
20
tests/unit/libutil-support/tests/hash.cc
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
#include <rapidcheck.h>
|
||||||
|
|
||||||
|
#include "hash.hh"
|
||||||
|
|
||||||
|
#include "tests/hash.hh"
|
||||||
|
|
||||||
|
namespace rc {
|
||||||
|
using namespace nix;
|
||||||
|
|
||||||
|
Gen<Hash> Arbitrary<Hash>::arbitrary()
|
||||||
|
{
|
||||||
|
Hash hash(htSHA1);
|
||||||
|
for (size_t i = 0; i < hash.hashSize; ++i)
|
||||||
|
hash.hash[i] = *gen::arbitrary<uint8_t>();
|
||||||
|
return gen::just(hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,12 +1,8 @@
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include <nlohmann/json.hpp>
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
#include <rapidcheck/gtest.h>
|
|
||||||
|
|
||||||
#include <hash.hh>
|
#include "hash.hh"
|
||||||
|
|
||||||
#include "tests/hash.hh"
|
|
||||||
|
|
||||||
namespace nix {
|
namespace nix {
|
||||||
|
|
||||||
|
@ -68,7 +64,6 @@ namespace nix {
|
||||||
"7ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd"
|
"7ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd"
|
||||||
"454d4423643ce80e2a9ac94fa54ca49f");
|
"454d4423643ce80e2a9ac94fa54ca49f");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(hashString, testKnownSHA512Hashes2) {
|
TEST(hashString, testKnownSHA512Hashes2) {
|
||||||
// values taken from: https://tools.ietf.org/html/rfc4634
|
// values taken from: https://tools.ietf.org/html/rfc4634
|
||||||
auto s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
auto s = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu";
|
||||||
|
@ -80,16 +75,3 @@ namespace nix {
|
||||||
"c7d329eeb6dd26545e96e55b874be909");
|
"c7d329eeb6dd26545e96e55b874be909");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace rc {
|
|
||||||
using namespace nix;
|
|
||||||
|
|
||||||
Gen<Hash> Arbitrary<Hash>::arbitrary()
|
|
||||||
{
|
|
||||||
Hash hash(htSHA1);
|
|
||||||
for (size_t i = 0; i < hash.hashSize; ++i)
|
|
||||||
hash.hash[i] = *gen::arbitrary<uint8_t>();
|
|
||||||
return gen::just(hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
23
tests/unit/libutil/local.mk
Normal file
23
tests/unit/libutil/local.mk
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
check: libutil-tests_RUN
|
||||||
|
|
||||||
|
programs += libutil-tests
|
||||||
|
|
||||||
|
libutil-tests_NAME = libnixutil-tests
|
||||||
|
|
||||||
|
libutil-tests_ENV := _NIX_TEST_UNIT_DATA=$(d)/data
|
||||||
|
|
||||||
|
libutil-tests_DIR := $(d)
|
||||||
|
|
||||||
|
libutil-tests_INSTALL_DIR :=
|
||||||
|
|
||||||
|
libutil-tests_SOURCES := $(wildcard $(d)/*.cc)
|
||||||
|
|
||||||
|
libutil-tests_EXTRA_INCLUDES = \
|
||||||
|
-I tests/unit/libutil-support \
|
||||||
|
-I src/libutil
|
||||||
|
|
||||||
|
libutil-tests_CXXFLAGS += $(libutil-tests_EXTRA_INCLUDES)
|
||||||
|
|
||||||
|
libutil-tests_LIBS = libutil-test-support libutil
|
||||||
|
|
||||||
|
libutil-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS)
|
Loading…
Reference in a new issue