Merge pull request #194 from nix-community/pytest

fix arguments not passed in use_nix + regression tests
This commit is contained in:
Jörg Thalheim 2022-06-01 07:53:42 +01:00 committed by GitHub
commit d0fb72b2e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View file

@ -313,7 +313,6 @@ use_nix() {
then then
local tmp_profile="${layout_dir}/flake-profile.$$" local tmp_profile="${layout_dir}/flake-profile.$$"
local tmp_profile_rc local tmp_profile_rc
local extra_args=()
if [[ "$packages" != "" ]]; then if [[ "$packages" != "" ]]; then
extra_args+=("--expr" "with import <nixpkgs> {}; mkShell { buildInputs = [ $packages ]; }") extra_args+=("--expr" "with import <nixpkgs> {}; mkShell { buildInputs = [ $packages ]; }")

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 { pkgs.mkShellNoCC {
nativeBuildInputs = [ pkgs.hello ]; nativeBuildInputs = [ pkgs.hello ];
shellHook = '' shellHook = ''
echo "Executing shellHook." echo "Executing shellHook."
''; '';
SHOULD_BE_SET = someArg;
passthru = {
subshell = pkgs.mkShellNoCC {
THIS_IS_A_SUBSHELL = "OK";
};
};
} }