mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 11:36:11 +01:00
improve tests
This commit is contained in:
parent
c73420268c
commit
9b5b553521
1 changed files with 31 additions and 4 deletions
|
|
@ -2,15 +2,22 @@
|
|||
|
||||
from tempfile import TemporaryDirectory
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import unittest
|
||||
from typing import List
|
||||
|
||||
|
||||
TEST_ROOT = Path(__file__).resolve().parent
|
||||
|
||||
|
||||
def run(cmd: List[str], **kwargs) -> subprocess.CompletedProcess:
|
||||
print("$ " + " ".join(cmd))
|
||||
return subprocess.run(cmd, **kwargs)
|
||||
|
||||
|
||||
class IntegrationTest(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
self.env = os.environ.copy()
|
||||
|
|
@ -24,12 +31,32 @@ class IntegrationTest(unittest.TestCase):
|
|||
f.write(f"use nix")
|
||||
|
||||
def test_direnv(self) -> None:
|
||||
subprocess.run(
|
||||
["direnv", "allow"], cwd=str(self.testenv), env=self.env, check=True
|
||||
run(["direnv", "allow"], cwd=str(self.testenv), env=self.env, check=True)
|
||||
|
||||
run(["nix-collect-garbage"], check=True)
|
||||
|
||||
out1 = run(
|
||||
["direnv", "exec", str(self.testenv), "hello"],
|
||||
env=self.env,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
subprocess.run(
|
||||
["direnv", "exec", str(self.testenv), "hello"], env=self.env, check=True
|
||||
sys.stderr.write(out1.stderr)
|
||||
self.assertIn("renewed cache and derivation link", out1.stderr)
|
||||
self.assertEqual(out1.returncode, 0)
|
||||
|
||||
run(["nix-collect-garbage"], check=True)
|
||||
run(["sh", "-c", "realpath /nix/var/nix/gcroots/per-user/$USER/*"], check=True)
|
||||
|
||||
out2 = run(
|
||||
["direnv", "exec", str(self.testenv), "hello"],
|
||||
env=self.env,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True,
|
||||
)
|
||||
sys.stderr.write(out2.stderr)
|
||||
self.assertIn("using cached derivation", out2.stderr)
|
||||
self.assertEqual(out2.returncode, 0)
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.dir.cleanup()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue