improve tests

This commit is contained in:
Jörg Thalheim 2020-04-11 21:02:08 +01:00
parent c73420268c
commit 9b5b553521
No known key found for this signature in database
GPG key ID: 003F2096411B5F92

View file

@ -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()