mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
tests: test arguments passed to use_nix
This commit is contained in:
parent
0530ef449f
commit
d74ad21a58
2 changed files with 45 additions and 1 deletions
37
tests/test_use_nix.py
Normal file
37
tests/test_use_nix.py
Normal 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()
|
||||
|
|
@ -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";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue