mirror of
https://github.com/nix-community/nix-direnv.git
synced 2025-11-08 19:46:11 +01:00
add tests
This commit is contained in:
parent
ea7c07e783
commit
862b772839
7 changed files with 112 additions and 0 deletions
12
.github/workflows/test.yml
vendored
Normal file
12
.github/workflows/test.yml
vendored
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
name: "Test"
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
jobs:
|
||||||
|
tests:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: cachix/install-nix-action@v7
|
||||||
|
- run:
|
||||||
|
nix-shell -I nixpkgs=https://github.com/NixOS/nixpkgs-channels/archive/nixpkgs-unstable.tar.gz ci.nix --run 'true'
|
||||||
21
ci.nix
Normal file
21
ci.nix
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
mkShell {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
shellcheck direnv mypy python3.pkgs.black python3.pkgs.flake8
|
||||||
|
];
|
||||||
|
|
||||||
|
shellHook = ''
|
||||||
|
set -e
|
||||||
|
echo -e "\x1b[32m## run shellcheck\x1b[0m"
|
||||||
|
LC_ALL=en_US.utf-8 black --check .
|
||||||
|
echo -e "\x1b[32m## run black\x1b[0m"
|
||||||
|
LC_ALL=en_US.utf-8 black --check .
|
||||||
|
echo -e "\x1b[32m## run flake8\x1b[0m"
|
||||||
|
flake8 --ignore E501 tests
|
||||||
|
echo -e "\x1b[32m## run mypy\x1b[0m"
|
||||||
|
mypy tests
|
||||||
|
|
||||||
|
echo -e "\x1b[32m## run unittest\x1b[0m"
|
||||||
|
${pkgs.python3.interpreter} -m unittest discover tests
|
||||||
|
'';
|
||||||
|
}
|
||||||
26
default.nix
Normal file
26
default.nix
Normal file
|
|
@ -0,0 +1,26 @@
|
||||||
|
{ pkgs ? import <nixpkgs> {} }:
|
||||||
|
|
||||||
|
with pkgs;
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
name = "nix-direnv";
|
||||||
|
|
||||||
|
src = ./.;
|
||||||
|
|
||||||
|
postPatch = ''
|
||||||
|
substituteInPlace direnvrc \
|
||||||
|
--replace "grep" "${gnugrep}/bin/grep" \
|
||||||
|
--replace "nix-shell" "${nix}/bin/nix-shell" \
|
||||||
|
--replace "nix-instantiate" "${nix}/bin/nix-shell"
|
||||||
|
'';
|
||||||
|
|
||||||
|
installPhase = ''
|
||||||
|
install -m500 -D direnvrc $out/share/nix-direnv/direnvrc
|
||||||
|
'';
|
||||||
|
|
||||||
|
meta = with stdenv.lib; {
|
||||||
|
description = "A fast, persistent use_nix implementation for direnv";
|
||||||
|
homepage = "https://github.com/nix-community/nix-direnv";
|
||||||
|
license = licenses.mit;
|
||||||
|
platforms = platforms.unix;
|
||||||
|
};
|
||||||
|
}
|
||||||
8
shell.nix
Normal file
8
shell.nix
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
mkShell {
|
||||||
|
nativeBuildInputs = [
|
||||||
|
python3
|
||||||
|
shellcheck
|
||||||
|
direnv
|
||||||
|
];
|
||||||
|
}
|
||||||
39
tests/test.py
Normal file
39
tests/test.py
Normal file
|
|
@ -0,0 +1,39 @@
|
||||||
|
#!/usr/bin/env python2
|
||||||
|
|
||||||
|
from tempfile import TemporaryDirectory
|
||||||
|
import os
|
||||||
|
import subprocess
|
||||||
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
|
||||||
|
TEST_ROOT = Path(__file__).resolve().parent
|
||||||
|
|
||||||
|
|
||||||
|
class IntegrationTest(unittest.TestCase):
|
||||||
|
def setUp(self) -> None:
|
||||||
|
self.env = os.environ.copy()
|
||||||
|
self.dir = TemporaryDirectory()
|
||||||
|
self.env["HOME"] = str(self.dir.name)
|
||||||
|
self.testenv = Path(self.dir.name).joinpath("testenv")
|
||||||
|
shutil.copytree(TEST_ROOT.joinpath("testenv"), self.testenv)
|
||||||
|
direnvrc = str(TEST_ROOT.parent.joinpath("direnvrc"))
|
||||||
|
with open(self.testenv.joinpath(".envrc"), "w") as f:
|
||||||
|
f.write(f"source {direnvrc}\n")
|
||||||
|
f.write(f"use nix")
|
||||||
|
|
||||||
|
def test_direnv(self) -> None:
|
||||||
|
subprocess.run(
|
||||||
|
["direnv", "allow"], cwd=str(self.testenv), env=self.env, check=True
|
||||||
|
)
|
||||||
|
subprocess.run(
|
||||||
|
["direnv", "exec", str(self.testenv), "hello"], env=self.env, check=True
|
||||||
|
)
|
||||||
|
|
||||||
|
def tearDown(self) -> None:
|
||||||
|
self.dir.cleanup()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
2
tests/testenv/.envrc
Normal file
2
tests/testenv/.envrc
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
source ../../direnvrc
|
||||||
|
use nix
|
||||||
4
tests/testenv/shell.nix
Normal file
4
tests/testenv/shell.nix
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
with import <nixpkgs> {};
|
||||||
|
mkShell {
|
||||||
|
nativeBuildInputs = [ hello ];
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue