Add tests

master
0xee 2019-12-03 20:43:28 +01:00
parent f6fc817e84
commit 0976f04505
5 changed files with 57 additions and 4 deletions

9
Makefile Normal file
View File

@ -0,0 +1,9 @@
build:
install:
mkdir -p $(PREFIX)/bin $(PREFIX)/share
cp direnv-cache $(PREFIX)/bin
cp direnvrc $(PREFIX)/share
check:
term-test -s tests

View File

@ -1,3 +1,13 @@
{ pkgs ? import <nixpkgs> {} }:
(pkgs.writers.writeBashBin "direnv-cache" ./direnv-cache).overrideAttrs
(o: { passthru = { direnvrc = ./direnvrc; }; })
{ stdenv, direnv, term-test }:
stdenv.mkDerivation {
name = "direnv-cache";
src = ./.;
propagatedBuildInputs = [ direnv ];
installPhase = ''
make install PREFIX=$out
'';
checkInputs = [ term-test ];
doCheck = true;
passthru = { direnvrc = ./direnvrc; };
}

View File

@ -14,4 +14,3 @@ cache() {
echo "Environment not cached"
fi
}

2
shell.nix Normal file
View File

@ -0,0 +1,2 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.callPackage ./. {}

View File

@ -0,0 +1,33 @@
# -*- mode: sh -*-
function initDirenv {
# direnv needs a writable home:
run "export HOME=$(pwd)"
run 'eval "$(direnv hook bash)"'
}
function test_simpleEnvrcWorks {
initDirenv
writeFile .envrc <<EOF
export FOO=bar
EOF
run "direnv allow"
assert "$(getEnv FOO)" == bar
}
function test_direnvExecRunsInCleanEnv {
initDirenv
run "export FOO=baz"
writeFile .envrc <<EOF
export FOO=bar
EOF
run "direnv allow"
assert "$(getEnv FOO)" == bar
#captureShell 'echo $FOO'
#captureShell 'direnv exec /proc env | grep FOO'
assert "$(captureShell 'direnv exec /proc env | grep FOO')" == "FOO=baz"
}