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