Fix tests

- `renewed_message` is now the same for `use nix` and `use flake`.
- we now expect `shellHook` to run, whether the environment is cached
  or not
This commit is contained in:
Eric Wolf 2022-04-03 11:56:41 +02:00 committed by Bryan Bennett
parent 3cca1afdec
commit a18e37535d
No known key found for this signature in database
GPG key ID: EF90E3E98B8F5C0B

View file

@ -40,6 +40,8 @@ class TestBaseNamespace:
cls.testenv = Path(cls.dir.name).joinpath("testenv") cls.testenv = Path(cls.dir.name).joinpath("testenv")
shutil.copytree(TEST_ROOT.joinpath("testenv"), cls.testenv) shutil.copytree(TEST_ROOT.joinpath("testenv"), cls.testenv)
cls.direnvrc = str(TEST_ROOT.parent.joinpath("direnvrc")) cls.direnvrc = str(TEST_ROOT.parent.joinpath("direnvrc"))
cls.renewed_message = "renewed cache"
cls.cached_message = "using cached dev shell"
with open(cls.testenv.joinpath(".envrc"), "w") as f: with open(cls.testenv.joinpath(".envrc"), "w") as f:
f.write(f"source {cls.direnvrc}\n{cls.direnvrc_command}") f.write(f"source {cls.direnvrc}\n{cls.direnvrc_command}")
@ -73,7 +75,7 @@ class TestBaseNamespace:
def test_fresh_shell_message(self) -> None: def test_fresh_shell_message(self) -> None:
self.assertIn(self.renewed_message, self.out1.stderr) self.assertIn(self.renewed_message, self.out1.stderr)
def test_fresh_shell_shellHook(self) -> None: def test_fresh_shell_shellHook_gets_executed(self) -> None:
self.assertIn("Executing shellHook.", self.out1.stderr) self.assertIn("Executing shellHook.", self.out1.stderr)
def test_fresh_shell_returncode(self) -> None: def test_fresh_shell_returncode(self) -> None:
@ -82,8 +84,8 @@ class TestBaseNamespace:
def test_cached_shell_message(self) -> None: def test_cached_shell_message(self) -> None:
self.assertIn(self.cached_message, self.out2.stderr) self.assertIn(self.cached_message, self.out2.stderr)
def test_cached_shell_shellHook(self) -> None: def test_cached_shell_shellHook_gets_executed(self) -> None:
self.assertNotIn("Executing shellHook.", self.out2.stderr) self.assertIn("Executing shellHook.", self.out2.stderr)
def test_cached_shell_returncode(self) -> None: def test_cached_shell_returncode(self) -> None:
self.assertEqual(self.out2.returncode, 0) self.assertEqual(self.out2.returncode, 0)
@ -91,14 +93,10 @@ class TestBaseNamespace:
class NixShellTest(TestBaseNamespace.TestBase): class NixShellTest(TestBaseNamespace.TestBase):
direnvrc_command = "use nix" direnvrc_command = "use nix"
renewed_message = "renewed cache and derivation link"
cached_message = "using cached derivation"
class FlakeTest(TestBaseNamespace.TestBase): class FlakeTest(TestBaseNamespace.TestBase):
direnvrc_command = "use flake" direnvrc_command = "use flake"
renewed_message = "renewed cache"
cached_message = "using cached dev shell"
def test_gcroot_symlink_created_and_valid(self) -> None: def test_gcroot_symlink_created_and_valid(self) -> None:
inputs = list(self.testenv.joinpath(".direnv/flake-inputs").iterdir()) inputs = list(self.testenv.joinpath(".direnv/flake-inputs").iterdir())