From 97e649922542ef66c9d80cb1b41817ed07c2c5a6 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Sun, 19 Jul 2020 14:37:01 +0100 Subject: test(3p/nix): Partially enable evaluator success tests Enables the `eval-okay-` test suite, with some caveats: * The output is not yet checked against the expected value, so the tests only check that pure evaluation succeeds * A handful of tests have been disabled as they are causing failures that may be related to the DummyStore implementation. Both of these will be addressed in followup commits, but there is already some value in having the pure evaluation tests pass. Change-Id: I62236c95ebffb06dc64a45455a8ee04344c400b7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1284 Tested-by: BuildkiteCI Reviewed-by: isomer Reviewed-by: glittershark --- third_party/nix/src/tests/lang/disabled/README.txt | 7 +++++++ .../disabled/eval-okay-context-introspection.nix | 24 ++++++++++++++++++++++ .../src/tests/lang/disabled/eval-okay-context.nix | 6 ++++++ .../nix/src/tests/lang/disabled/eval-okay-path.nix | 7 +++++++ .../tests/lang/disabled/eval-okay-search-path.nix | 11 ++++++++++ .../tests/lang/disabled/eval-okay-tail-call-1.nix | 3 +++ .../tests/lang/eval-okay-context-introspection.nix | 24 ---------------------- .../nix/src/tests/lang/eval-okay-context.nix | 6 ------ third_party/nix/src/tests/lang/eval-okay-path.nix | 7 ------- .../nix/src/tests/lang/eval-okay-search-path.nix | 11 ---------- .../nix/src/tests/lang/eval-okay-tail-call-1.nix | 3 --- third_party/nix/src/tests/language-tests.cc | 21 +++++++++++++++++++ 12 files changed, 79 insertions(+), 51 deletions(-) create mode 100644 third_party/nix/src/tests/lang/disabled/README.txt create mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-context-introspection.nix create 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-path.nix create mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-search-path.nix create mode 100644 third_party/nix/src/tests/lang/disabled/eval-okay-tail-call-1.nix delete mode 100644 third_party/nix/src/tests/lang/eval-okay-context-introspection.nix delete mode 100644 third_party/nix/src/tests/lang/eval-okay-context.nix delete mode 100644 third_party/nix/src/tests/lang/eval-okay-path.nix delete mode 100644 third_party/nix/src/tests/lang/eval-okay-search-path.nix delete mode 100644 third_party/nix/src/tests/lang/eval-okay-tail-call-1.nix (limited to 'third_party/nix') diff --git a/third_party/nix/src/tests/lang/disabled/README.txt b/third_party/nix/src/tests/lang/disabled/README.txt new file mode 100644 index 000000000000..3dbcbf4f0dd9 --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/README.txt @@ -0,0 +1,7 @@ +These tests are disabeld primarily because the DummyStore used for +tests does not interact with real files on disk at the moment, but the +tests expect it to. + +Once we have a solution for this (potentially just reading & hashing +the files, but not writing them anywhere) these tests will be enabled +again. 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 new file mode 100644 index 000000000000..43178bd2eef9 --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-context-introspection.nix @@ -0,0 +1,24 @@ +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 new file mode 100644 index 000000000000..7b9531cfe9e1 --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-context.nix @@ -0,0 +1,6 @@ +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-path.nix b/third_party/nix/src/tests/lang/disabled/eval-okay-path.nix new file mode 100644 index 000000000000..e67168cf3edf --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-path.nix @@ -0,0 +1,7 @@ +builtins.path + { path = ./.; + filter = path: _: baseNameOf path == "data"; + recursive = true; + sha256 = "1yhm3gwvg5a41yylymgblsclk95fs6jy72w0wv925mmidlhcq4sw"; + name = "output"; + } diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.nix b/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.nix new file mode 100644 index 000000000000..cca41f821f83 --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-search-path.nix @@ -0,0 +1,11 @@ +with import ./lib.nix; +with builtins; + +assert pathExists ; + +assert length __nixPath == 6; +assert length (filter (x: x.prefix == "nix") __nixPath) == 1; +assert length (filter (x: baseNameOf x.path == "dir4") __nixPath) == 1; + +import + import + import + import + + (let __nixPath = [ { path = ./dir2; } { path = ./dir1; } ]; in import ) diff --git a/third_party/nix/src/tests/lang/disabled/eval-okay-tail-call-1.nix b/third_party/nix/src/tests/lang/disabled/eval-okay-tail-call-1.nix new file mode 100644 index 000000000000..a3962ce3fdb5 --- /dev/null +++ b/third_party/nix/src/tests/lang/disabled/eval-okay-tail-call-1.nix @@ -0,0 +1,3 @@ +let + f = n: if n == 100000 then n else f (n + 1); +in f 0 diff --git a/third_party/nix/src/tests/lang/eval-okay-context-introspection.nix b/third_party/nix/src/tests/lang/eval-okay-context-introspection.nix deleted file mode 100644 index 43178bd2eef9..000000000000 --- a/third_party/nix/src/tests/lang/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/eval-okay-context.nix b/third_party/nix/src/tests/lang/eval-okay-context.nix deleted file mode 100644 index 7b9531cfe9e1..000000000000 --- a/third_party/nix/src/tests/lang/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/eval-okay-path.nix b/third_party/nix/src/tests/lang/eval-okay-path.nix deleted file mode 100644 index e67168cf3edf..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-path.nix +++ /dev/null @@ -1,7 +0,0 @@ -builtins.path - { path = ./.; - filter = path: _: baseNameOf path == "data"; - recursive = true; - sha256 = "1yhm3gwvg5a41yylymgblsclk95fs6jy72w0wv925mmidlhcq4sw"; - name = "output"; - } diff --git a/third_party/nix/src/tests/lang/eval-okay-search-path.nix b/third_party/nix/src/tests/lang/eval-okay-search-path.nix deleted file mode 100644 index cca41f821f83..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-search-path.nix +++ /dev/null @@ -1,11 +0,0 @@ -with import ./lib.nix; -with builtins; - -assert pathExists ; - -assert length __nixPath == 6; -assert length (filter (x: x.prefix == "nix") __nixPath) == 1; -assert length (filter (x: baseNameOf x.path == "dir4") __nixPath) == 1; - -import + import + import + import - + (let __nixPath = [ { path = ./dir2; } { path = ./dir1; } ]; in import ) diff --git a/third_party/nix/src/tests/lang/eval-okay-tail-call-1.nix b/third_party/nix/src/tests/lang/eval-okay-tail-call-1.nix deleted file mode 100644 index a3962ce3fdb5..000000000000 --- a/third_party/nix/src/tests/lang/eval-okay-tail-call-1.nix +++ /dev/null @@ -1,3 +0,0 @@ -let - f = n: if n == 100000 then n else f (n + 1); -in f 0 diff --git a/third_party/nix/src/tests/language-tests.cc b/third_party/nix/src/tests/language-tests.cc index 7e53cd8f5eaa..daa2fa233e19 100644 --- a/third_party/nix/src/tests/language-tests.cc +++ b/third_party/nix/src/tests/language-tests.cc @@ -187,4 +187,25 @@ INSTANTIATE_TEST_SUITE_P(Eval, EvalFailureTest, testing::ValuesIn(TestFilesFor("eval-fail-")), TestNameFor); +class EvalSuccessTest : public testing::TestWithParam {}; + +// Test pattern for files that should fail to evaluate. +TEST_P(EvalSuccessTest, Fails) { + std::shared_ptr store = std::make_shared(); + EvalState state({}, ref(store)); + auto path = GetParam(); + + Expr* expr; + EXPECT_NO_THROW(expr = state.parseExprFromFile(GetParam().string())) + << path.stem().string() << ": should parse successfully"; + + Value result; + state.eval(expr, result); + state.forceValue(result); +} + +INSTANTIATE_TEST_SUITE_P(Eval, EvalSuccessTest, + testing::ValuesIn(TestFilesFor("eval-okay-")), + TestNameFor); + } // namespace nix::tests -- cgit 1.4.1