diff --git a/.gitignore b/.gitignore index 04d96ca2c091..23ba1077f68c 100644 --- a/.gitignore +++ b/.gitignore @@ -41,14 +41,14 @@ perl/Makefile.config /src/libexpr/parser-tab.hh /src/libexpr/parser-tab.output /src/libexpr/nix.tbl -/src/libexpr/tests/libnixexpr-tests +/tests/unit/libexpr/libnixexpr-tests # /src/libstore/ *.gen.* -/src/libstore/tests/libnixstore-tests +/tests/unit/libstore/libnixstore-tests # /src/libutil/ -/src/libutil/tests/libnixutil-tests +/tests/unit/libutil/libnixutil-tests /src/nix/nix diff --git a/Makefile b/Makefile index 4f4ac0c6e295..87283fb335cf 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,11 @@ makefiles = \ endif ifeq ($(ENABLE_BUILD)_$(ENABLE_TESTS), yes_yes) -UNIT_TEST_ENV = _NIX_TEST_UNIT_DATA=unit-test-data +UNIT_TEST_ENV = _NIX_TEST_UNIT_DATA=tests/unit/data makefiles += \ - src/libutil/tests/local.mk \ - src/libstore/tests/local.mk \ - src/libexpr/tests/local.mk + tests/unit/libutil/local.mk \ + tests/unit/libstore/local.mk \ + tests/unit/libexpr/local.mk endif ifeq ($(ENABLE_TESTS), yes) diff --git a/doc/internal-api/doxygen.cfg.in b/doc/internal-api/doxygen.cfg.in index 599be2470b8f..ad5af97e6fe9 100644 --- a/doc/internal-api/doxygen.cfg.in +++ b/doc/internal-api/doxygen.cfg.in @@ -39,17 +39,21 @@ INPUT = \ src/libcmd \ src/libexpr \ src/libexpr/flake \ - src/libexpr/tests \ - src/libexpr/tests/value \ + tests/unit/libexpr \ + tests/unit/libexpr/value \ + tests/unit/libexpr/test \ + tests/unit/libexpr/test/value \ src/libexpr/value \ src/libfetchers \ src/libmain \ src/libstore \ src/libstore/build \ src/libstore/builtins \ - src/libstore/tests \ + tests/unit/libstore \ + tests/unit/libstore/test \ src/libutil \ - src/libutil/tests \ + tests/unit/libutil \ + tests/unit/libutil/test \ src/nix \ src/nix-env \ src/nix-store diff --git a/doc/manual/src/contributing/testing.md b/doc/manual/src/contributing/testing.md index 0b45b88a3239..42a4d6e15c37 100644 --- a/doc/manual/src/contributing/testing.md +++ b/doc/manual/src/contributing/testing.md @@ -30,32 +30,69 @@ The unit tests are defined using the [googletest] and [rapidcheck] frameworks. > ├── libexpr > │ ├── value/context.hh > │ ├── value/context.cc +> │ … +> │ +> ├── tests > │ │ > │ … -> └── tests -> │ ├── value/context.hh -> │ ├── value/context.cc +> │ └── unit +> │ ├── libutil +> │ │ │ +> │ │ … > │ │ +> │ ├── libexpr +> │ │ └── test +> │ │ ├── value/context.hh +> │ │ ├── value/context.cc +> │ │ … > │ … -> │ -> ├── unit-test-data -> │ ├── libstore -> │ │ ├── worker-protocol/content-address.bin -> │ │ … -> │ … +> │ └── data +> │ ├── libutil +> │ │ ├── git/tree.txt +> │ │ … +> │ ├── libexpr +> │ │ │ +> │ │ … +> │ … > … > ``` -The unit tests for each Nix library (`libnixexpr`, `libnixstore`, etc..) live inside a directory `src/${library_shortname}/tests` within the directory for the library (`src/${library_shortname}`). +The tests for each Nix library (`libnixexpr`, `libnixstore`, etc..) live inside a directory `src/${library_name_without-nix}-tests` next to the directory for the library (`src/${library_name_without-nix}`). +Given a interface (header) and implementation pair in the original library, say, `libexpr/value/context.{hh,cc}`, we write tests for it in `libexpr-tests/value/context.cc`, and (possibly) declare additional interfaces for testing purposes in `libexpr-tests/test/value/context.hh`. + +> **Note** +> +> Only the extra header is nested inside the `test` directory. This is explained further below. -The data is in `unit-test-data`, with one subdir per library, with the same name as where the code goes. -For example, `libnixstore` code is in `src/libstore`, and its test data is in `unit-test-data/libstore`. -The path to the `unit-test-data` directory is passed to the unit test executable with the environment variable `_NIX_TEST_UNIT_DATA`. +The data is in `tests/unit/data`, with one subdir per library, with the same name as where the code goes. +For example, `libnixstore` code is in `src/libstore`, and its test data is in `tests/unit/data/libstore`. +The path to the `tests/unit/data` directory is passed to the unit test executable with the environment variable `_NIX_TEST_UNIT_DATA`. > **Note** > Due to the way googletest works, downstream unit test executables will actually include and re-run upstream library tests. > Therefore it is important that the same value for `_NIX_TEST_UNIT_DATA` be used with the tests for each library. -> That is why we have the test data nested within a single `unit-test-data` directory. +> That is why we have the test data nested within a single `tests/unit/data` directory. + +### Rationale + +The use of a separate directory for the unit tests might seem inconvenient, as the tests are not "right next to" the part of the code they are testing. +But organizing the tests this way has one big benefit: +there is no risk of any build-system wildcards for the library accidentally picking up test code that shoud not built and installed as part of the library. + +Likewise, the use of the `test/` subdir might seem superfluous: +Isn't the point of the `*-test` subdir to indicate that these files are tests? +Why do we need another `test` subdirectory? +The answer is that we need to be able to tell apart the two headers, and make sure we include the right one. +For `.cc` files, this is matter of doing `#include "foo.hh"` vs `#include "tests/foo.hh` +For `.hh` files, this is a bit more subtle, because a `#include "foo.hh` instead `test/foo.hh` will end up including itself because `#include "..."` +[always prioritizes files in the same directory](https://pubs.opengroup.org/onlinepubs/9699919799/utilities/c99.html#tag_20_11_04), rather than the original header from the library. +Instead, use `#include ` to get the original library header, and `#include "tests/foo.hh"` to get the test header. + +Why do we have test headers at all? +These are usually for [rapidcheck]'s `Arbitrary` machinery, which is 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. +Indeed, if we don't reuse the upstream type's `Arbitrary` instance, the downstream type's `Arbitrary` instance would become much more complex and hard to understand. +In order to reuse these instances, we therefore declare them in these testing headers. ### Running tests diff --git a/flake.nix b/flake.nix index 51d8184233a4..fd6e5c25e0d2 100644 --- a/flake.nix +++ b/flake.nix @@ -91,7 +91,7 @@ ./misc ./precompiled-headers.h ./src - ./unit-test-data + ./tests/unit ./COPYING ./scripts/local.mk functionalTestFiles diff --git a/mk/common-test.sh b/mk/common-test.sh index 00ccd1584239..f493fb2bab37 100644 --- a/mk/common-test.sh +++ b/mk/common-test.sh @@ -1,7 +1,7 @@ # Remove overall test dir (at most one of the two should match) and # remove file extension. test_name=$(echo -n "$test" | sed \ - -e "s|^unit-test-data/||" \ + -e "s|^tests/unit/data/||" \ -e "s|^tests/functional/||" \ -e "s|\.sh$||" \ ) diff --git a/src/libexpr/tests/local.mk b/src/libexpr/tests/local.mk deleted file mode 100644 index 331a5ead60e4..000000000000 --- a/src/libexpr/tests/local.mk +++ /dev/null @@ -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 := $(GTEST_LIBS) -lgmock diff --git a/unit-test-data/libstore/common-protocol/content-address.bin b/tests/unit/data/libstore/common-protocol/content-address.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/content-address.bin rename to tests/unit/data/libstore/common-protocol/content-address.bin diff --git a/unit-test-data/libstore/common-protocol/drv-output.bin b/tests/unit/data/libstore/common-protocol/drv-output.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/drv-output.bin rename to tests/unit/data/libstore/common-protocol/drv-output.bin diff --git a/unit-test-data/libstore/common-protocol/optional-content-address.bin b/tests/unit/data/libstore/common-protocol/optional-content-address.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/optional-content-address.bin rename to tests/unit/data/libstore/common-protocol/optional-content-address.bin diff --git a/unit-test-data/libstore/common-protocol/optional-store-path.bin b/tests/unit/data/libstore/common-protocol/optional-store-path.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/optional-store-path.bin rename to tests/unit/data/libstore/common-protocol/optional-store-path.bin diff --git a/unit-test-data/libstore/common-protocol/realisation.bin b/tests/unit/data/libstore/common-protocol/realisation.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/realisation.bin rename to tests/unit/data/libstore/common-protocol/realisation.bin diff --git a/unit-test-data/libstore/common-protocol/set.bin b/tests/unit/data/libstore/common-protocol/set.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/set.bin rename to tests/unit/data/libstore/common-protocol/set.bin diff --git a/unit-test-data/libstore/common-protocol/store-path.bin b/tests/unit/data/libstore/common-protocol/store-path.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/store-path.bin rename to tests/unit/data/libstore/common-protocol/store-path.bin diff --git a/unit-test-data/libstore/common-protocol/string.bin b/tests/unit/data/libstore/common-protocol/string.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/string.bin rename to tests/unit/data/libstore/common-protocol/string.bin diff --git a/unit-test-data/libstore/common-protocol/vector.bin b/tests/unit/data/libstore/common-protocol/vector.bin similarity index 100% rename from unit-test-data/libstore/common-protocol/vector.bin rename to tests/unit/data/libstore/common-protocol/vector.bin diff --git a/unit-test-data/libstore/derivation/bad-old-version-dyn-deps.drv b/tests/unit/data/libstore/derivation/bad-old-version-dyn-deps.drv similarity index 100% rename from unit-test-data/libstore/derivation/bad-old-version-dyn-deps.drv rename to tests/unit/data/libstore/derivation/bad-old-version-dyn-deps.drv diff --git a/unit-test-data/libstore/derivation/bad-version.drv b/tests/unit/data/libstore/derivation/bad-version.drv similarity index 100% rename from unit-test-data/libstore/derivation/bad-version.drv rename to tests/unit/data/libstore/derivation/bad-version.drv diff --git a/unit-test-data/libstore/derivation/dynDerivationDeps.drv b/tests/unit/data/libstore/derivation/dynDerivationDeps.drv similarity index 100% rename from unit-test-data/libstore/derivation/dynDerivationDeps.drv rename to tests/unit/data/libstore/derivation/dynDerivationDeps.drv diff --git a/unit-test-data/libstore/derivation/dynDerivationDeps.json b/tests/unit/data/libstore/derivation/dynDerivationDeps.json similarity index 100% rename from unit-test-data/libstore/derivation/dynDerivationDeps.json rename to tests/unit/data/libstore/derivation/dynDerivationDeps.json diff --git a/unit-test-data/libstore/derivation/output-caFixedFlat.json b/tests/unit/data/libstore/derivation/output-caFixedFlat.json similarity index 100% rename from unit-test-data/libstore/derivation/output-caFixedFlat.json rename to tests/unit/data/libstore/derivation/output-caFixedFlat.json diff --git a/unit-test-data/libstore/derivation/output-caFixedNAR.json b/tests/unit/data/libstore/derivation/output-caFixedNAR.json similarity index 100% rename from unit-test-data/libstore/derivation/output-caFixedNAR.json rename to tests/unit/data/libstore/derivation/output-caFixedNAR.json diff --git a/unit-test-data/libstore/derivation/output-caFixedText.json b/tests/unit/data/libstore/derivation/output-caFixedText.json similarity index 100% rename from unit-test-data/libstore/derivation/output-caFixedText.json rename to tests/unit/data/libstore/derivation/output-caFixedText.json diff --git a/unit-test-data/libstore/derivation/output-caFloating.json b/tests/unit/data/libstore/derivation/output-caFloating.json similarity index 100% rename from unit-test-data/libstore/derivation/output-caFloating.json rename to tests/unit/data/libstore/derivation/output-caFloating.json diff --git a/unit-test-data/libstore/derivation/output-deferred.json b/tests/unit/data/libstore/derivation/output-deferred.json similarity index 100% rename from unit-test-data/libstore/derivation/output-deferred.json rename to tests/unit/data/libstore/derivation/output-deferred.json diff --git a/unit-test-data/libstore/derivation/output-impure.json b/tests/unit/data/libstore/derivation/output-impure.json similarity index 100% rename from unit-test-data/libstore/derivation/output-impure.json rename to tests/unit/data/libstore/derivation/output-impure.json diff --git a/unit-test-data/libstore/derivation/output-inputAddressed.json b/tests/unit/data/libstore/derivation/output-inputAddressed.json similarity index 100% rename from unit-test-data/libstore/derivation/output-inputAddressed.json rename to tests/unit/data/libstore/derivation/output-inputAddressed.json diff --git a/unit-test-data/libstore/derivation/simple.drv b/tests/unit/data/libstore/derivation/simple.drv similarity index 100% rename from unit-test-data/libstore/derivation/simple.drv rename to tests/unit/data/libstore/derivation/simple.drv diff --git a/unit-test-data/libstore/derivation/simple.json b/tests/unit/data/libstore/derivation/simple.json similarity index 100% rename from unit-test-data/libstore/derivation/simple.json rename to tests/unit/data/libstore/derivation/simple.json diff --git a/unit-test-data/libstore/nar-info/impure.json b/tests/unit/data/libstore/nar-info/impure.json similarity index 100% rename from unit-test-data/libstore/nar-info/impure.json rename to tests/unit/data/libstore/nar-info/impure.json diff --git a/unit-test-data/libstore/nar-info/pure.json b/tests/unit/data/libstore/nar-info/pure.json similarity index 100% rename from unit-test-data/libstore/nar-info/pure.json rename to tests/unit/data/libstore/nar-info/pure.json diff --git a/unit-test-data/libstore/path-info/impure.json b/tests/unit/data/libstore/path-info/impure.json similarity index 100% rename from unit-test-data/libstore/path-info/impure.json rename to tests/unit/data/libstore/path-info/impure.json diff --git a/unit-test-data/libstore/path-info/pure.json b/tests/unit/data/libstore/path-info/pure.json similarity index 100% rename from unit-test-data/libstore/path-info/pure.json rename to tests/unit/data/libstore/path-info/pure.json diff --git a/unit-test-data/libstore/serve-protocol/build-result-2.2.bin b/tests/unit/data/libstore/serve-protocol/build-result-2.2.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/build-result-2.2.bin rename to tests/unit/data/libstore/serve-protocol/build-result-2.2.bin diff --git a/unit-test-data/libstore/serve-protocol/build-result-2.3.bin b/tests/unit/data/libstore/serve-protocol/build-result-2.3.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/build-result-2.3.bin rename to tests/unit/data/libstore/serve-protocol/build-result-2.3.bin diff --git a/unit-test-data/libstore/serve-protocol/build-result-2.6.bin b/tests/unit/data/libstore/serve-protocol/build-result-2.6.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/build-result-2.6.bin rename to tests/unit/data/libstore/serve-protocol/build-result-2.6.bin diff --git a/unit-test-data/libstore/serve-protocol/content-address.bin b/tests/unit/data/libstore/serve-protocol/content-address.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/content-address.bin rename to tests/unit/data/libstore/serve-protocol/content-address.bin diff --git a/unit-test-data/libstore/serve-protocol/drv-output.bin b/tests/unit/data/libstore/serve-protocol/drv-output.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/drv-output.bin rename to tests/unit/data/libstore/serve-protocol/drv-output.bin diff --git a/unit-test-data/libstore/serve-protocol/optional-content-address.bin b/tests/unit/data/libstore/serve-protocol/optional-content-address.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/optional-content-address.bin rename to tests/unit/data/libstore/serve-protocol/optional-content-address.bin diff --git a/unit-test-data/libstore/serve-protocol/optional-store-path.bin b/tests/unit/data/libstore/serve-protocol/optional-store-path.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/optional-store-path.bin rename to tests/unit/data/libstore/serve-protocol/optional-store-path.bin diff --git a/unit-test-data/libstore/serve-protocol/realisation.bin b/tests/unit/data/libstore/serve-protocol/realisation.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/realisation.bin rename to tests/unit/data/libstore/serve-protocol/realisation.bin diff --git a/unit-test-data/libstore/serve-protocol/set.bin b/tests/unit/data/libstore/serve-protocol/set.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/set.bin rename to tests/unit/data/libstore/serve-protocol/set.bin diff --git a/unit-test-data/libstore/serve-protocol/store-path.bin b/tests/unit/data/libstore/serve-protocol/store-path.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/store-path.bin rename to tests/unit/data/libstore/serve-protocol/store-path.bin diff --git a/unit-test-data/libstore/serve-protocol/string.bin b/tests/unit/data/libstore/serve-protocol/string.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/string.bin rename to tests/unit/data/libstore/serve-protocol/string.bin diff --git a/unit-test-data/libstore/serve-protocol/vector.bin b/tests/unit/data/libstore/serve-protocol/vector.bin similarity index 100% rename from unit-test-data/libstore/serve-protocol/vector.bin rename to tests/unit/data/libstore/serve-protocol/vector.bin diff --git a/unit-test-data/libstore/worker-protocol/build-result-1.27.bin b/tests/unit/data/libstore/worker-protocol/build-result-1.27.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/build-result-1.27.bin rename to tests/unit/data/libstore/worker-protocol/build-result-1.27.bin diff --git a/unit-test-data/libstore/worker-protocol/build-result-1.28.bin b/tests/unit/data/libstore/worker-protocol/build-result-1.28.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/build-result-1.28.bin rename to tests/unit/data/libstore/worker-protocol/build-result-1.28.bin diff --git a/unit-test-data/libstore/worker-protocol/build-result-1.29.bin b/tests/unit/data/libstore/worker-protocol/build-result-1.29.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/build-result-1.29.bin rename to tests/unit/data/libstore/worker-protocol/build-result-1.29.bin diff --git a/unit-test-data/libstore/worker-protocol/content-address.bin b/tests/unit/data/libstore/worker-protocol/content-address.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/content-address.bin rename to tests/unit/data/libstore/worker-protocol/content-address.bin diff --git a/unit-test-data/libstore/worker-protocol/derived-path-1.29.bin b/tests/unit/data/libstore/worker-protocol/derived-path-1.29.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/derived-path-1.29.bin rename to tests/unit/data/libstore/worker-protocol/derived-path-1.29.bin diff --git a/unit-test-data/libstore/worker-protocol/derived-path-1.30.bin b/tests/unit/data/libstore/worker-protocol/derived-path-1.30.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/derived-path-1.30.bin rename to tests/unit/data/libstore/worker-protocol/derived-path-1.30.bin diff --git a/unit-test-data/libstore/worker-protocol/drv-output.bin b/tests/unit/data/libstore/worker-protocol/drv-output.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/drv-output.bin rename to tests/unit/data/libstore/worker-protocol/drv-output.bin diff --git a/unit-test-data/libstore/worker-protocol/keyed-build-result-1.29.bin b/tests/unit/data/libstore/worker-protocol/keyed-build-result-1.29.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/keyed-build-result-1.29.bin rename to tests/unit/data/libstore/worker-protocol/keyed-build-result-1.29.bin diff --git a/unit-test-data/libstore/worker-protocol/optional-content-address.bin b/tests/unit/data/libstore/worker-protocol/optional-content-address.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/optional-content-address.bin rename to tests/unit/data/libstore/worker-protocol/optional-content-address.bin diff --git a/unit-test-data/libstore/worker-protocol/optional-store-path.bin b/tests/unit/data/libstore/worker-protocol/optional-store-path.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/optional-store-path.bin rename to tests/unit/data/libstore/worker-protocol/optional-store-path.bin diff --git a/unit-test-data/libstore/worker-protocol/optional-trusted-flag.bin b/tests/unit/data/libstore/worker-protocol/optional-trusted-flag.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/optional-trusted-flag.bin rename to tests/unit/data/libstore/worker-protocol/optional-trusted-flag.bin diff --git a/unit-test-data/libstore/worker-protocol/realisation.bin b/tests/unit/data/libstore/worker-protocol/realisation.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/realisation.bin rename to tests/unit/data/libstore/worker-protocol/realisation.bin diff --git a/unit-test-data/libstore/worker-protocol/set.bin b/tests/unit/data/libstore/worker-protocol/set.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/set.bin rename to tests/unit/data/libstore/worker-protocol/set.bin diff --git a/unit-test-data/libstore/worker-protocol/store-path.bin b/tests/unit/data/libstore/worker-protocol/store-path.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/store-path.bin rename to tests/unit/data/libstore/worker-protocol/store-path.bin diff --git a/unit-test-data/libstore/worker-protocol/string.bin b/tests/unit/data/libstore/worker-protocol/string.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/string.bin rename to tests/unit/data/libstore/worker-protocol/string.bin diff --git a/unit-test-data/libstore/worker-protocol/unkeyed-valid-path-info-1.15.bin b/tests/unit/data/libstore/worker-protocol/unkeyed-valid-path-info-1.15.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/unkeyed-valid-path-info-1.15.bin rename to tests/unit/data/libstore/worker-protocol/unkeyed-valid-path-info-1.15.bin diff --git a/unit-test-data/libstore/worker-protocol/valid-path-info-1.15.bin b/tests/unit/data/libstore/worker-protocol/valid-path-info-1.15.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/valid-path-info-1.15.bin rename to tests/unit/data/libstore/worker-protocol/valid-path-info-1.15.bin diff --git a/unit-test-data/libstore/worker-protocol/valid-path-info-1.16.bin b/tests/unit/data/libstore/worker-protocol/valid-path-info-1.16.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/valid-path-info-1.16.bin rename to tests/unit/data/libstore/worker-protocol/valid-path-info-1.16.bin diff --git a/unit-test-data/libstore/worker-protocol/vector.bin b/tests/unit/data/libstore/worker-protocol/vector.bin similarity index 100% rename from unit-test-data/libstore/worker-protocol/vector.bin rename to tests/unit/data/libstore/worker-protocol/vector.bin diff --git a/unit-test-data/libutil/git/check-data.sh b/tests/unit/data/libutil/git/check-data.sh similarity index 98% rename from unit-test-data/libutil/git/check-data.sh rename to tests/unit/data/libutil/git/check-data.sh index 68b705c95c6e..b3f59c4f12ab 100644 --- a/unit-test-data/libutil/git/check-data.sh +++ b/tests/unit/data/libutil/git/check-data.sh @@ -2,7 +2,7 @@ set -eu -o pipefail -export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)/git-hashing/unit-test-data +export TEST_ROOT=$(realpath ${TMPDIR:-/tmp}/nix-test)/git-hashing/check-data mkdir -p $TEST_ROOT repo="$TEST_ROOT/scratch" diff --git a/unit-test-data/libutil/git/hello-world-blob.bin b/tests/unit/data/libutil/git/hello-world-blob.bin similarity index 100% rename from unit-test-data/libutil/git/hello-world-blob.bin rename to tests/unit/data/libutil/git/hello-world-blob.bin diff --git a/unit-test-data/libutil/git/hello-world.bin b/tests/unit/data/libutil/git/hello-world.bin similarity index 100% rename from unit-test-data/libutil/git/hello-world.bin rename to tests/unit/data/libutil/git/hello-world.bin diff --git a/unit-test-data/libutil/git/tree.bin b/tests/unit/data/libutil/git/tree.bin similarity index 100% rename from unit-test-data/libutil/git/tree.bin rename to tests/unit/data/libutil/git/tree.bin diff --git a/unit-test-data/libutil/git/tree.txt b/tests/unit/data/libutil/git/tree.txt similarity index 100% rename from unit-test-data/libutil/git/tree.txt rename to tests/unit/data/libutil/git/tree.txt diff --git a/tests/unit/libexpr/local.mk b/tests/unit/libexpr/local.mk new file mode 100644 index 000000000000..b17a9fcd86c9 --- /dev/null +++ b/tests/unit/libexpr/local.mk @@ -0,0 +1,28 @@ +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)/tests/*.cc) \ + $(wildcard $(d)/tests/value/*.cc) + +libexpr-tests_CXXFLAGS += \ + -I tests/unit/libexpr \ + -I tests/unit/libstore \ + -I tests/unit/libutil \ + -I src/libexpr \ + -I src/libfetchers \ + -I src/libstore \ + -I src/libutil + +libexpr-tests_LIBS = \ + libstore-tests libutils-tests \ + libexpr libfetchers libstore libutil + +libexpr-tests_LDFLAGS := $(GTEST_LIBS) -lgmock diff --git a/src/libexpr/tests/derived-path.cc b/tests/unit/libexpr/tests/derived-path.cc similarity index 100% rename from src/libexpr/tests/derived-path.cc rename to tests/unit/libexpr/tests/derived-path.cc diff --git a/src/libexpr/tests/error_traces.cc b/tests/unit/libexpr/tests/error_traces.cc similarity index 100% rename from src/libexpr/tests/error_traces.cc rename to tests/unit/libexpr/tests/error_traces.cc diff --git a/src/libexpr/tests/flakeref.cc b/tests/unit/libexpr/tests/flakeref.cc similarity index 100% rename from src/libexpr/tests/flakeref.cc rename to tests/unit/libexpr/tests/flakeref.cc diff --git a/src/libexpr/tests/json.cc b/tests/unit/libexpr/tests/json.cc similarity index 100% rename from src/libexpr/tests/json.cc rename to tests/unit/libexpr/tests/json.cc diff --git a/src/libexpr/tests/libexpr.hh b/tests/unit/libexpr/tests/libexpr.hh similarity index 100% rename from src/libexpr/tests/libexpr.hh rename to tests/unit/libexpr/tests/libexpr.hh diff --git a/src/libexpr/tests/primops.cc b/tests/unit/libexpr/tests/primops.cc similarity index 100% rename from src/libexpr/tests/primops.cc rename to tests/unit/libexpr/tests/primops.cc diff --git a/src/libexpr/tests/search-path.cc b/tests/unit/libexpr/tests/search-path.cc similarity index 100% rename from src/libexpr/tests/search-path.cc rename to tests/unit/libexpr/tests/search-path.cc diff --git a/src/libexpr/tests/trivial.cc b/tests/unit/libexpr/tests/trivial.cc similarity index 100% rename from src/libexpr/tests/trivial.cc rename to tests/unit/libexpr/tests/trivial.cc diff --git a/src/libexpr/tests/value/context.hh b/tests/unit/libexpr/tests/value/context.hh similarity index 95% rename from src/libexpr/tests/value/context.hh rename to tests/unit/libexpr/tests/value/context.hh index c0bc97ba3c46..8c68c78bbd1c 100644 --- a/src/libexpr/tests/value/context.hh +++ b/tests/unit/libexpr/tests/value/context.hh @@ -3,7 +3,7 @@ #include -#include +#include "value/context.hh" namespace rc { using namespace nix; diff --git a/src/libexpr/tests/value/print.cc b/tests/unit/libexpr/tests/value/print.cc similarity index 100% rename from src/libexpr/tests/value/print.cc rename to tests/unit/libexpr/tests/value/print.cc diff --git a/src/libexpr/tests/value/context.cc b/tests/unit/libexpr/value/context.cc similarity index 100% rename from src/libexpr/tests/value/context.cc rename to tests/unit/libexpr/value/context.cc diff --git a/src/libstore/tests/local.mk b/tests/unit/libstore/local.mk similarity index 64% rename from src/libstore/tests/local.mk rename to tests/unit/libstore/local.mk index 03becc7d11b6..92ec8e355bf4 100644 --- a/src/libstore/tests/local.mk +++ b/tests/unit/libstore/local.mk @@ -20,10 +20,16 @@ libstore-tests_DIR := $(d) libstore-tests_INSTALL_DIR := -libstore-tests_SOURCES := $(wildcard $(d)/*.cc) +libstore-tests_SOURCES := $(wildcard $(d)/tests/*.cc) -libstore-tests_CXXFLAGS += -I src/libstore -I src/libutil +libstore-tests_CXXFLAGS += \ + -I tests/unit/libstore \ + -I tests/unit/libutil \ + -I src/libstore \ + -I src/libutil -libstore-tests_LIBS = libutil-tests libstore libutil +libstore-tests_LIBS = \ + libutil-tests \ + libstore libutil libstore-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS) diff --git a/src/libstore/tests/test-data/machines.bad_format b/tests/unit/libstore/test-data/machines.bad_format similarity index 100% rename from src/libstore/tests/test-data/machines.bad_format rename to tests/unit/libstore/test-data/machines.bad_format diff --git a/src/libstore/tests/test-data/machines.valid b/tests/unit/libstore/test-data/machines.valid similarity index 100% rename from src/libstore/tests/test-data/machines.valid rename to tests/unit/libstore/test-data/machines.valid diff --git a/src/libstore/tests/common-protocol.cc b/tests/unit/libstore/tests/common-protocol.cc similarity index 100% rename from src/libstore/tests/common-protocol.cc rename to tests/unit/libstore/tests/common-protocol.cc diff --git a/src/libstore/tests/derivation.cc b/tests/unit/libstore/tests/derivation.cc similarity index 100% rename from src/libstore/tests/derivation.cc rename to tests/unit/libstore/tests/derivation.cc diff --git a/src/libstore/tests/derived-path.cc b/tests/unit/libstore/tests/derived-path.cc similarity index 100% rename from src/libstore/tests/derived-path.cc rename to tests/unit/libstore/tests/derived-path.cc diff --git a/src/libstore/tests/derived-path.hh b/tests/unit/libstore/tests/derived-path.hh similarity index 100% rename from src/libstore/tests/derived-path.hh rename to tests/unit/libstore/tests/derived-path.hh diff --git a/src/libstore/tests/downstream-placeholder.cc b/tests/unit/libstore/tests/downstream-placeholder.cc similarity index 100% rename from src/libstore/tests/downstream-placeholder.cc rename to tests/unit/libstore/tests/downstream-placeholder.cc diff --git a/src/libstore/tests/libstore.hh b/tests/unit/libstore/tests/libstore.hh similarity index 100% rename from src/libstore/tests/libstore.hh rename to tests/unit/libstore/tests/libstore.hh diff --git a/src/libstore/tests/machines.cc b/tests/unit/libstore/tests/machines.cc similarity index 97% rename from src/libstore/tests/machines.cc rename to tests/unit/libstore/tests/machines.cc index fede328ea3f3..5b66e5a5be93 100644 --- a/src/libstore/tests/machines.cc +++ b/tests/unit/libstore/tests/machines.cc @@ -139,7 +139,7 @@ TEST(machines, getMachinesWithIncorrectFormat) { } 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)); settings.builders = std::string("@") + path; @@ -166,6 +166,6 @@ TEST(machines, getMachinesWithIncorrectFileReference) { } 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); } diff --git a/src/libstore/tests/nar-info-disk-cache.cc b/tests/unit/libstore/tests/nar-info-disk-cache.cc similarity index 100% rename from src/libstore/tests/nar-info-disk-cache.cc rename to tests/unit/libstore/tests/nar-info-disk-cache.cc diff --git a/src/libstore/tests/nar-info.cc b/tests/unit/libstore/tests/nar-info.cc similarity index 100% rename from src/libstore/tests/nar-info.cc rename to tests/unit/libstore/tests/nar-info.cc diff --git a/src/libstore/tests/outputs-spec.cc b/tests/unit/libstore/tests/outputs-spec.cc similarity index 99% rename from src/libstore/tests/outputs-spec.cc rename to tests/unit/libstore/tests/outputs-spec.cc index 95294518544b..214afda4e34c 100644 --- a/src/libstore/tests/outputs-spec.cc +++ b/tests/unit/libstore/tests/outputs-spec.cc @@ -1,4 +1,4 @@ -#include "outputs-spec.hh" +#include "tests/outputs-spec.hh" #include #include diff --git a/src/libstore/tests/outputs-spec.hh b/tests/unit/libstore/tests/outputs-spec.hh similarity index 89% rename from src/libstore/tests/outputs-spec.hh rename to tests/unit/libstore/tests/outputs-spec.hh index ded331b333e3..f5bf9042d201 100644 --- a/src/libstore/tests/outputs-spec.hh +++ b/tests/unit/libstore/tests/outputs-spec.hh @@ -5,7 +5,7 @@ #include -#include +#include "tests/path.hh" namespace rc { using namespace nix; diff --git a/src/libstore/tests/path-info.cc b/tests/unit/libstore/tests/path-info.cc similarity index 100% rename from src/libstore/tests/path-info.cc rename to tests/unit/libstore/tests/path-info.cc diff --git a/src/libstore/tests/path.cc b/tests/unit/libstore/tests/path.cc similarity index 100% rename from src/libstore/tests/path.cc rename to tests/unit/libstore/tests/path.cc diff --git a/src/libstore/tests/path.hh b/tests/unit/libstore/tests/path.hh similarity index 100% rename from src/libstore/tests/path.hh rename to tests/unit/libstore/tests/path.hh diff --git a/src/libstore/tests/protocol.hh b/tests/unit/libstore/tests/protocol.hh similarity index 100% rename from src/libstore/tests/protocol.hh rename to tests/unit/libstore/tests/protocol.hh diff --git a/src/libstore/tests/references.cc b/tests/unit/libstore/tests/references.cc similarity index 100% rename from src/libstore/tests/references.cc rename to tests/unit/libstore/tests/references.cc diff --git a/src/libstore/tests/serve-protocol.cc b/tests/unit/libstore/tests/serve-protocol.cc similarity index 100% rename from src/libstore/tests/serve-protocol.cc rename to tests/unit/libstore/tests/serve-protocol.cc diff --git a/src/libstore/tests/worker-protocol.cc b/tests/unit/libstore/tests/worker-protocol.cc similarity index 100% rename from src/libstore/tests/worker-protocol.cc rename to tests/unit/libstore/tests/worker-protocol.cc diff --git a/src/libutil/tests/local.mk b/tests/unit/libutil/local.mk similarity index 64% rename from src/libutil/tests/local.mk rename to tests/unit/libutil/local.mk index 5a970c0f20b3..a6462ae117f8 100644 --- a/src/libutil/tests/local.mk +++ b/tests/unit/libutil/local.mk @@ -20,14 +20,16 @@ libutil-tests_DIR := $(d) libutil-tests_INSTALL_DIR := -libutil-tests_SOURCES := $(wildcard $(d)/*.cc) +libutil-tests_SOURCES := $(wildcard $(d)/tests/*.cc) -libutil-tests_CXXFLAGS += -I src/libutil +libutil-tests_CXXFLAGS += \ + -I tests/unit/libutil \ + -I src/libutil libutil-tests_LIBS = libutil libutil-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS) -check: unit-test-data/libutil/git/check-data.sh.test +check: tests/unit/data/libutil/git/check-data.sh.test -$(eval $(call run-test,unit-test-data/libutil/git/check-data.sh)) +$(eval $(call run-test,tests/unit/data/libutil/git/check-data.sh)) diff --git a/src/libutil/tests/args.cc b/tests/unit/libutil/tests/args.cc similarity index 98% rename from src/libutil/tests/args.cc rename to tests/unit/libutil/tests/args.cc index bea74a8c8393..950224430065 100644 --- a/src/libutil/tests/args.cc +++ b/tests/unit/libutil/tests/args.cc @@ -1,5 +1,5 @@ -#include "../args.hh" -#include "libutil/fs-sink.hh" +#include "args.hh" +#include "fs-sink.hh" #include #include @@ -165,4 +165,4 @@ RC_GTEST_PROP( #endif -} \ No newline at end of file +} diff --git a/src/libutil/tests/canon-path.cc b/tests/unit/libutil/tests/canon-path.cc similarity index 100% rename from src/libutil/tests/canon-path.cc rename to tests/unit/libutil/tests/canon-path.cc diff --git a/src/libutil/tests/characterization.hh b/tests/unit/libutil/tests/characterization.hh similarity index 97% rename from src/libutil/tests/characterization.hh rename to tests/unit/libutil/tests/characterization.hh index 6eb513d68746..1a897bb5f2a5 100644 --- a/src/libutil/tests/characterization.hh +++ b/tests/unit/libutil/tests/characterization.hh @@ -9,7 +9,7 @@ namespace nix { /** - * The path to the `unit-test-data` directory. See the contributing + * The path to the `tests/unit/data` directory. See the contributing * guide in the manual for further details. */ static Path getUnitTestData() { diff --git a/src/libutil/tests/chunked-vector.cc b/tests/unit/libutil/tests/chunked-vector.cc similarity index 100% rename from src/libutil/tests/chunked-vector.cc rename to tests/unit/libutil/tests/chunked-vector.cc diff --git a/src/libutil/tests/closure.cc b/tests/unit/libutil/tests/closure.cc similarity index 100% rename from src/libutil/tests/closure.cc rename to tests/unit/libutil/tests/closure.cc diff --git a/src/libutil/tests/compression.cc b/tests/unit/libutil/tests/compression.cc similarity index 100% rename from src/libutil/tests/compression.cc rename to tests/unit/libutil/tests/compression.cc diff --git a/src/libutil/tests/config.cc b/tests/unit/libutil/tests/config.cc similarity index 100% rename from src/libutil/tests/config.cc rename to tests/unit/libutil/tests/config.cc diff --git a/src/libutil/tests/git.cc b/tests/unit/libutil/tests/git.cc similarity index 99% rename from src/libutil/tests/git.cc rename to tests/unit/libutil/tests/git.cc index 2842ea4d03f5..8aeb994e2591 100644 --- a/src/libutil/tests/git.cc +++ b/tests/unit/libutil/tests/git.cc @@ -87,7 +87,7 @@ TEST_F(GitTest, blob_write) { /** * This data is for "shallow" tree tests. However, we use "real" hashes * so that we can check our test data in the corresponding functional - * test (`git-hashing/unit-test-data`). + * test (`git-hashing/tests/unit/data`). */ const static Tree tree = { { diff --git a/src/libutil/tests/hash.cc b/tests/unit/libutil/tests/hash.cc similarity index 99% rename from src/libutil/tests/hash.cc rename to tests/unit/libutil/tests/hash.cc index 9a5ebbb30fdc..813aaf1f186e 100644 --- a/src/libutil/tests/hash.cc +++ b/tests/unit/libutil/tests/hash.cc @@ -4,7 +4,7 @@ #include #include -#include +#include "hash.hh" #include "tests/hash.hh" diff --git a/src/libutil/tests/hash.hh b/tests/unit/libutil/tests/hash.hh similarity index 100% rename from src/libutil/tests/hash.hh rename to tests/unit/libutil/tests/hash.hh diff --git a/src/libutil/tests/hilite.cc b/tests/unit/libutil/tests/hilite.cc similarity index 100% rename from src/libutil/tests/hilite.cc rename to tests/unit/libutil/tests/hilite.cc diff --git a/src/libutil/tests/logging.cc b/tests/unit/libutil/tests/logging.cc similarity index 100% rename from src/libutil/tests/logging.cc rename to tests/unit/libutil/tests/logging.cc diff --git a/src/libutil/tests/lru-cache.cc b/tests/unit/libutil/tests/lru-cache.cc similarity index 100% rename from src/libutil/tests/lru-cache.cc rename to tests/unit/libutil/tests/lru-cache.cc diff --git a/src/libutil/tests/pool.cc b/tests/unit/libutil/tests/pool.cc similarity index 100% rename from src/libutil/tests/pool.cc rename to tests/unit/libutil/tests/pool.cc diff --git a/src/libutil/tests/references.cc b/tests/unit/libutil/tests/references.cc similarity index 100% rename from src/libutil/tests/references.cc rename to tests/unit/libutil/tests/references.cc diff --git a/src/libutil/tests/suggestions.cc b/tests/unit/libutil/tests/suggestions.cc similarity index 100% rename from src/libutil/tests/suggestions.cc rename to tests/unit/libutil/tests/suggestions.cc diff --git a/src/libutil/tests/tests.cc b/tests/unit/libutil/tests/tests.cc similarity index 100% rename from src/libutil/tests/tests.cc rename to tests/unit/libutil/tests/tests.cc diff --git a/src/libutil/tests/url.cc b/tests/unit/libutil/tests/url.cc similarity index 100% rename from src/libutil/tests/url.cc rename to tests/unit/libutil/tests/url.cc diff --git a/src/libutil/tests/xml-writer.cc b/tests/unit/libutil/tests/xml-writer.cc similarity index 100% rename from src/libutil/tests/xml-writer.cc rename to tests/unit/libutil/tests/xml-writer.cc