mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
Merge pull request #194 from nix-community/pytest
fix arguments not passed in use_nix + regression tests
This commit is contained in:
commit
d0fb72b2e5
3 changed files with 45 additions and 2 deletions
1
direnvrc
1
direnvrc
|
|
@ -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
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 {
|
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";
|
||||||
|
};
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue