about summary refs log tree commit diff
path: root/third_party/nix/src/tests/language-tests.cc
diff options
context:
space:
mode:
authorKane York <kanepyork@gmail.com>2020-08-15T02·04-0700
committerkanepyork <rikingcoding@gmail.com>2020-08-18T03·58+0000
commitb76cd7253a1d0e6ce2260071c375eae7a8141468 (patch)
tree51da97b5f2dd18dd3f2378487afd6734f8843e1a /third_party/nix/src/tests/language-tests.cc
parentfea4df560bdb9a14c3ea6d45aaad26a6a24d6ce5 (diff)
feat(tvix): Re-enable language tests that needed a store r/1673
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 <grfn@gws.fyi>
Diffstat (limited to 'third_party/nix/src/tests/language-tests.cc')
-rw-r--r--third_party/nix/src/tests/language-tests.cc52
1 files changed, 51 insertions, 1 deletions
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<std::filesystem::path> {};
 
 // Test pattern for files that should evaluate successfully.
-TEST_P(EvalSuccessTest, Fails) {
+TEST_P(EvalSuccessTest, Succeeds) {
   std::shared_ptr<Store> store = std::make_shared<DummyStore>();
   EvalState state({}, ref<Store>(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<std::filesystem::path> {
+ public:
+  virtual void TearDown() { store_test_.TearDown(); }
+
+  absl::StatusOr<std::unique_ptr<nix::LocalStore>> 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<nix::LocalStore> store_ =
+      OpenTemporaryStore().ConsumeValueOrDie();
+  ref<Store> store = ref<Store>(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