tests: test arguments passed to use_nix

This commit is contained in:
Jörg Thalheim 2022-06-01 08:45:23 +02:00
parent 0530ef449f
commit d74ad21a58
No known key found for this signature in database
2 changed files with 45 additions and 1 deletions

37
tests/test_use_nix.py Normal file
View file

@ -0,0 +1,37 @@
#!/usr/bin/env python2
import sys
import subprocess
import unittest
from procs import run
from direnv_project import DirenvProject
def direnv_exec(direnv_project: DirenvProject, cmd: str) -> None:
out = run(
["direnv", "exec", str(direnv_project.dir), "sh", "-c", cmd],
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
check=False,
cwd=direnv_project.dir,
)
sys.stdout.write(out.stdout)
sys.stderr.write(out.stderr)
assert out.returncode == 0
assert "OK\n" == out.stdout
assert "renewed cache" in out.stderr
def test_attrs(direnv_project: DirenvProject) -> None:
direnv_project.setup_envrc("use nix -A subshell")
direnv_exec(direnv_project, "echo $THIS_IS_A_SUBSHELL")
def test_args(direnv_project: DirenvProject) -> None:
direnv_project.setup_envrc("use nix --argstr someArg OK")
direnv_exec(direnv_project, "echo $SHOULD_BE_SET")
if __name__ == "__main__":
unittest.main()

View file

@ -1,7 +1,14 @@
{ pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> {}, someArg ? null }:
pkgs.mkShellNoCC {
nativeBuildInputs = [ pkgs.hello ];
shellHook = ''
echo "Executing shellHook."
'';
SHOULD_BE_SET = someArg;
passthru = {
subshell = pkgs.mkShellNoCC {
THIS_IS_A_SUBSHELL = "OK";
};
};
}