diff options
Diffstat (limited to 'third_party/nix/src/tests/language-tests.cc')
-rw-r--r-- | third_party/nix/src/tests/language-tests.cc | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/third_party/nix/src/tests/language-tests.cc b/third_party/nix/src/tests/language-tests.cc index daa2fa233e19..cac5aee5841c 100644 --- a/third_party/nix/src/tests/language-tests.cc +++ b/third_party/nix/src/tests/language-tests.cc @@ -23,9 +23,12 @@ #include <algorithm> #include <filesystem> +#include <fstream> #include <iostream> +#include <iterator> #include <memory> #include <optional> +#include <sstream> #include <string> #include <absl/strings/ascii.h> @@ -86,6 +89,20 @@ std::string TestNameFor( return name; } +// Load the expected output of a given test as a string. +std::string ExpectedOutputFor(absl::string_view stem) { + std::filesystem::path path( + absl::StrCat(NIX_SRC_DIR, "/src/tests/lang/", stem, ".exp")); + + EXPECT_TRUE(std::filesystem::exists(path)) + << stem << ": expected output file should exist"; + + std::ifstream input(path); + std::stringstream buffer; + buffer << input.rdbuf(); + return std::string(absl::StripTrailingAsciiWhitespace(buffer.str())); +} + } // namespace using nix::tests::DummyStore; @@ -189,7 +206,7 @@ INSTANTIATE_TEST_SUITE_P(Eval, EvalFailureTest, class EvalSuccessTest : public testing::TestWithParam<std::filesystem::path> {}; -// Test pattern for files that should fail to evaluate. +// Test pattern for files that should evaluate successfully. TEST_P(EvalSuccessTest, Fails) { std::shared_ptr<Store> store = std::make_shared<DummyStore>(); EvalState state({}, ref<Store>(store)); @@ -200,8 +217,18 @@ TEST_P(EvalSuccessTest, Fails) { << path.stem().string() << ": should parse successfully"; Value result; - state.eval(expr, result); - state.forceValue(result); + + EXPECT_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, EvalSuccessTest, |