Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 50 lines 1.9 kB view raw
1{ 2 lib, 3 runCommand, 4 root, 5 bash, 6 fish, 7 tcsh, 8 zsh, 9}: 10runCommand "test-thisroot" 11 { 12 meta = with lib; { 13 description = "Test for root thisroot.* sourcing"; 14 maintainers = unique ((with maintainers; [ ShamrockLee ]) ++ root.meta.maintainers); 15 }; 16 } 17 '' 18 set -eu -o pipefail 19 declare -a shellNameArray shellOutpathArray sourcefileNameArray sourceCommandArray 20 shellNameArray=( bash zsh tcsh fish ) 21 shellOutpathArray=( "${bash}" "${zsh}" "${tcsh}" "${fish}") 22 sourcefileNameArray=( thisroot.sh thisroot.sh thisroot.csh thisroot.fish ) 23 sourceCommandArray=( "source" "source" "source" "source" ) 24 debugFlagstrArray=( "-e" "-e" "-e" "" ) 25 nShellToTest="''${#shellNameArray[@]}" 26 if [[ "''${#shellOutpathArray[@]}" -ne "$nShellToTest" ]] \ 27 || [[ "''${#sourcefileNameArray[@]}" -ne "$nShellToTest" ]] \ 28 || [[ "''${#sourceCommandArray[@]}" -ne "$nShellToTest" ]] \ 29 || [[ "''${#debugFlagstrArray[@]}" -ne "$nShellToTest" ]] 30 then 31 echo "error: Lengths of test parameter arrays doesn't match." >&2 32 exit 1 33 fi 34 typePExpect="${root}/bin/root" 35 for ((i=0; i<$nShellToTest; ++i)); do 36 tryCommand="''${sourceCommandArray[$i]} \"${root}/bin/''${sourcefileNameArray[$i]}\"" 37 echo "Testing ''${shellNameArray[$i]} $tryCommand" 38 # Home directory for Fish 39 HOME_TEMP="$(mktemp -d temporary_home_XXXXXX)" 40 binPATHGot="$(PATH="''${shellOutpathArray[$i]}/bin" HOME=$HOME_TEMP "''${shellNameArray[$i]}" ''${debugFlagstrArray[$i]} -c "$tryCommand && echo \"\$PATH\"")" 41 rm -r "$HOME_TEMP" 42 typePGot="$(PATH="$binPATHGot" type -p root)" 43 if [[ "$typePGot" != "$typePExpect" ]]; then 44 echo "error: Got PATH \"$binPATHGot\", in which the root executable path is \"$typePGot\". Expect root executable path \"$typePExpect\"." >&2 45 exit 1 46 fi 47 done 48 echo "test-thisroot pass!" 49 touch "$out" 50 ''