From b76cd7253a1d0e6ce2260071c375eae7a8141468 Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 14 Aug 2020 19:04:30 -0700 Subject: feat(tvix): Re-enable language tests that needed a store Now that we have access to a store in tests, we can enable the tests that needed a store. Additionally, move the expected output files for disabled tests into the disabled folder. Change-Id: I2492d49d43b93c7c9b0463e4d3d2855a5a51365d Reviewed-on: https://cl.tvl.fyi/c/depot/+/1758 Tested-by: BuildkiteCI Reviewed-by: glittershark --- .../src/tests/lang/disabled/eval-okay-autoargs.exp | 1 - .../src/tests/lang/disabled/eval-okay-autoargs.nix | 15 ------- .../disabled/eval-okay-context-introspection.nix | 24 ---------- .../src/tests/lang/disabled/eval-okay-context.nix | 6 --- .../tests/lang/disabled/eval-okay-search-path.exp | 1 + .../lang/disabled/eval-okay-search-path.flags | 1 + .../src/tests/lang/disabled/eval-okay-toxml.nix | 3 -- .../nix/src/tests/lang/disabled/eval-okay-xml.exp | 52 ++++++++++++++++++++++ .../tests/lang/eval-okay-context-introspection.exp | 1 - .../nix/src/tests/lang/eval-okay-context.exp | 1 - .../nix/src/tests/lang/eval-okay-search-path.exp | 1 - .../nix/src/tests/lang/eval-okay-search-path.flags | 1 - third_party/nix/src/tests/lang/eval-okay-toxml.exp | 1 - third_party/nix/src/tests/lang/eval-okay-xml.exp | 52 ---------------------- .../nix/src/tests/lang/evalargs-okay-autoargs.nix | 15 +++++++ .../nix/src/tests/lang/evalstore-okay-autoargs.exp | 1 + .../lang/evalstore-okay-context-introspection.exp | 1 + .../lang/evalstore-okay-context-introspection.nix | 24 ++++++++++ .../nix/src/tests/lang/evalstore-okay-context.exp | 1 + .../nix/src/tests/lang/evalstore-okay-context.nix | 6 +++ .../nix/src/tests/lang/evalstore-okay-toxml.exp | 1 + .../nix/src/tests/lang/evalstore-okay-toxml.nix | 3 ++ third_party/nix/src/tests/language-tests.cc | 52 +++++++++++++++++++++- 23 files changed, 157 insertions(+), 107 deletions(-) delete mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.exp delete mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.nix delete mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-context-introspection.nix delete mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-context.nix create mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-search-path.exp create mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-search-path.flags delete mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-toxml.nix create mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-xml.exp delete mode 100644 third_party/nix/src/tests/lang/eval-okay-context-introspection.exp delete mode 100644 third_party/nix/src/tests/lang/eval-okay-context.exp delete mode 100644 third_party/nix/src/tests/lang/eval-okay-search-path.exp delete mode 100644 third_party/nix/src/tests/lang/eval-okay-search-path.flags delete mode 100644 third_party/nix/src/tests/lang/eval-okay-toxml.exp delete mode 100644 third_party/nix/src/tests/lang/eval-okay-xml.exp create mode 100644 third_party/nix/src/tests/lang/evalargs-okay-autoargs.nix create mode 100644 third_party/nix/src/tests/lang/evalstore-okay-autoargs.exp create mode 100644 third_party/nix/src/tests/lang/evalstore-okay-context-introspection.exp create mode 100644 third_party/nix/src/tests/lang/evalstore-okay-context-introspection.nix create mode 100644 third_party/nix/src/tests/lang/evalstore-okay-context.exp create mode 100644 third_party/nix/src/tests/lang/evalstore-okay-context.nix create mode 100644 third_party/nix/src/tests/lang/evalstore-okay-toxml.exp create mode 100644 third_party/nix/src/tests/lang/evalstore-okay-toxml.nix (limited to 'third_party') diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.exp b/third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.exp deleted file mode 100644 index 7a8391786a09..000000000000 --- a/third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.exp +++ /dev/null @@ -1 +0,0 @@ -"xyzzy!xyzzy!foobar" diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.nix b/third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.nix deleted file mode 100644 index 815f51b1d67a..000000000000 --- a/third_party/nix/src/tests/lang/disabled/eval-okay-autoargs.nix +++ /dev/null @@ -1,15 +0,0 @@ -let - - foobar = "foobar"; - -in - -{ xyzzy2 ? xyzzy # mutually recursive args -, xyzzy ? "blaat" # will be overridden by --argstr -, fb ? foobar -, lib # will be set by --arg -}: - -{ - result = lib.concat [xyzzy xyzzy2 fb]; -} diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-context-introspection.nix b/third_party/nix/src/tests/lang/disabled/eval-okay-context-introspection.nix deleted file mode 100644 index 43178bd2eef9..000000000000 --- a/third_party/nix/src/tests/lang/disabled/eval-okay-context-introspection.nix +++ /dev/null @@ -1,24 +0,0 @@ -let - drv = derivation { - name = "fail"; - builder = "/bin/false"; - system = "x86_64-linux"; - outputs = [ "out" "foo" ]; - }; - - path = "${./eval-okay-context-introspection.nix}"; - - desired-context = { - "${builtins.unsafeDiscardStringContext path}" = { - path = true; - }; - "${builtins.unsafeDiscardStringContext drv.drvPath}" = { - outputs = [ "foo" "out" ]; - allOutputs = true; - }; - }; - - legit-context = builtins.getContext "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}"; - - constructed-context = builtins.getContext (builtins.appendContext "" desired-context); -in legit-context == constructed-context diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-context.nix b/third_party/nix/src/tests/lang/disabled/eval-okay-context.nix deleted file mode 100644 index 7b9531cfe9e1..000000000000 --- a/third_party/nix/src/tests/lang/disabled/eval-okay-context.nix +++ /dev/null @@ -1,6 +0,0 @@ -let s = "foo ${builtins.substring 33 100 (baseNameOf "${./eval-okay-context.nix}")} bar"; -in - if s != "foo eval-okay-context.nix bar" - then abort "context not discarded" - else builtins.unsafeDiscardStringContext s - diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.exp b/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.exp new file mode 100644 index 000000000000..4519bc406db5 --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.exp @@ -0,0 +1 @@ +"abccX" diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.flags b/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.flags new file mode 100644 index 000000000000..a28e6821004a --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.flags @@ -0,0 +1 @@ +-I lang/dir1 -I lang/dir2 -I dir5=lang/dir3 \ No newline at end of file diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-toxml.nix b/third_party/nix/src/tests/lang/disabled/eval-okay-toxml.nix deleted file mode 100644 index 068c97a6c1b3..000000000000 --- a/third_party/nix/src/tests/lang/disabled/eval-okay-toxml.nix +++ /dev/null @@ -1,3 +0,0 @@ -# Make sure the expected XML output is produced; in particular, make sure it -# doesn't contain source location information. -builtins.toXML { a = "s"; } diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-xml.exp b/third_party/nix/src/tests/lang/disabled/eval-okay-xml.exp new file mode 100644 index 000000000000..92b75e0b8b17 --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-xml.exp @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/third_party/nix/src/tests/lang/eval-okay-context-introspection.exp b/third_party/nix/src/tests/lang/eval-okay-context-introspection.exp deleted file mode 100644 index 27ba77ddaf61..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-context-introspection.exp +++ /dev/null @@ -1 +0,0 @@ -true diff --git a/third_party/nix/src/tests/lang/eval-okay-context.exp b/third_party/nix/src/tests/lang/eval-okay-context.exp deleted file mode 100644 index 2f535bdbc454..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-context.exp +++ /dev/null @@ -1 +0,0 @@ -"foo eval-okay-context.nix bar" diff --git a/third_party/nix/src/tests/lang/eval-okay-search-path.exp b/third_party/nix/src/tests/lang/eval-okay-search-path.exp deleted file mode 100644 index 4519bc406db5..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-search-path.exp +++ /dev/null @@ -1 +0,0 @@ -"abccX" diff --git a/third_party/nix/src/tests/lang/eval-okay-search-path.flags b/third_party/nix/src/tests/lang/eval-okay-search-path.flags deleted file mode 100644 index a28e6821004a..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-search-path.flags +++ /dev/null @@ -1 +0,0 @@ --I lang/dir1 -I lang/dir2 -I dir5=lang/dir3 \ No newline at end of file diff --git a/third_party/nix/src/tests/lang/eval-okay-toxml.exp b/third_party/nix/src/tests/lang/eval-okay-toxml.exp deleted file mode 100644 index 828220890ecd..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-toxml.exp +++ /dev/null @@ -1 +0,0 @@ -"\n\n \n \n \n \n \n\n" diff --git a/third_party/nix/src/tests/lang/eval-okay-xml.exp b/third_party/nix/src/tests/lang/eval-okay-xml.exp deleted file mode 100644 index 92b75e0b8b17..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-xml.exp +++ /dev/null @@ -1,52 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/third_party/nix/src/tests/lang/evalargs-okay-autoargs.nix b/third_party/nix/src/tests/lang/evalargs-okay-autoargs.nix new file mode 100644 index 000000000000..815f51b1d67a --- /dev/null +++ b/third_party/nix/src/tests/lang/evalargs-okay-autoargs.nix @@ -0,0 +1,15 @@ +let + + foobar = "foobar"; + +in + +{ xyzzy2 ? xyzzy # mutually recursive args +, xyzzy ? "blaat" # will be overridden by --argstr +, fb ? foobar +, lib # will be set by --arg +}: + +{ + result = lib.concat [xyzzy xyzzy2 fb]; +} diff --git a/third_party/nix/src/tests/lang/evalstore-okay-autoargs.exp b/third_party/nix/src/tests/lang/evalstore-okay-autoargs.exp new file mode 100644 index 000000000000..7a8391786a09 --- /dev/null +++ b/third_party/nix/src/tests/lang/evalstore-okay-autoargs.exp @@ -0,0 +1 @@ +"xyzzy!xyzzy!foobar" diff --git a/third_party/nix/src/tests/lang/evalstore-okay-context-introspection.exp b/third_party/nix/src/tests/lang/evalstore-okay-context-introspection.exp new file mode 100644 index 000000000000..27ba77ddaf61 --- /dev/null +++ b/third_party/nix/src/tests/lang/evalstore-okay-context-introspection.exp @@ -0,0 +1 @@ +true diff --git a/third_party/nix/src/tests/lang/evalstore-okay-context-introspection.nix b/third_party/nix/src/tests/lang/evalstore-okay-context-introspection.nix new file mode 100644 index 000000000000..d11aad38c726 --- /dev/null +++ b/third_party/nix/src/tests/lang/evalstore-okay-context-introspection.nix @@ -0,0 +1,24 @@ +let + drv = derivation { + name = "fail"; + builder = "/bin/false"; + system = "x86_64-linux"; + outputs = [ "out" "foo" ]; + }; + + path = "${./evalstore-okay-context-introspection.nix}"; + + desired-context = { + "${builtins.unsafeDiscardStringContext path}" = { + path = true; + }; + "${builtins.unsafeDiscardStringContext drv.drvPath}" = { + outputs = [ "foo" "out" ]; + allOutputs = true; + }; + }; + + legit-context = builtins.getContext "${path}${drv.outPath}${drv.foo.outPath}${drv.drvPath}"; + + constructed-context = builtins.getContext (builtins.appendContext "" desired-context); +in legit-context == constructed-context diff --git a/third_party/nix/src/tests/lang/evalstore-okay-context.exp b/third_party/nix/src/tests/lang/evalstore-okay-context.exp new file mode 100644 index 000000000000..f8088f9e172a --- /dev/null +++ b/third_party/nix/src/tests/lang/evalstore-okay-context.exp @@ -0,0 +1 @@ +"foo evalstore-okay-context.nix bar" diff --git a/third_party/nix/src/tests/lang/evalstore-okay-context.nix b/third_party/nix/src/tests/lang/evalstore-okay-context.nix new file mode 100644 index 000000000000..90f82abe1c36 --- /dev/null +++ b/third_party/nix/src/tests/lang/evalstore-okay-context.nix @@ -0,0 +1,6 @@ +let s = "foo ${builtins.substring 33 100 (baseNameOf "${./evalstore-okay-context.nix}")} bar"; +in + if s != "foo evalstore-okay-context.nix bar" + then abort "context not discarded" + else builtins.unsafeDiscardStringContext s + diff --git a/third_party/nix/src/tests/lang/evalstore-okay-toxml.exp b/third_party/nix/src/tests/lang/evalstore-okay-toxml.exp new file mode 100644 index 000000000000..828220890ecd --- /dev/null +++ b/third_party/nix/src/tests/lang/evalstore-okay-toxml.exp @@ -0,0 +1 @@ +"\n\n \n \n \n \n \n\n" diff --git a/third_party/nix/src/tests/lang/evalstore-okay-toxml.nix b/third_party/nix/src/tests/lang/evalstore-okay-toxml.nix new file mode 100644 index 000000000000..068c97a6c1b3 --- /dev/null +++ b/third_party/nix/src/tests/lang/evalstore-okay-toxml.nix @@ -0,0 +1,3 @@ +# Make sure the expected XML output is produced; in particular, make sure it +# doesn't contain source location information. +builtins.toXML { a = "s"; } diff --git a/third_party/nix/src/tests/language-tests.cc b/third_party/nix/src/tests/language-tests.cc index 5b0e808d1921..189e1ede5c37 100644 --- a/third_party/nix/src/tests/language-tests.cc +++ b/third_party/nix/src/tests/language-tests.cc @@ -46,6 +46,7 @@ #include "libexpr/nixexpr.hh" #include "nix_config.h" #include "tests/dummy-store.hh" +#include "tests/store-util.hh" namespace nix::tests { namespace { @@ -208,7 +209,7 @@ INSTANTIATE_TEST_SUITE_P(Eval, EvalFailureTest, class EvalSuccessTest : public testing::TestWithParam {}; // Test pattern for files that should evaluate successfully. -TEST_P(EvalSuccessTest, Fails) { +TEST_P(EvalSuccessTest, Succeeds) { std::shared_ptr store = std::make_shared(); EvalState state({}, ref(store)); auto path = GetParam(); @@ -236,4 +237,53 @@ INSTANTIATE_TEST_SUITE_P(Eval, EvalSuccessTest, testing::ValuesIn(TestFilesFor("eval-okay-")), TestNameFor); +class BlankStoreTest : public nix::StoreTest { + virtual void TestBody() override{}; +}; + +class EvalStoreSuccessTest + : public testing::TestWithParam { + public: + virtual void TearDown() { store_test_.TearDown(); } + + absl::StatusOr> OpenTemporaryStore() { + return store_test_.OpenTemporaryStore(); + } + + private: + BlankStoreTest store_test_; +}; + +// Test pattern for files that should evaluate successfully but require a real +// store. +TEST_P(EvalStoreSuccessTest, Succeeds) { + std::unique_ptr store_ = + OpenTemporaryStore().ConsumeValueOrDie(); + ref store = ref(store_.release()); + EvalState state({}, store); + auto path = GetParam(); + + Expr* expr = nullptr; + ASSERT_NO_THROW(expr = state.parseExprFromFile(GetParam().string())) + << path.stem().string() << ": should parse successfully"; + + Value result; + + ASSERT_NO_THROW({ + state.eval(expr, result); + state.forceValueDeep(result); + }) << path.stem().string() + << ": should evaluate successfully"; + + auto expected = ExpectedOutputFor(path.stem().string()); + std::ostringstream value_str; + value_str << result; + + EXPECT_EQ(expected, value_str.str()) << "evaluator output should match"; +} + +INSTANTIATE_TEST_SUITE_P(Eval, EvalStoreSuccessTest, + testing::ValuesIn(TestFilesFor("evalstore-okay-")), + TestNameFor); + } // namespace nix::tests -- cgit 1.4.1