aboutsummaryrefslogtreecommitdiff
path: root/tests/unit/libexpr/expr-print.cc
blob: aa25d00df98fa452b29f5c7564da84b6cebbd134 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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)");
}

}