about summary refs log tree commit diff
path: root/nixpkgs/pkgs/applications/science/misc/root/tests/test-thisroot.nix
blob: 3540dde8c91389d7dd35734a93a74bcb533985f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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"
  ''