From 65e690a087e1f946c54d660886d63d13b0865ade Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 25 Jan 2023 11:27:52 +0100 Subject: [PATCH 1/4] Revert "Add `rapidcheck` dependency for testing" This reverts commit c92e51ecec88dcb1e3485e50431bd66099b67c7f. --- configure.ac | 6 ------ doc/manual/src/contributing/hacking.md | 3 +-- flake.nix | 5 +---- src/libstore/tests/local.mk | 2 +- 4 files changed, 3 insertions(+), 13 deletions(-) diff --git a/configure.ac b/configure.ac index 0066bc389..1b0d6fd27 100644 --- a/configure.ac +++ b/configure.ac @@ -274,12 +274,6 @@ fi PKG_CHECK_MODULES([GTEST], [gtest_main]) -# Look for rapidcheck. -# No pkg-config yet, https://github.com/emil-e/rapidcheck/issues/302 -AC_CHECK_HEADERS([rapidcheck/gtest.h], [], [], [#include ]) -AC_CHECK_LIB([rapidcheck], []) - - # Look for nlohmann/json. PKG_CHECK_MODULES([NLOHMANN_JSON], [nlohmann_json >= 3.9]) diff --git a/doc/manual/src/contributing/hacking.md b/doc/manual/src/contributing/hacking.md index 9dbafcc0a..aeb0d41b3 100644 --- a/doc/manual/src/contributing/hacking.md +++ b/doc/manual/src/contributing/hacking.md @@ -92,8 +92,7 @@ $ nix develop The unit-tests for each Nix library (`libexpr`, `libstore`, etc..) are defined under `src/{library_name}/tests` using the -[googletest](https://google.github.io/googletest/) and -[rapidcheck](https://github.com/emil-e/rapidcheck) frameworks. +[googletest](https://google.github.io/googletest/) framework. 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. diff --git a/flake.nix b/flake.nix index 549ded43d..ce80fbd56 100644 --- a/flake.nix +++ b/flake.nix @@ -82,9 +82,7 @@ }); configureFlags = - [ - "CXXFLAGS=-I${lib.getDev rapidcheck}/extras/gtest/include" - ] ++ lib.optionals stdenv.isLinux [ + lib.optionals stdenv.isLinux [ "--with-boost=${boost}/lib" "--with-sandbox-shell=${sh}/bin/busybox" ] @@ -118,7 +116,6 @@ boost lowdown-nix gtest - rapidcheck ] ++ lib.optionals stdenv.isLinux [libseccomp] ++ lib.optional (stdenv.isLinux || stdenv.isDarwin) libsodium diff --git a/src/libstore/tests/local.mk b/src/libstore/tests/local.mk index a2cf8a0cf..f74295d97 100644 --- a/src/libstore/tests/local.mk +++ b/src/libstore/tests/local.mk @@ -12,4 +12,4 @@ libstore-tests_CXXFLAGS += -I src/libstore -I src/libutil libstore-tests_LIBS = libstore libutil -libstore-tests_LDFLAGS := -lrapidcheck $(GTEST_LIBS) +libstore-tests_LDFLAGS := $(GTEST_LIBS) From 9566203d0d65e7146fee1b26bb93f41fbf8a6a32 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 25 Jan 2023 11:28:36 +0100 Subject: [PATCH 2/4] Partially revert "Test store paths, with property tests" This reverts the addition of property tests from commit d111d2ed49a2ba9563d6379977c7e1671a2410f4. --- src/libstore/tests/libstoretests.hh | 23 ----- src/libstore/tests/path.cc | 144 ---------------------------- 2 files changed, 167 deletions(-) delete mode 100644 src/libstore/tests/libstoretests.hh delete mode 100644 src/libstore/tests/path.cc diff --git a/src/libstore/tests/libstoretests.hh b/src/libstore/tests/libstoretests.hh deleted file mode 100644 index 05397659b..000000000 --- a/src/libstore/tests/libstoretests.hh +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include - -#include "store-api.hh" - -namespace nix { - -class LibStoreTest : public ::testing::Test { - public: - static void SetUpTestSuite() { - initLibStore(); - } - - protected: - LibStoreTest() - : store(openStore("dummy://")) - { } - - ref store; -}; - - -} /* namespace nix */ diff --git a/src/libstore/tests/path.cc b/src/libstore/tests/path.cc deleted file mode 100644 index 8ea252c92..000000000 --- a/src/libstore/tests/path.cc +++ /dev/null @@ -1,144 +0,0 @@ -#include - -#include -#include -#include - -#include "path-regex.hh" -#include "store-api.hh" - -#include "libstoretests.hh" - -namespace nix { - -#define STORE_DIR "/nix/store/" -#define HASH_PART "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q" - -class StorePathTest : public LibStoreTest -{ -}; - -static std::regex nameRegex { std::string { nameRegexStr } }; - -#define TEST_DONT_PARSE(NAME, STR) \ - TEST_F(StorePathTest, bad_ ## NAME) { \ - std::string_view str = \ - STORE_DIR HASH_PART "-" STR; \ - ASSERT_THROW( \ - store->parseStorePath(str), \ - BadStorePath); \ - std::string name { STR }; \ - EXPECT_FALSE(std::regex_match(name, nameRegex)); \ - } - -TEST_DONT_PARSE(empty, "") -TEST_DONT_PARSE(garbage, "&*()") -TEST_DONT_PARSE(double_star, "**") -TEST_DONT_PARSE(star_first, "*,foo") -TEST_DONT_PARSE(star_second, "foo,*") -TEST_DONT_PARSE(bang, "foo!o") - -#undef TEST_DONT_PARSE - -#define TEST_DO_PARSE(NAME, STR) \ - TEST_F(StorePathTest, good_ ## NAME) { \ - std::string_view str = \ - STORE_DIR HASH_PART "-" STR; \ - auto p = store->parseStorePath(str); \ - std::string name { p.name() }; \ - EXPECT_TRUE(std::regex_match(name, nameRegex)); \ - } - -// 0-9 a-z A-Z + - . _ ? = - -TEST_DO_PARSE(numbers, "02345") -TEST_DO_PARSE(lower_case, "foo") -TEST_DO_PARSE(upper_case, "FOO") -TEST_DO_PARSE(plus, "foo+bar") -TEST_DO_PARSE(dash, "foo-dev") -TEST_DO_PARSE(underscore, "foo_bar") -TEST_DO_PARSE(period, "foo.txt") -TEST_DO_PARSE(question_mark, "foo?why") -TEST_DO_PARSE(equals_sign, "foo=foo") - -#undef TEST_DO_PARSE - -// For rapidcheck -void showValue(const StorePath & p, std::ostream & os) { - os << p.to_string(); -} - -} - -namespace rc { -using namespace nix; - -template<> -struct Arbitrary { - static Gen arbitrary(); -}; - -Gen Arbitrary::arbitrary() -{ - auto len = *gen::inRange(1, StorePath::MaxPathLen); - - std::string pre { HASH_PART "-" }; - pre.reserve(pre.size() + len); - - for (size_t c = 0; c < len; ++c) { - switch (auto i = *gen::inRange(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: - pre += '.'; - break; - case 65: - pre += '_'; - break; - case 66: - pre += '?'; - break; - case 67: - pre += '='; - break; - default: - assert(false); - } - } - - return gen::just(StorePath { pre }); -} - -} // namespace rc - -namespace nix { - -RC_GTEST_FIXTURE_PROP( - StorePathTest, - prop_regex_accept, - (const StorePath & p)) -{ - RC_ASSERT(std::regex_match(std::string { p.name() }, nameRegex)); -} - -RC_GTEST_FIXTURE_PROP( - StorePathTest, - prop_round_rip, - (const StorePath & p)) -{ - RC_ASSERT(p == store->parseStorePath(store->printStorePath(p))); -} - -} From 3424e1e055398718918ac51a1d84f16cac514dd9 Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 25 Jan 2023 18:08:57 +0100 Subject: [PATCH 3/4] Revert "Try to fix #7669" We've decided against backporting rapidcheck This reverts commit e60ee9e90aceb363a0d4c1c87ad8b92964b2c73a. --- flake.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index ce80fbd56..88ffcf333 100644 --- a/flake.nix +++ b/flake.nix @@ -655,7 +655,6 @@ inherit system crossSystem; overlays = [ self.overlays.default ]; }; - inherit (nixpkgsCross) lib; in with commonDeps { pkgs = nixpkgsCross; }; nixpkgsCross.stdenv.mkDerivation { name = "nix-${version}"; @@ -668,11 +667,7 @@ nativeBuildInputs = nativeBuildDeps; buildInputs = buildDeps ++ propagatedDeps; - configureFlags = [ - "CXXFLAGS=-I${lib.getDev nixpkgsCross.rapidcheck}/extras/gtest/include" - "--sysconfdir=/etc" - "--disable-doc-gen" - ]; + configureFlags = [ "--sysconfdir=/etc" "--disable-doc-gen" ]; enableParallelBuilding = true; From cdad101bc917af8d71bf5ae800ceeda09b1b1b9b Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Wed, 25 Jan 2023 18:11:36 +0100 Subject: [PATCH 4/4] Restore some non-rapidcheck tests --- src/libstore/tests/libstoretests.hh | 23 ++++++++++ src/libstore/tests/path.cc | 66 +++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 src/libstore/tests/libstoretests.hh create mode 100644 src/libstore/tests/path.cc diff --git a/src/libstore/tests/libstoretests.hh b/src/libstore/tests/libstoretests.hh new file mode 100644 index 000000000..05397659b --- /dev/null +++ b/src/libstore/tests/libstoretests.hh @@ -0,0 +1,23 @@ +#include +#include + +#include "store-api.hh" + +namespace nix { + +class LibStoreTest : public ::testing::Test { + public: + static void SetUpTestSuite() { + initLibStore(); + } + + protected: + LibStoreTest() + : store(openStore("dummy://")) + { } + + ref store; +}; + + +} /* namespace nix */ diff --git a/src/libstore/tests/path.cc b/src/libstore/tests/path.cc new file mode 100644 index 000000000..db6f31a0a --- /dev/null +++ b/src/libstore/tests/path.cc @@ -0,0 +1,66 @@ +#include + +#include +#include + +#include "path-regex.hh" +#include "store-api.hh" + +#include "libstoretests.hh" + +namespace nix { + +#define STORE_DIR "/nix/store/" +#define HASH_PART "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q" + +class StorePathTest : public LibStoreTest +{ +}; + +static std::regex nameRegex { std::string { nameRegexStr } }; + +#define TEST_DONT_PARSE(NAME, STR) \ + TEST_F(StorePathTest, bad_ ## NAME) { \ + std::string_view str = \ + STORE_DIR HASH_PART "-" STR; \ + ASSERT_THROW( \ + store->parseStorePath(str), \ + BadStorePath); \ + std::string name { STR }; \ + EXPECT_FALSE(std::regex_match(name, nameRegex)); \ + } + +TEST_DONT_PARSE(empty, "") +TEST_DONT_PARSE(garbage, "&*()") +TEST_DONT_PARSE(double_star, "**") +TEST_DONT_PARSE(star_first, "*,foo") +TEST_DONT_PARSE(star_second, "foo,*") +TEST_DONT_PARSE(bang, "foo!o") + +#undef TEST_DONT_PARSE + +#define TEST_DO_PARSE(NAME, STR) \ + TEST_F(StorePathTest, good_ ## NAME) { \ + std::string_view str = \ + STORE_DIR HASH_PART "-" STR; \ + auto p = store->parseStorePath(str); \ + std::string name { p.name() }; \ + EXPECT_TRUE(std::regex_match(name, nameRegex)); \ + } + +// 0-9 a-z A-Z + - . _ ? = + +TEST_DO_PARSE(numbers, "02345") +TEST_DO_PARSE(lower_case, "foo") +TEST_DO_PARSE(upper_case, "FOO") +TEST_DO_PARSE(plus, "foo+bar") +TEST_DO_PARSE(dash, "foo-dev") +TEST_DO_PARSE(underscore, "foo_bar") +TEST_DO_PARSE(period, "foo.txt") +TEST_DO_PARSE(question_mark, "foo?why") +TEST_DO_PARSE(equals_sign, "foo=foo") + +#undef TEST_DO_PARSE + + +}