aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/libexpr')
-rw-r--r--tests/unit/libexpr/expr-print.cc34
1 files changed, 34 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)");
+}
+
+}