summaryrefslogtreecommitdiffstats
path: root/tests/file_input/test_file_input.py
blob: 43bdae371963c40233ea6c5fad69fe2f7a59963d (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from pathlib import Path

from tests.testlib import (
    copy_fixture,
    flake_compat_arg,
    nix,
    nix_eval_flake_attr,
    nix_eval_flake_compat,
)


# May fail randomly on older Lixes and CppNixes due to: https://git.lix.systems/lix-project/lix/issues/750
def test_file_input(tmpdir: Path):
    copy_fixture("file_input", tmpdir)
    compat = nix_eval_flake_compat(tmpdir, "lix-manifest")
    native = nix_eval_flake_attr(tmpdir, "lix-manifest")

    assert native == compat


# Check that the file input is not a derivation, in spite of our use of
# derivations internally.
def test_file_input_not_derivation(tmpdir: Path):
    copy_fixture("file_input", tmpdir)
    compat = nix_eval_flake_compat(tmpdir, "dependent")
    native = nix_eval_flake_attr(tmpdir, "dependent")

    assert native == compat


def test_native_fetchTree(tmpdir: Path):
    copy_fixture("file_input", tmpdir)

    # Make builtins.fetchTree print something visible when it is actually used.
    def do_eval(*args):
        res = nix(
            "eval",
            "--json",
            *flake_compat_arg,
            *args,
            "--impure",
            "--expr",
            """
            let
              scope = {
                builtins = builtins // {
                  fetchTree = x: builtins.trace "meow kitty" (builtins.fetchTree x);
                };
                import = builtins.scopedImport scope;
              };
            in builtins.scopedImport scope ./default.nix
            """,
            "lix-manifest",
            work_dir=tmpdir,
            capture_stderr=True,
        )

        res.ok()
        return res

    res = do_eval()
    assert b"meow kitty" not in res.proc.stderr

    res = do_eval("--arg", "useBuiltinsFetchTree", "true")
    assert b"meow kitty" in res.proc.stderr