| 1 |
############################################################################## |
| 2 |
# Modules Revision 3.0 |
| 3 |
# Providing a flexible user environment |
| 4 |
# |
| 5 |
# File: modules.70-maint/%M% |
| 6 |
# Revision: %I% |
| 7 |
# First Edition: 2017/11/25 |
| 8 |
# Last Mod.: %U%, %G% |
| 9 |
# |
| 10 |
# Authors: Xavier Delaruelle, [email protected] |
| 11 |
# |
| 12 |
# Description: Testuite testsequence |
| 13 |
# Command: append-path |
| 14 |
# Modulefiles: |
| 15 |
# Sub-Command: |
| 16 |
# |
| 17 |
# Comment: %C{ |
| 18 |
# Test 'append-path' module command |
| 19 |
# }C% |
| 20 |
# |
| 21 |
############################################################################## |
| 22 |
|
| 23 |
if {[info exists env(FOO)]} { |
| 24 |
if {$verbose} { |
| 25 |
send_user "\tUnset FOO\n" |
| 26 |
} |
| 27 |
set ORIG_FOO $env(FOO) |
| 28 |
unset env(FOO) |
| 29 |
} |
| 30 |
|
| 31 |
set path1 "/path/to/dir1" |
| 32 |
set path2 "/path/other/dir2" |
| 33 |
|
| 34 |
lappend ans [list set FOO $path1] |
| 35 |
|
| 36 |
testouterr_cmd_re "sh" "append-path FOO $path1" $ans "" |
| 37 |
|
| 38 |
skip_if_quick_mode |
| 39 |
|
| 40 |
if {$verbose} { |
| 41 |
send_user "\tSetup FOO = '$path1'\n" |
| 42 |
} |
| 43 |
set env(FOO) $path1 |
| 44 |
|
| 45 |
set ans [list] |
| 46 |
lappend ans [list set FOO "$path1"] |
| 47 |
testouterr_cmd_re "sh" "append-path FOO $path1" $ans "" |
| 48 |
|
| 49 |
set ans [list] |
| 50 |
lappend ans [list set FOO "$path1:$path2"] |
| 51 |
testouterr_cmd_re "ALL" "append-path FOO $path2" $ans "" |
| 52 |
testouterr_cmd_re "sh" "append-path -d : FOO $path2" $ans "" |
| 53 |
testouterr_cmd_re "sh" "append-path --delim : FOO $path2" $ans "" |
| 54 |
testouterr_cmd_re "sh" "append-path --delim=: FOO $path2" $ans "" |
| 55 |
|
| 56 |
set ans [list] |
| 57 |
lappend ans [list set FOO "$path1,$path2"] |
| 58 |
testouterr_cmd_re "sh" "append-path -d , FOO $path2" $ans "" |
| 59 |
testouterr_cmd_re "sh" "append-path --delim , FOO $path2" $ans "" |
| 60 |
testouterr_cmd_re "sh" "append-path --delim=, FOO $path2" $ans "" |
| 61 |
|
| 62 |
|
| 63 |
if {$verbose} { |
| 64 |
send_user "\tSetup FOO = '$path1:$path2'\n" |
| 65 |
} |
| 66 |
set env(FOO) "$path1:$path2" |
| 67 |
|
| 68 |
set ans [list] |
| 69 |
lappend ans [list set FOO "$path1:$path2"] |
| 70 |
testouterr_cmd_re "sh" "append-path FOO $path2" $ans "" |
| 71 |
|
| 72 |
set ans [list] |
| 73 |
lappend ans [list set __MODULES_SHARE_FOO ":1"] |
| 74 |
lappend ans [list set FOO "$path1:$path2:"] |
| 75 |
testouterr_cmd_re "sh" "append-path FOO " $ans "" |
| 76 |
|
| 77 |
# test bad argument list |
| 78 |
testouterr_cmd_re "sh" "append-path FOO" "ERR" "$error_msgs: Unexpected number of args for 'append-path' command\n$err_typehelp" |
| 79 |
testouterr_cmd_re "sh" "append-path -d : FOO" "ERR" "$error_msgs: append-path $msg_needenvvarval FOO" |
| 80 |
testouterr_cmd_re "sh" "append-path -d :" "ERR" "$error_msgs: append-path $msg_needenvvarname" |
| 81 |
testouterr_cmd_re "sh" "append-path -d : " "ERR" "$error_msgs: append-path $msg_validenvvarname" |
| 82 |
testouterr_cmd_re "sh" "append-path --delim= FOO /path/to" "ERR" "$error_msgs: append-path $msg_nonemptydelim" |
| 83 |
|
| 84 |
|
| 85 |
# |
| 86 |
# Append multiple paths passed as one string |
| 87 |
# |
| 88 |
|
| 89 |
set path1 "/path/to/dir1" |
| 90 |
if {$verbose} { |
| 91 |
send_user "\tSetup FOO = '$path1'\n" |
| 92 |
} |
| 93 |
set env(FOO) $path1 |
| 94 |
|
| 95 |
set ans [list] |
| 96 |
lappend ans [list set __MODULES_SHARE_FOO ":1"] |
| 97 |
lappend ans [list set FOO "$path1:/modules/testsuite2.2:/modules/testsuite2.2/2.2:"] |
| 98 |
testouterr_cmd_re "sh" "append-path FOO /modules/testsuite2.2:/modules/testsuite2.2/2.2:" $ans "" |
| 99 |
testouterr_cmd_re "sh" "append-path FOO /modules/testsuite2.2 /modules/testsuite2.2/2.2:" $ans "" |
| 100 |
|
| 101 |
# with specific delim |
| 102 |
if {$verbose} { |
| 103 |
send_user "\tSetup FOO = 'http://foobar.org,http://foobar.net'\n" |
| 104 |
} |
| 105 |
set env(FOO) "http://foobar.org,http://foobar.net" |
| 106 |
|
| 107 |
set ans [list] |
| 108 |
lappend ans [list set __MODULES_SHARE_FOO ":1"] |
| 109 |
lappend ans [list set FOO "http://foobar.org,http://foobar.net,http://foobar.com,http://foobar.io,"] |
| 110 |
testouterr_cmd_re "sh" "append-path -d , FOO http://foobar.com,http://foobar.io," $ans "" |
| 111 |
testouterr_cmd_re "sh" "append-path -d , FOO http://foobar.com http://foobar.io," $ans "" |
| 112 |
|
| 113 |
|
| 114 |
# |
| 115 |
# Append path in duplication mode |
| 116 |
# |
| 117 |
|
| 118 |
if {$verbose} { |
| 119 |
send_user "\tSetup FOO = '$path1'\n" |
| 120 |
} |
| 121 |
set env(FOO) $path1 |
| 122 |
|
| 123 |
set ans [list] |
| 124 |
# reference counter is increased due to the duplication mode |
| 125 |
lappend ans [list set __MODULES_SHARE_FOO "$path1:2"] |
| 126 |
lappend ans [list set FOO "$path1:$path1"] |
| 127 |
testouterr_cmd_re "sh" "append-path --duplicates FOO $path1" $ans "" |
| 128 |
testouterr_cmd_re "sh" "append-path --index --duplicates FOO $path1" $ans "$warn_msgs: --index option has no effect on append-path" |
| 129 |
|
| 130 |
|
| 131 |
# |
| 132 |
# Append path on DYLD-specific variables |
| 133 |
# |
| 134 |
|
| 135 |
set ans [list] |
| 136 |
lappend ans [list set DYLD_FOO "$path1"] |
| 137 |
testouterr_cmd_re "sh" "append-path DYLD_FOO $path1" $ans "" |
| 138 |
|
| 139 |
if {$verbose} { |
| 140 |
send_user "\tSetup DYLD_FOO = '$path1'\n" |
| 141 |
} |
| 142 |
set env(DYLD_FOO) $path1 |
| 143 |
|
| 144 |
# path-variable handling not effective on OSX with DYLD variables when System |
| 145 |
# Integrity Protection (SIP) is enabled: variables are not exported in |
| 146 |
# subshell context, so they appear undefined to modulecmd.tcl |
| 147 |
if {$sip_enabled} { |
| 148 |
set ans [list] |
| 149 |
lappend ans [list set DYLD_FOO "$path1"] |
| 150 |
} else { |
| 151 |
set ans [list] |
| 152 |
lappend ans [list set __MODULES_SHARE_DYLD_FOO "$path1:2"] |
| 153 |
lappend ans [list set DYLD_FOO "$path1:$path1"] |
| 154 |
} |
| 155 |
set tserr "(dyld: warning, unknown environment variable: DYLD_FOO\n|)" |
| 156 |
testouterr_cmd_re "sh" "append-path --duplicates DYLD_FOO $path1" $ans $tserr |
| 157 |
|
| 158 |
|
| 159 |
# |
| 160 |
# test path command arguments |
| 161 |
# |
| 162 |
|
| 163 |
testouterr_cmd sh {append-path FOO /tmp --remove-on-unload} ERR [err_invopt --remove-on-unload] |
| 164 |
testouterr_cmd sh {append-path FOO /tmp --append-on-unload /tmp} ERR [err_invopt --append-on-unload] |
| 165 |
testouterr_cmd sh {append-path FOO /tmp --prepend-on-unload /tmp} ERR [err_invopt --prepend-on-unload] |
| 166 |
testouterr_cmd sh {append-path FOO /tmp --noop-on-unload /tmp} ERR [err_invopt --noop-on-unload] |
| 167 |
|
| 168 |
|
| 169 |
# |
| 170 |
# test --glob option usage |
| 171 |
# |
| 172 |
|
| 173 |
set ans [list] |
| 174 |
lappend ans [list set FOO $path1:/tmp*] |
| 175 |
set tserr "$warn_msgs: --glob option has no effect on append-path" |
| 176 |
testouterr_cmd sh {append-path --glob FOO /tmp*} $ans $tserr |
| 177 |
|
| 178 |
|
| 179 |
# |
| 180 |
# test change to MODULEPATH |
| 181 |
# |
| 182 |
|
| 183 |
set ans [list] |
| 184 |
lappend ans [list set MODULEPATH $modpath:/path/to/dir] |
| 185 |
testouterr_cmd sh {append-path MODULEPATH /path/to/dir} $ans {} |
| 186 |
|
| 187 |
|
| 188 |
# |
| 189 |
# Cleanup |
| 190 |
# |
| 191 |
|
| 192 |
reset_test_env |