about summary refs log tree commit diff
path: root/pkgs/applications/science/misc/root/tests
diff options
context:
space:
mode:
authorShamrock Lee <44064051+ShamrockLee@users.noreply.github.com>2022-10-12 03:11:09 +0800
committerShamrock Lee <44064051+ShamrockLee@users.noreply.github.com>2022-11-10 09:27:35 +0800
commita664ec27f44b4c7f29c03eff8b60ca62f90b2f16 (patch)
treede683a81b2f8a0e00a067d58333c14cb8e8b4d91 /pkgs/applications/science/misc/root/tests
parent7f91dec5ddf8a75c8da23df982ad027ba333a150 (diff)
root: add package test test-thisroot
Diffstat (limited to 'pkgs/applications/science/misc/root/tests')
-rw-r--r--pkgs/applications/science/misc/root/tests/default.nix4
-rw-r--r--pkgs/applications/science/misc/root/tests/test-thisroot.nix49
2 files changed, 53 insertions, 0 deletions
diff --git a/pkgs/applications/science/misc/root/tests/default.nix b/pkgs/applications/science/misc/root/tests/default.nix
new file mode 100644
index 0000000000000..9d2da2533f7f7
--- /dev/null
+++ b/pkgs/applications/science/misc/root/tests/default.nix
@@ -0,0 +1,4 @@
+{ callPackage }:
+{
+  test-thisroot = callPackage ./test-thisroot.nix { };
+}
diff --git a/pkgs/applications/science/misc/root/tests/test-thisroot.nix b/pkgs/applications/science/misc/root/tests/test-thisroot.nix
new file mode 100644
index 0000000000000..3540dde8c9138
--- /dev/null
+++ b/pkgs/applications/science/misc/root/tests/test-thisroot.nix
@@ -0,0 +1,49 @@
+{ lib
+, runCommand
+, root
+, bash
+, fish
+, ksh
+, tcsh
+, zsh
+}: runCommand "test-thisroot"
+{
+  meta = with lib; {
+    description = "Test for root thisroot.* sourcing";
+    maintainers = unique ((with maintainers; [ ShamrockLee ]) ++ root.meta.maintainers);
+  };
+}
+  ''
+    set -eu -o pipefail
+    declare -a shellNameArray shellOutpathArray sourcefileNameArray sourceCommandArray
+    shellNameArray=( bash zsh tcsh fish )
+    shellOutpathArray=( "${bash}" "${zsh}" "${tcsh}" "${fish}")
+    sourcefileNameArray=( thisroot.sh thisroot.sh thisroot.csh thisroot.fish )
+    sourceCommandArray=( "source" "source" "source" "source" )
+    debugFlagstrArray=( "-e" "-e" "-e" "" )
+    nShellToTest="''${#shellNameArray[@]}"
+    if [[ "''${#shellOutpathArray[@]}" -ne "$nShellToTest" ]] \
+      || [[ "''${#sourcefileNameArray[@]}" -ne "$nShellToTest" ]] \
+      || [[ "''${#sourceCommandArray[@]}" -ne "$nShellToTest" ]] \
+      || [[ "''${#debugFlagstrArray[@]}" -ne "$nShellToTest" ]]
+    then
+      echo "error: Lengths of test parameter arrays doesn't match." >&2
+      exit 1
+    fi
+    typePExpect="${root}/bin/root"
+    for ((i=0; i<$nShellToTest; ++i)); do
+      tryCommand="''${sourceCommandArray[$i]} \"${root}/bin/''${sourcefileNameArray[$i]}\""
+      echo "Testing ''${shellNameArray[$i]} $tryCommand"
+      # Home directory for Fish
+      HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)"
+      binPATHGot="$(PATH="''${shellOutpathArray[$i]}/bin" HOME=$HOME_TEMP "''${shellNameArray[$i]}" ''${debugFlagstrArray[$i]} -c "$tryCommand && echo \"\$PATH\"")"
+      rm -r "$HOME_TEMP"
+      typePGot="$(PATH="$binPATHGot" type -p root)"
+      if [[ "$typePGot" != "$typePExpect" ]]; then
+        echo "error: Got PATH \"$binPATHGot\", in which the root executable path is \"$typePGot\". Expect root executable path \"$typePExpect\"." >&2
+        exit 1
+      fi
+    done
+    echo "test-thisroot pass!"
+    touch "$out"
+  ''