mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 11:36:11 +01:00
Merge pull request #332 from amarshall/strict-env-test
Run tests with and without direnv’s strict_env
This commit is contained in:
commit
e44ff86b6b
7 changed files with 26 additions and 27 deletions
|
|
@ -7,6 +7,7 @@ mkShell {
|
|||
python3.pkgs.mypy
|
||||
python3.pkgs.black
|
||||
python3.pkgs.flake8
|
||||
ruff
|
||||
shellcheck
|
||||
direnv
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
pytest_plugins = [
|
||||
"direnv_project",
|
||||
"root",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import shutil
|
||||
import textwrap
|
||||
from dataclasses import dataclass
|
||||
|
|
@ -20,9 +18,10 @@ class DirenvProject:
|
|||
def envrc(self) -> Path:
|
||||
return self.dir / ".envrc"
|
||||
|
||||
def setup_envrc(self, content: str) -> None:
|
||||
def setup_envrc(self, content: str, strict_env: bool) -> None:
|
||||
text = textwrap.dedent(
|
||||
f"""
|
||||
{'strict_env' if strict_env else ''}
|
||||
source {self.nix_direnv}
|
||||
{content}
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from typing import IO, Any, List, Optional, Union
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import pytest
|
||||
from direnv_project import DirenvProject
|
||||
from procs import run
|
||||
|
||||
|
|
@ -60,18 +59,21 @@ def common_test_clean(direnv_project: DirenvProject) -> None:
|
|||
assert len(profiles) == 1
|
||||
|
||||
|
||||
def test_use_nix(direnv_project: DirenvProject) -> None:
|
||||
direnv_project.setup_envrc("use nix")
|
||||
@pytest.mark.parametrize("strict_env", [False, True])
|
||||
def test_use_nix(direnv_project: DirenvProject, strict_env: bool) -> None:
|
||||
direnv_project.setup_envrc("use nix", strict_env=strict_env)
|
||||
common_test(direnv_project)
|
||||
|
||||
direnv_project.setup_envrc(
|
||||
"use nix --argstr shellHook 'echo Executing hijacked shellHook.'"
|
||||
"use nix --argstr shellHook 'echo Executing hijacked shellHook.'",
|
||||
strict_env=strict_env,
|
||||
)
|
||||
common_test_clean(direnv_project)
|
||||
|
||||
|
||||
def test_use_flake(direnv_project: DirenvProject) -> None:
|
||||
direnv_project.setup_envrc("use flake")
|
||||
@pytest.mark.parametrize("strict_env", [False, True])
|
||||
def test_use_flake(direnv_project: DirenvProject, strict_env: bool) -> None:
|
||||
direnv_project.setup_envrc("use flake", strict_env=strict_env)
|
||||
common_test(direnv_project)
|
||||
inputs = list((direnv_project.dir / ".direnv/flake-inputs").iterdir())
|
||||
# should only contain our flake-utils flake
|
||||
|
|
@ -82,7 +84,7 @@ def test_use_flake(direnv_project: DirenvProject) -> None:
|
|||
for symlink in inputs:
|
||||
assert symlink.is_dir()
|
||||
|
||||
direnv_project.setup_envrc("use flake --impure")
|
||||
direnv_project.setup_envrc("use flake --impure", strict_env=strict_env)
|
||||
common_test_clean(direnv_project)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,10 @@
|
|||
#!/usr/bin/env python2
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
from typing import Optional
|
||||
|
||||
import pytest
|
||||
from direnv_project import DirenvProject
|
||||
from procs import run
|
||||
|
||||
|
|
@ -30,25 +29,29 @@ def direnv_exec(
|
|||
assert "renewed cache" in out.stderr
|
||||
|
||||
|
||||
def test_attrs(direnv_project: DirenvProject) -> None:
|
||||
direnv_project.setup_envrc("use nix -A subshell")
|
||||
@pytest.mark.parametrize("strict_env", [False, True])
|
||||
def test_attrs(direnv_project: DirenvProject, strict_env: bool) -> None:
|
||||
direnv_project.setup_envrc("use nix -A subshell", strict_env=strict_env)
|
||||
direnv_exec(direnv_project, "echo $THIS_IS_A_SUBSHELL")
|
||||
|
||||
|
||||
def test_no_nix_path(direnv_project: DirenvProject) -> None:
|
||||
direnv_project.setup_envrc("use nix --argstr someArg OK")
|
||||
@pytest.mark.parametrize("strict_env", [False, True])
|
||||
def test_no_nix_path(direnv_project: DirenvProject, strict_env: bool) -> None:
|
||||
direnv_project.setup_envrc("use nix --argstr someArg OK", strict_env=strict_env)
|
||||
env = os.environ.copy()
|
||||
del env["NIX_PATH"]
|
||||
direnv_exec(direnv_project, "echo $SHOULD_BE_SET", env=env)
|
||||
|
||||
|
||||
def test_args(direnv_project: DirenvProject) -> None:
|
||||
direnv_project.setup_envrc("use nix --argstr someArg OK")
|
||||
@pytest.mark.parametrize("strict_env", [False, True])
|
||||
def test_args(direnv_project: DirenvProject, strict_env: bool) -> None:
|
||||
direnv_project.setup_envrc("use nix --argstr someArg OK", strict_env=strict_env)
|
||||
direnv_exec(direnv_project, "echo $SHOULD_BE_SET")
|
||||
|
||||
|
||||
def test_no_files(direnv_project: DirenvProject) -> None:
|
||||
direnv_project.setup_envrc("use nix -p hello")
|
||||
@pytest.mark.parametrize("strict_env", [False, True])
|
||||
def test_no_files(direnv_project: DirenvProject, strict_env: bool) -> None:
|
||||
direnv_project.setup_envrc("use nix -p hello", strict_env=strict_env)
|
||||
out = run(
|
||||
["direnv", "status"],
|
||||
stderr=subprocess.PIPE,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue