From 3789cd05d8006b54ccc2d4f64de1c81f31d409c8 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Mon, 4 May 2020 10:00:21 -0700 Subject: [PATCH] fish: fix and enable `fishConfig` test `nix-build -A fish.tests.fishConfig` will now test that the `fish_config` tool would start up properly. Previously, this test was effectively disabled due to `withTests` being stubbed out. I don't think this test ever truly worked, because the generated temporary file would be cleaned up automatically (or maybe this "automatically" changed between versions). The solution to this is to add `delete=False` to the `NamedTemporaryFile` function call, to keep the temporary file around in order to grep its contents for the expected output. --- pkgs/shells/fish/default.nix | 68 +++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/pkgs/shells/fish/default.nix b/pkgs/shells/fish/default.nix index 0f18eb79d2d808..11d9e48008faf6 100644 --- a/pkgs/shells/fish/default.nix +++ b/pkgs/shells/fish/default.nix @@ -16,6 +16,7 @@ , python3 , cmake +, runCommand , writeText , nixosTests , useOperatingSystemEtc ? true @@ -202,38 +203,41 @@ let passthru = { shellPath = "/bin/fish"; - tests.nixos = nixosTests.fish; + tests = { + nixos = nixosTests.fish; + + # Test the fish_config tool by checking the generated splash page. + # Since the webserver requires a port to run, it is not started. + fishConfig = + let fishScript = writeText "test.fish" '' + set -x __fish_bin_dir ${fish}/bin + echo $__fish_bin_dir + cp -r ${fish}/share/fish/tools/web_config/* . + chmod -R +w * + + # if we don't set `delete=False`, the file will get cleaned up + # automatically (leading the test to fail because there's no + # tempfile to check) + sed -e "s@, mode='w'@, mode='w', delete=False@" -i webconfig.py + + # we delete everything after the fileurl is assigned + sed -e '/fileurl =/q' -i webconfig.py + echo "print(fileurl)" >> webconfig.py + + # and check whether the message appears on the page + cat (${python3}/bin/python ./webconfig.py \ + | tail -n1 | sed -ne 's|.*\(/build/.*\)|\1|p' \ + ) | grep 'a href="http://localhost.*Start the Fish Web config' + + # cannot test the http server because it needs a localhost port + ''; + in + runCommand "test-web-config" { } '' + HOME=$(mktemp -d) + ${fish}/bin/fish ${fishScript} && touch $out + ''; + }; }; }; - - tests = { - - # Test the fish_config tool by checking the generated splash page. - # Since the webserver requires a port to run, it is not started. - fishConfig = - let - fishScript = writeText "test.fish" '' - set -x __fish_bin_dir ${fish}/bin - echo $__fish_bin_dir - cp -r ${fish}/share/fish/tools/web_config/* . - chmod -R +w * - # we delete everything after the fileurl is assigned - sed -e '/fileurl =/q' -i webconfig.py - echo "print(fileurl)" >> webconfig.py - # and check whether the message appears on the page - cat (${python3}/bin/python ./webconfig.py \ - | tail -n1 | sed -ne 's|.*\(/tmp/.*\)|\1|p' \ - ) | grep 'a href="http://localhost.*Start the Fish Web config' - - # cannot test the http server because it needs a localhost port - ''; - in '' - HOME=$(mktemp -d) - ${fish}/bin/fish ${fishScript} - ''; - }; - - # FIXME(Profpatsch) replace withTests stub - withTests = with lib; flip const; in -withTests tests fish +fish