Files
lix/tests/functional2/flakes/test_trivial.py
T
piegames 481fc30ae7 libexpr/flakes: Replace the AST checks with maxCallDepth = 0
Change-Id: I7130cc941b4b7432df76a3995d298edfb28e6a01
2026-05-06 17:22:19 +02:00

90 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from testlib.fixtures.nix import Nix
from testlib.fixtures.file_helper import with_files, File
from pathlib import Path
import pytest
@pytest.fixture(autouse=True)
def common_init(nix: Nix):
nix.settings.add_xp_feature("nix-command", "flakes")
# Trivial let bindings should work within a flake
@with_files(
{
"flake.nix": File("""
let
description = "meow";
in {
inherit description;
inputs = { };
outputs = { self }: { };
}
""")
}
)
def test_trivial_let(nix: Nix, files: Path):
assert nix.nix(["flake", "show", "--json", files]).run().ok().json() == {}
# Interpolation is not a function call and thus allowed (it desugars to string concatenation)
@with_files(
{
"dependency": {"flake.nix": File("{ outputs = _: {}; }")},
"flake.nix": File("""
let
src = "path:.";
in {
inputs = {
lix.url = "${src}/dependency";
};
outputs = { self, lix }: {
};
}
"""),
}
)
def test_trivial_interpolation(nix: Nix, files: Path):
assert nix.nix(["flake", "show", "--json", files]).run().ok().json() == {}
# `-1` desugars to `__sub 0 1` and thus is stupidly forbidden.
# Once we have finalized the deprecation of shadowing of internal symbols, we will be able to change subtraction and division
# to use proper AST nodes. Like they should have in the first place.
@with_files(
{
"flake.nix": File("""
{
inputs = -1;
outputs = { self, lix }: { };
}
""")
}
)
def test_trivial_implicit_function(nix: Nix, files: Path):
assert (
"error: stack overflow"
in nix.nix(["flake", "show", "--json", files]).run().expect(1).stderr_plain
)
@with_files(
{
"flake.nix": File("""
{
inputs = builtins.seq true { };
outputs = { self, lix }: { };
}
""")
}
)
def test_trivial_explicit_function(nix: Nix, files: Path):
assert (
"error: stack overflow"
in nix.nix(["flake", "show", "--json", files]).run().expect(1).stderr_plain
)