From 3eec0cfb1818baba16b7199493262eaac4f52e4a Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 6 Nov 2020 11:33:56 +0100 Subject: [PATCH 1/3] fix(tests): add lsp & docs to tests We should make the test auto-discover which executables to search for. Maybe even have some functional tests which run the executables. --- shell.nix | 2 ++ test.bash | 2 ++ 2 files changed, 4 insertions(+) diff --git a/shell.nix b/shell.nix index 6d366e7..f8161d4 100644 --- a/shell.nix +++ b/shell.nix @@ -13,5 +13,7 @@ in dhall-bash-simple dhall-nix-simple dhall-yaml-simple + dhall-lsp-simple + dhall-docs-simple ]; } diff --git a/test.bash b/test.bash index 992af5c..ec26325 100755 --- a/test.bash +++ b/test.bash @@ -19,5 +19,7 @@ test_exe dhall-to-json; test_exe dhall-to-bash; test_exe dhall-to-nix; test_exe dhall-to-yaml-ng; +test_exe dhall-docs; +test_exe dhall-lsp-server; exit $ERRORS; From e555e2201c16ce3d7b5a151f6ff21d76ed78541b Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 6 Nov 2020 11:47:26 +0100 Subject: [PATCH 2/3] test(*): automatically check all binaries, based on binNames The test list would go out-of-date when new packages were added. This does the same check as before, but uses the binaries we already specify on the nix level (via a passthru). The next step is to try to run the binaries (e.g. with --version), which will give us a better test of whether they are actually executable. --- .github/workflows/ci.yml | 2 +- build.nix | 2 ++ test.bash | 25 ------------------------- test.nix | 39 +++++++++++++++++++++++++++++++++++++++ test.sh | 4 ++++ 5 files changed, 46 insertions(+), 26 deletions(-) delete mode 100755 test.bash create mode 100644 test.nix create mode 100755 test.sh diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d8f65dc..04fb87c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,4 +16,4 @@ jobs: steps: - uses: actions/checkout@v2 - uses: cachix/install-nix-action@v9 - - run: ./test.bash + - run: ./test.sh diff --git a/build.nix b/build.nix index 22ea7e8..b38b225 100644 --- a/build.nix +++ b/build.nix @@ -21,6 +21,8 @@ pkgs.stdenv.mkDerivation rec { nativeBuildInputs = [ pkgs.installShellFiles ]; + passthru.binNames = binNames; + installPhase = '' mkdir -p $out/bin diff --git a/test.bash b/test.bash deleted file mode 100755 index ec26325..0000000 --- a/test.bash +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env nix-shell -#!nix-shell -i bash - -ERRORS=0; - -function test_exe () { - EXE=$1; - LOCATION=$(command -v "$EXE"); - if [ -x "$LOCATION" ]; then - echo "found $EXE"; - else - echo "didnt find $EXE"; - ERRORS=1; - fi -} - -test_exe dhall; -test_exe dhall-to-json; -test_exe dhall-to-bash; -test_exe dhall-to-nix; -test_exe dhall-to-yaml-ng; -test_exe dhall-docs; -test_exe dhall-lsp-server; - -exit $ERRORS; diff --git a/test.nix b/test.nix new file mode 100644 index 0000000..02e0cf4 --- /dev/null +++ b/test.nix @@ -0,0 +1,39 @@ +{ pkgs ? import {} }: + +let + + lib = pkgs.lib; + + executables = lib.concatLists + (lib.mapAttrsToList + # every package puts its binNames into passthru + (_: v: map (bin: "${v}/bin/${bin}") v.passthru.binNames) + (import ./default.nix { inherit pkgs; })); + + testExeLocation = pkgs.writers.writeDash "test-exe-location" '' + set -e + ERRORS=0; + + test_exe () { + EXE=$1; + LOCATION=$(command -v "$EXE"); + if [ -x "$LOCATION" ]; then + echo "found $EXE"; + else + echo "didnt find $EXE"; + ERRORS=1; + fi + } + + for exe in ${lib.escapeShellArgs executables}; do + test_exe "$exe" + done + + exit "$ERRORS" + + ''; + +in { + inherit + testExeLocation; +} diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..6243540 --- /dev/null +++ b/test.sh @@ -0,0 +1,4 @@ +#!/usr/bin/env sh +set -e +test_script="$(nix-build ./test.nix)" +exec "$test_script" From 4d48badd725b67792a82858756fc213c1f67c17b Mon Sep 17 00:00:00 2001 From: Profpatsch Date: Fri, 6 Nov 2020 11:52:42 +0100 Subject: [PATCH 3/3] test(*): run --version on each command Simple test to see whether we can execute the commands. --- test.nix | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test.nix b/test.nix index 02e0cf4..b408f6f 100644 --- a/test.nix +++ b/test.nix @@ -16,12 +16,12 @@ let test_exe () { EXE=$1; - LOCATION=$(command -v "$EXE"); - if [ -x "$LOCATION" ]; then - echo "found $EXE"; + echo "$EXE --version:" + if $EXE --version; then + return 0 else - echo "didnt find $EXE"; - ERRORS=1; + echo "$EXE --version failed!" + ERRORS=1 fi }