diff options
author | Qyriad <qyriad@qyriad.me> | 2024-06-24 14:33:12 -0600 |
---|---|---|
committer | Qyriad <qyriad@qyriad.me> | 2024-07-04 15:55:38 -0600 |
commit | 59bf6825ef34dd8951302fb033837c2658b2367d (patch) | |
tree | 7919c48ddcf77567eac8a2b1fe488cea18b22132 /tests | |
parent | 4f0c27abe159c69db15f968607bc26de5ba1034f (diff) |
add an impl of Expr::show for ExprInheritFrom that doesn't crash
ExprVar::show() assumes it has a name. dynamic inherits do not
necessarily (ever?) have a name.
Change-Id: If10893188e307431da17f0c1bd0787adc74f7141
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/libexpr/expr-print.cc | 34 | ||||
-rw-r--r-- | tests/unit/meson.build | 1 |
2 files changed, 35 insertions, 0 deletions
diff --git a/tests/unit/libexpr/expr-print.cc b/tests/unit/libexpr/expr-print.cc new file mode 100644 index 000000000..aa25d00df --- /dev/null +++ b/tests/unit/libexpr/expr-print.cc @@ -0,0 +1,34 @@ +#include <sstream> +#include <string_view> + +#include <gtest/gtest.h> + +#include "tests/libexpr.hh" + +#include "nixexpr.hh" +#include "ref.hh" + +namespace nix +{ + +using namespace testing; +struct ExprPrintingTests : LibExprTest +{ + void test(Expr const & expr, std::string_view expected) + { + std::stringstream out; + expr.show(state.symbols, out); + ASSERT_EQ(out.str(), expected); + } +}; + +TEST_F(ExprPrintingTests, ExprInheritFrom) +{ + // ExprInheritFrom has its own show() impl. + // If it uses its parent class's impl it will crash. + auto inheritSource = make_ref<ExprVar>(state.symbols.create("stdenv")); + ExprInheritFrom const eInheritFrom(noPos, 0, inheritSource); + test(eInheritFrom, "(/* expanded inherit (expr) */ stdenv)"); +} + +} diff --git a/tests/unit/meson.build b/tests/unit/meson.build index 17d089f18..a6719a060 100644 --- a/tests/unit/meson.build +++ b/tests/unit/meson.build @@ -186,6 +186,7 @@ libexpr_tests_sources = files( 'libexpr/primops.cc', 'libexpr/search-path.cc', 'libexpr/trivial.cc', + 'libexpr/expr-print.cc', 'libexpr/value/context.cc', 'libexpr/value/print.cc', ) |