| 1 |
#!/bin/csh -f |
| 2 |
# |
| 3 |
# INSTALL_TEST_CSH, csh-kind test launcher for install non-reg suite |
| 4 |
# Copyright (C) 2017-2021 Xavier Delaruelle |
| 5 |
# |
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 2 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
# |
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
# |
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
########################################################################## |
| 20 |
|
| 21 |
set progpath=$0 |
| 22 |
set progdir=`dirname $progpath` |
| 23 |
if ( "$progdir" == '' ) then |
| 24 |
set progdir='.' |
| 25 |
endif |
| 26 |
set ret=0 |
| 27 |
|
| 28 |
if ( $#argv < 4 ) then |
| 29 |
# print usage message |
| 30 |
echo "Usage: $progpath initfile mode shell command" |
| 31 |
exit 1 |
| 32 |
endif |
| 33 |
|
| 34 |
set initfile="$1" |
| 35 |
shift |
| 36 |
set mode=$1 |
| 37 |
shift |
| 38 |
set sh=$1 |
| 39 |
shift |
| 40 |
set cmdlist="$*" |
| 41 |
|
| 42 |
# get shell kind and options for sublaunch |
| 43 |
set shname=`basename $sh` |
| 44 |
switch ($shname) |
| 45 |
case bash: |
| 46 |
case ksh: |
| 47 |
case ksh93: |
| 48 |
case zsh: |
| 49 |
set shkind='sh' |
| 50 |
breaksw |
| 51 |
case tcsh: |
| 52 |
set shkind='csh' |
| 53 |
breaksw |
| 54 |
default: |
| 55 |
set shkind=$shname |
| 56 |
endsw |
| 57 |
switch ($shkind) |
| 58 |
# ignore global csh system init file to avoid side effect |
| 59 |
case csh: |
| 60 |
set shopts='-f' |
| 61 |
breaksw |
| 62 |
default: |
| 63 |
set shopts='' |
| 64 |
endsw |
| 65 |
|
| 66 |
# init module via autoinit cmd if modulecmd.tcl is initfile |
| 67 |
if ( "`basename '$initfile'`" == 'modulecmd.tcl' ) then |
| 68 |
set autoinit=0 |
| 69 |
else |
| 70 |
set autoinit=1 |
| 71 |
endif |
| 72 |
|
| 73 |
if ( $autoinit == 0 && ! -x "$initfile" ) then |
| 74 |
echo "ERROR: Cannot execute $initfile" |
| 75 |
exit 1 |
| 76 |
else if ( $autoinit != 0 && ! -r "$initfile" ) then |
| 77 |
echo "ERROR: Cannot read $initfile" |
| 78 |
exit 1 |
| 79 |
endif |
| 80 |
|
| 81 |
# source module init file if first step of given mode |
| 82 |
if ( "$mode" == 'top' || "$mode" == 'sub' || "$mode" == 'subsub' ) then |
| 83 |
if ( $autoinit == 0 ) then |
| 84 |
eval "`'$initfile' $shname autoinit`" |
| 85 |
else |
| 86 |
source "$initfile" |
| 87 |
endif |
| 88 |
endif |
| 89 |
|
| 90 |
# execute command list or perform recursive call |
| 91 |
switch ($mode) |
| 92 |
case top: |
| 93 |
case launch: |
| 94 |
# hardcode single quote test from 080-args to correctly pass the single |
| 95 |
# quotes to the module command |
| 96 |
set hardcodetest=1 |
| 97 |
if ( "$cmdlist" == "module load ''" ) then |
| 98 |
module load '' |
| 99 |
set ret=($ret + $status) |
| 100 |
set hardcodetest=0 |
| 101 |
endif |
| 102 |
if ( "$cmdlist" == "module load \'\'" ) then |
| 103 |
module load \'\' |
| 104 |
set ret=($ret + $status) |
| 105 |
set hardcodetest=0 |
| 106 |
endif |
| 107 |
if ( "$cmdlist" == "module append-path -d ' ' FOO /path/to/dir2;module source $TESTSUITEDIR/modulefiles.2/putsvar" ) then |
| 108 |
module append-path -d ' ' FOO /path/to/dir2 |
| 109 |
set ret=($ret + $status) |
| 110 |
module source $TESTSUITEDIR/modulefiles.2/putsvar |
| 111 |
set ret=($ret + $status) |
| 112 |
set hardcodetest=0 |
| 113 |
endif |
| 114 |
if ( "$cmdlist" =~ "*module sh-to-mod *csh testsuite/example/sh-to-mod.csh*" ) then |
| 115 |
module sh-to-mod csh testsuite/example/sh-to-mod.csh v\'l val\"e val\\\"e "" >& shtomod; |
| 116 |
set ret=($ret + $status) |
| 117 |
module load ./shtomod; |
| 118 |
set ret=($ret + $status) |
| 119 |
echo "${FOOCB}:${FOOEM}:${FOOSP}:${FOOWC}:${FOOARG1}:${FOOARG2}:${FOOARG3}:${FOOARG4}"; |
| 120 |
set ret=($ret + $status) |
| 121 |
alfoo; |
| 122 |
set ret=($ret + $status) |
| 123 |
alcb; |
| 124 |
set ret=($ret + $status) |
| 125 |
alsp; |
| 126 |
set ret=($ret + $status) |
| 127 |
set hardcodetest=0 |
| 128 |
endif |
| 129 |
|
| 130 |
if ( $hardcodetest != 0 ) then |
| 131 |
foreach cmd ("`echo '${cmdlist}' | tr ';' '\n'`") |
| 132 |
eval $cmd |
| 133 |
set ret=($ret + $status) |
| 134 |
end |
| 135 |
endif |
| 136 |
breaksw |
| 137 |
case sub: |
| 138 |
case sublaunch: |
| 139 |
$sh $shopts $progdir/install_test_${shkind} "$initfile" launch $sh "$cmdlist" |
| 140 |
set ret=$status |
| 141 |
breaksw |
| 142 |
case subsub: |
| 143 |
$sh $shopts $progdir/install_test_${shkind} "$initfile" sublaunch $sh "$cmdlist" |
| 144 |
set ret=$status |
| 145 |
breaksw |
| 146 |
default: |
| 147 |
echo "ERROR: Unrecognized mode option. Valid mode are 'top', 'sub', 'subsub'" |
| 148 |
exit 1 |
| 149 |
endsw |
| 150 |
|
| 151 |
# throw command exit code |
| 152 |
exit $ret |
| 153 |
|
| 154 |
# vim:set tabstop=3 shiftwidth=3 expandtab autoindent: |