##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2020/05/20
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:
#   Modulefiles:    source-sh
#   Sub-Command:    *
#
#   Comment:	%C{
#           Check 'source-sh' modulefile command
#		}C%
#
##############################################################################

set mp $modpath.2
set mpre [regsub -all "\(\[.+?\]\)" $mp {\\\1}]

# setup specific environment
setenv_path_var MODULEPATH $mp

setenv_var TESTSUITE_SHTOMOD_PATHDUP 1


#
# load and unload tests
#

# basic load
set ans [list]
lappend ans [list set FOOPATHCB_modshare /path/to/d\{r2:1:/path/to/dir1:1:/path/to/dir3:1]
lappend ans [list set _LMFILES_ $mp/source-sh/1]
lappend ans [list set LOADEDMODULES source-sh/1]
lappend ans [list set FOOPATHDUP "/path/to/dir1:/path/to/dir2:/path/to/dir3:/path/to dir4"]
lappend ans [list set FOOPATHDUPMIX_modshare ":1:/path/to/dir1 /path/to/dir2 /path/to/dir1:1:/path/to/dir1:1:/path/to/dir3:1"]
lappend ans [list set FOOPATHEM :/path/to/dir1:/path/to/dir2:/path/to/dir3]
lappend ans [list set FOOPATHSP {/path/to/dir1 /path/to/dir2 /path/to/dir3}]
lappend ans [list set FOOPATHEM_modshare :1:/path/to/dir1:1:/path/to/dir2:1:/path/to/dir3:1]
lappend ans [list set FOOEM {}]
lappend ans [list set FOOPATHCB /path/to/dir1:/path/to/d\{r2:/path/to/dir3]
lappend ans [list set FOOPATHDUPEM_modshare :1:/path/to/dir1:1:/path/to/dir2:1:/path/to/dir3:1]
lappend ans [list set FOOSP {value }]
lappend ans [list set FOOPATHDUPSPEM {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to/dir3 }]
lappend ans [list set FOOPATHDUPMIX ":/path/to/dir1:/path/to/dir1 /path/to/dir2 /path/to/dir1:/path/to/dir3"]
lappend ans [list set FOOCB va\{ue]
lappend ans [list set FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3]
lappend ans [list set FOOPATH_modshare /path/to/dir1:1:/path/to/dir2:1:/path/to/dir3:1]
lappend ans [list set _LMFILES__modshare $mp/source-sh/1:1]
lappend ans [list set LOADEDMODULES_modshare source-sh/1:1]
lappend ans [list set FOO value]
lappend ans [list set FOOPATHDUP_modshare "/path/to/dir1:1:/path/to dir4:1:/path/to/dir2:1:/path/to/dir3:1"]
lappend ans [list set FOOPATHDUPEM :/path/to/dir1:/path/to/dir2:/path/to/dir3]
lappend ans [list set MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}]
lappend ans [list set FOOPATHDUPSP "/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to:dir4 /path/to/dir3"]
lappend ans [list set FOOPATHSPEM {/path/to/dir1 /path/to/dir2 /path/to/dir3 }]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}:1]
lappend ans [list set FOOPATHDUPSP_modshare "/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to:1:dir4 /path/to/dir3:1"]
lappend ans [list alias alsp {echo f\"o; echo b\\\"r; echo f\'o}]
lappend ans [list alias alfoo {echo $(grep "report .Modules " ../../modulecmd.tcl | tr -d \\ 2>/dev/null | awk '{print $3}')}]
lappend ans [list alias alcb echo\ f\{o]
lappend ans [list alias alem {}]
lappend ans [list funcfoo "() { echo foo; };"]
lappend ans [list funccb "() { echo f\{o; };"]
lappend ans [list funcnl "() { echo foo;
    echo bar; };"]
lappend ans [list funcsp "() { echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o; };"]
lappend ans [list chdir $mp]

testouterr_cmd sh {load source-sh/1} $ans {}

# basic unload
setenv_loaded_module [list source-sh/1] [list $mp/source-sh/1]
setenv_path_var MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}
setenv_path_var FOOPATHDUP "/path/to/dir1:/path/to/dir2:/path/to/dir3:/path/to dir4"
setenv_path_var FOOPATHEM :/path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_path_var FOOPATHCB /path/to/dir1:/path/to/d\{r2:/path/to/dir3
setenv_path_var FOOPATHDUPMIX ":/path/to/dir1:/path/to/dir1 /path/to/dir2 /path/to/dir1:/path/to/dir3"
setenv_path_var FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_path_var FOOPATHDUPEM :/path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_path_var FOOPATHDUPSP "/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to:dir4 /path/to/dir3"
setenv_var FOOPATHSP {/path/to/dir1 /path/to/dir2 /path/to/dir3}
setenv_var FOOEM {}
setenv_var FOOSP {value }
setenv_var FOOPATHDUPSPEM {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to/dir3 }
setenv_var FOOCB va\{ue
setenv_var FOO value
setenv_var FOOPATHSPEM {/path/to/dir1 /path/to/dir2 /path/to/dir3 }

set ans [list]
lappend ans [list unset FOOPATHCB_modshare]
lappend ans [list unset _LMFILES_]
lappend ans [list unset LOADEDMODULES]
lappend ans [list unset FOOPATHDUP]
lappend ans [list unset FOOPATHDUPMIX_modshare]
lappend ans [list unset FOOPATHEM]
lappend ans [list unset FOOPATHSP]
lappend ans [list unset FOOPATHEM_modshare]
lappend ans [list unset FOOEM]
lappend ans [list unset FOOPATHCB]
lappend ans [list unset FOOPATHDUPEM_modshare]
lappend ans [list unset FOOSP]
lappend ans [list unset FOOPATHDUPSPEM]
lappend ans [list unset FOOPATHDUPMIX]
lappend ans [list unset FOOCB]
lappend ans [list unset FOOPATH]
lappend ans [list unset FOOPATH_modshare]
lappend ans [list unset _LMFILES__modshare]
lappend ans [list unset LOADEDMODULES_modshare]
lappend ans [list unset FOO]
lappend ans [list unset FOOPATHDUP_modshare]
lappend ans [list unset FOOPATHDUPEM]
lappend ans [list unset MODULES_LMSOURCESH]
lappend ans [list unset FOOPATHDUPSP]
lappend ans [list unset FOOPATHSPEM]
lappend ans [list unset MODULES_LMSOURCESH_modshare]
lappend ans [list unset FOOPATHDUPSP_modshare]
lappend ans [list unalias alsp]
lappend ans [list unalias alfoo]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funcfoo;"]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
testouterr_cmd sh {unload source-sh/1} $ans {}

# load other modulefiles using source-sh
set ans [list]
lappend ans [list setpath LOADEDMODULES source-sh/1:source-sh/2]
lappend ans [list setpath _LMFILES_ $mp/source-sh/1:$mp/source-sh/2]
lappend ans [list setpath FOOPATH /path/to/mini:/path/to/dir1:/path/to/dir2:/path/to/dir3]
lappend ans [list set FOOMINI value]
lappend ans [list setpath MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}:source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value]
lappend ans [list alias almini echo\ mini]
testouterr_cmd_re sh {load source-sh/2} $ans {}

# unload one of these modulefiles
setenv_loaded_module [list source-sh/1 source-sh/2] [list $mp/source-sh/1 $mp/source-sh/2]
setenv_var FOOMINI value
setenv_path_var FOOPATH /path/to/mini:/path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_path_var MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}:source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value

set ans [list]
lappend ans [list set _LMFILES__modshare $mp/source-sh/1:1]
lappend ans [list set LOADEDMODULES_modshare source-sh/1:1]
lappend ans [list set MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}]
lappend ans [list unset FOOMINI]
lappend ans [list set FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3]
lappend ans [list set _LMFILES_ $mp/source-sh/1]
lappend ans [list set LOADEDMODULES source-sh/1]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}:1]
lappend ans [list set FOOPATH_modshare /path/to/dir1:1:/path/to/dir2:1:/path/to/dir3:1]
lappend ans [list unalias almini]
testouterr_cmd sh {unload source-sh/2} $ans {}

set ans [list]
lappend ans [list unset FOOPATHCB_modshare]
lappend ans [list set _LMFILES_ $mp/source-sh/2]
lappend ans [list set LOADEDMODULES source-sh/2]
lappend ans [list unset FOOPATHDUP]
lappend ans [list unset FOOPATHDUPMIX_modshare]
lappend ans [list unset FOOPATHEM]
lappend ans [list unset FOOPATHSP]
lappend ans [list unset FOOPATHEM_modshare]
lappend ans [list unset FOOEM]
lappend ans [list unset FOOPATHCB]
lappend ans [list unset FOOPATHDUPEM_modshare]
lappend ans [list unset FOOSP]
lappend ans [list unset FOOPATHDUPSPEM]
lappend ans [list unset FOOPATHDUPMIX]
lappend ans [list unset FOOCB]
lappend ans [list set FOOPATH /path/to/mini]
lappend ans [list set FOOPATH_modshare /path/to/mini:1]
lappend ans [list set _LMFILES__modshare $mp/source-sh/2:1]
lappend ans [list set LOADEDMODULES_modshare source-sh/2:1]
lappend ans [list unset FOO]
lappend ans [list unset FOOPATHDUP_modshare]
lappend ans [list unset FOOPATHDUPEM]
lappend ans [list set MODULES_LMSOURCESH source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value]
lappend ans [list unset FOOPATHDUPSP]
lappend ans [list unset FOOPATHSPEM]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value:1]
lappend ans [list unset FOOPATHDUPSP_modshare]
lappend ans [list unalias alsp]
lappend ans [list unalias alfoo]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funcfoo;"]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
testouterr_cmd sh {unload source-sh/1} $ans {}

# load a third modulefile, using same script than firstly loaded module
set ans [list]
lappend ans [list set FOOPATHDUPMIX_modshare ":2:/path/to/dir1 /path/to/dir2 /path/to/dir1:1:/path/to/dir1:1:/path/to/dir3:2"]
lappend ans [list set FOOPATHDUP "/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3:/path/to dir4:/path/to/dir3"]
lappend ans [list unset FOOPATHDUPEM_modshare]
lappend ans [list set FOOPATHDUPMIX :/path/to/dir1:/path/to/dir1\ /path/to/dir2\ /path/to/dir1:/path/to/dir3]
lappend ans [list set FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3]
lappend ans [list unset FOOPATH_modshare]
lappend ans [list unset FOOPATHDUP_modshare]
lappend ans [list set FOOPATHDUPEM :/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3::/path/to/dir3]
lappend ans [list setpath LOADEDMODULES source-sh/1:source-sh/2:source-sh/3]
lappend ans [list setpath _LMFILES_ $mp/source-sh/1:$mp/source-sh/2:$mp/source-sh/3]
lappend ans [list setpath MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}:source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value:source-sh/3\&bash\ testsuite/example/sh-to-mod.sh\|append-path\ FOOPATHDUPMIX\ /path/to/dir3\ \{\}\|chdir\ $mp\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOOPATH\ /path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir3\|setenv\ FOOPATHDUP\ \{/path/to/dir1\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir3\<EnvModEscPS\>/path/to\ dir4\<EnvModEscPS\>/path/to/dir3\}\|setenv\ FOOPATHDUPEM\ \<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir3\<EnvModEscPS\>\<EnvModEscPS\>/path/to/dir3]
lappend ans [list alias alsp {echo f\"o; echo b\\\"r; echo f\'o}]
lappend ans [list alias alfoo {echo $(grep "report .Modules " ../../modulecmd.tcl | tr -d \\ 2>/dev/null | awk '{print $3}')}]
lappend ans [list alias alcb echo\ f\{o]
lappend ans [list alias alem {}]
lappend ans [list funcfoo "\\\(\\\) { echo foo; };"]
lappend ans [list funccb "\\\(\\\) { echo f\{o; };"]
lappend ans [list funcnl "\\\(\\\) { echo foo;
    echo bar; };"]
lappend ans [list funcsp "\\\(\\\) { echo f\\\\\"o;
    echo b\\\\\\\\\\\\\"r;
    echo f\\\\'o; };"]
lappend ans [list chdir $mpre]

testouterr_cmd_re sh {load source-sh/3} $ans {}

# unload from that point
setenv_loaded_module [list source-sh/1 source-sh/2 source-sh/3] [list $mp/source-sh/1 $mp/source-sh/2 $mp/source-sh/3]
setenv_var FOOPATHDUP "/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3:/path/to dir4:/path/to/dir3"
unsetenv_var FOOPATHDUPEM_modshare
unsetenv_var FOOPATH_modshare
unsetenv_var FOOPATHDUP_modshare
setenv_path_var FOOPATHDUPMIX :/path/to/dir1:/path/to/dir1\ /path/to/dir2\ /path/to/dir1:/path/to/dir3
setenv_var FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_var FOOPATHDUPEM :/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3::/path/to/dir3
setenv_path_var MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}\|setenv\ FOOSP\ \{value\ \}:source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value:source-sh/3\&bash\ testsuite/example/sh-to-mod.sh\|append-path\ FOOPATHDUPMIX\ /path/to/dir3\ \{\}\|chdir\ $mp\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOOPATH\ /path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir3\|setenv\ FOOPATHDUP\ \{/path/to/dir1\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir3\<EnvModEscPS\>/path/to\ dir4\<EnvModEscPS\>/path/to/dir3\}\|setenv\ FOOPATHDUPEM\ \<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir3\<EnvModEscPS\>\<EnvModEscPS\>/path/to/dir3

set ans [list]
lappend ans [list unset FOOPATHDUP]
lappend ans [list unset FOOPATHSP]
lappend ans [list unset FOOSP]
lappend ans [list unset FOOPATHDUPSPEM]
lappend ans [list unset FOOCB]
lappend ans [list unset FOOPATH]
lappend ans [list unset FOOPATHDUPEM]
lappend ans [list unset FOO]
lappend ans [list unset FOOPATHSPEM]
lappend ans [list unsetpath FOOPATHDUPMIX]
lappend ans [list unsetpath FOOPATHEM]
lappend ans [list unsetpath FOOPATHCB]
lappend ans [list unsetpath FOOPATHDUPSP]
lappend ans [list unset FOOEM]
lappend ans [list setpath LOADEDMODULES source-sh/2:source-sh/3]
lappend ans [list setpath _LMFILES_ $mp/source-sh/2:$mp/source-sh/3]
lappend ans [list setpath MODULES_LMSOURCESH source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value:source-sh/3\&bash\ testsuite/example/sh-to-mod.sh\|append-path\ FOOPATHDUPMIX\ /path/to/dir3\ \{\}\|chdir\ $mp\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alfoo\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcfoo\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOOPATH\ /path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir3\|setenv\ FOOPATHDUP\ \{/path/to/dir1\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir3\<EnvModEscPS\>/path/to\ dir4\<EnvModEscPS\>/path/to/dir3\}\|setenv\ FOOPATHDUPEM\ \<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir2\<EnvModEscPS\>/path/to/dir1\<EnvModEscPS\>/path/to/dir3\<EnvModEscPS\>\<EnvModEscPS\>/path/to/dir3]
lappend ans [list unalias alsp]
lappend ans [list unalias alfoo]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funcfoo;"]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
testouterr_cmd_re sh {unload source-sh/1} $ans {}


#
# test other modes
#

# test 'list' sub-command
testouterr_cmd sh {list -t} OK $cur_loaded\nsource-sh/1\nsource-sh/2\nsource-sh/3

# test 'whatis' sub-command when some modules are loaded
testouterr_cmd_re sh {whatis source-sh} OK "$modlin $mpre $modlin
\\s*source-sh/1: source-sh/1
\\s*source-sh/2: source-sh/2
\\s*source-sh/3: source-sh/3
\\s*source-sh/4.0: source-sh/4.0
\\s*source-sh/4.1: source-sh/4.1
\\s*source-sh/4.2: source-sh/4.2
\\s*source-sh/4.3: source-sh/4.3
\\s*source-sh/6.0: source-sh/6.0"

# test 'help' sub-command when some modules are loaded
testouterr_cmd_re sh {help source-sh/1} OK "$modlin
Module Specific Help for $mpre/source-sh/1:

$warn_msgs: Unable to find ModulesHelp in $mpre/source-sh/1.
$modlin"
testouterr_cmd_re sh {help source-sh/4.3} OK "$modlin
Module Specific Help for $mpre/source-sh/4.3:

$warn_msgs: Unable to find ModulesHelp in $mpre/source-sh/4.3.
$modlin"

# test 'test' sub-command when some modules are loaded
testouterr_cmd_re sh {test source-sh/1} OK "$modlin
Module Specific Test for $mpre/source-sh/1:

$warn_msgs: Unable to find ModulesTest in $mpre/source-sh/1.
$modlin"
testouterr_cmd_re sh {test source-sh/4.3} OK "$modlin
Module Specific Test for $mpre/source-sh/4.3:

$warn_msgs: Unable to find ModulesTest in $mpre/source-sh/4.3.
$modlin"

# test 'display' sub-command when some modules are loaded
set tserr_disp1 "-------------------------------------------------------------------
$mp/source-sh/1:

chdir\t\t$mp
prepend-path\tFOOPATH /path/to/dir1 /path/to/dir2 /path/to/dir3
prepend-path\tFOOPATHCB /path/to/dir1 /path/to/d\{r2 /path/to/dir3
prepend-path\tFOOPATHDUP /path/to/dir1 /path/to/dir2 /path/to/dir3 {/path/to dir4}
prepend-path\tFOOPATHDUPEM {} /path/to/dir1 /path/to/dir2 /path/to/dir3
prepend-path\tFOOPATHDUPMIX {} /path/to/dir1 {/path/to/dir1 /path/to/dir2 /path/to/dir1} /path/to/dir3
prepend-path\tFOOPATHDUPSP {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to} {dir4 /path/to/dir3}
prepend-path\tFOOPATHEM {} /path/to/dir1 /path/to/dir2 /path/to/dir3
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv\t\tFOO value
setenv\t\tFOOCB va\{ue
setenv\t\tFOOEM {}
setenv\t\tFOOPATHDUPSPEM {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to/dir3 }
setenv\t\tFOOPATHSP {/path/to/dir1 /path/to/dir2 /path/to/dir3}
setenv\t\tFOOPATHSPEM {/path/to/dir1 /path/to/dir2 /path/to/dir3 }
setenv\t\tFOOSP {value }
module-whatis\tsource-sh/1
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/1} OK $tserr_disp1
set tserr_disp2 "-------------------------------------------------------------------
$mp/source-sh/4.3:

[msg_moderr {Script 'testsuite/example/unk-to-mod.sh' cannot be found} {source-sh sh testsuite/example/unk-to-mod.sh} $mp/source-sh/4.3 2 {  }]
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/4.3} ERR $tserr_disp2
set tserr_disp3 "-------------------------------------------------------------------
$mp/source-sh/5.0:

append-path	FOOPATHDUPMIX /path/to/dir3 {}
chdir		$mp
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
prepend-path	FOOPATH /path/to/mini
set-alias	almini {echo mini}
append-path	FOOPATHDUPMIX /path/to/dir3 {}
chdir		$mp
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv		FOOARG1 arg1
setenv		FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/5.0} OK $tserr_disp3
set tserr_disp4 "-------------------------------------------------------------------
$mp/source-sh/5.1:

append-path	FOOPATHDUPMIX /path/to/dir3 {}
chdir		$mp
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv		FOOARG1 arg1
setenv		FOOARG2 arg2
prepend-path	FOOPATH /path/to/mini
set-alias	almini {echo mini}
append-path	FOOPATHDUPMIX /path/to/dir3 {}
chdir		$mp
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv		FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/5.1} OK $tserr_disp4


unsetenv_loaded_module
unsetenv_path_var MODULES_LMSOURCESH
unsetenv_path_var FOOPATHDUP
unsetenv_path_var FOOPATHEM
unsetenv_path_var FOOPATHCB
unsetenv_path_var FOOPATHDUPMIX
unsetenv_path_var FOOPATH
unsetenv_path_var FOOPATHDUPEM
unsetenv_path_var FOOPATHDUPSP
unsetenv_var FOOPATHSP
unsetenv_var FOOEM
unsetenv_var FOOSP
unsetenv_var FOOPATHDUPSPEM
unsetenv_var FOOCB
unsetenv_var FOO
unsetenv_var FOOPATHSPEM
unsetenv_var FOOMINI

# test 'whatis' sub-command when no module loaded
testouterr_cmd_re sh {whatis source-sh} OK "$modlin $mpre $modlin
\\s*source-sh/1: source-sh/1
\\s*source-sh/2: source-sh/2
\\s*source-sh/3: source-sh/3
\\s*source-sh/4.0: source-sh/4.0
\\s*source-sh/4.1: source-sh/4.1
\\s*source-sh/4.2: source-sh/4.2
\\s*source-sh/4.3: source-sh/4.3"

# test 'help' sub-command when no module loaded
testouterr_cmd_re sh {help source-sh/1} OK "$modlin
Module Specific Help for $mpre/source-sh/1:

$warn_msgs: Unable to find ModulesHelp in $mpre/source-sh/1.
$modlin"
testouterr_cmd_re sh {help source-sh/4.3} OK "$modlin
Module Specific Help for $mpre/source-sh/4.3:

$warn_msgs: Unable to find ModulesHelp in $mpre/source-sh/4.3.
$modlin"

# test 'test' sub-command when no module loaded
testouterr_cmd_re sh {test source-sh/1} OK "$modlin
Module Specific Test for $mpre/source-sh/1:

$warn_msgs: Unable to find ModulesTest in $mpre/source-sh/1.
$modlin"
testouterr_cmd_re sh {test source-sh/4.3} OK "$modlin
Module Specific Test for $mpre/source-sh/4.3:

$warn_msgs: Unable to find ModulesTest in $mpre/source-sh/4.3.
$modlin"

# test 'display' sub-command when no module loaded
testouterr_cmd sh {display source-sh/1} OK $tserr_disp1
testouterr_cmd sh {display source-sh/4.3} ERR $tserr_disp2
set tserr_disp3 "-------------------------------------------------------------------
$mp/source-sh/5.0:

chdir		$mp
prepend-path	FOOPATH /path/to/dir1 /path/to/dir2 /path/to/dir3
prepend-path	FOOPATHCB /path/to/dir1 /path/to/d{r2 /path/to/dir3
prepend-path	FOOPATHDUP /path/to/dir1 /path/to/dir2 /path/to/dir3 {/path/to dir4}
prepend-path	FOOPATHDUPEM {} /path/to/dir1 /path/to/dir2 /path/to/dir3
prepend-path	FOOPATHDUPMIX {} /path/to/dir1 {/path/to/dir1 /path/to/dir2 /path/to/dir1} /path/to/dir3
prepend-path	FOOPATHDUPSP {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to} {dir4 /path/to/dir3}
prepend-path	FOOPATHEM {} /path/to/dir1 /path/to/dir2 /path/to/dir3
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv		FOO value
setenv		FOOCB va{ue
setenv		FOOEM {}
setenv		FOOPATHDUPSPEM {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to/dir3 }
setenv		FOOPATHSP {/path/to/dir1 /path/to/dir2 /path/to/dir3}
setenv		FOOPATHSPEM {/path/to/dir1 /path/to/dir2 /path/to/dir3 }
setenv		FOOSP {value }
prepend-path	FOOPATH /path/to/mini
set-alias	almini {echo mini}
setenv		FOOMINI value
append-path	FOOPATHDUPMIX /path/to/dir3 {}
chdir		$mp
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv		FOOARG1 arg1
setenv		FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3
setenv		FOOPATHDUP {/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3:/path/to dir4:/path/to/dir3}
setenv		FOOPATHDUPEM :/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3::/path/to/dir3
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/5.0} OK $tserr_disp3
set tserr_disp4 "-------------------------------------------------------------------
$mp/source-sh/5.1:

chdir		$mp
prepend-path	FOOPATH /path/to/dir1 /path/to/dir2 /path/to/dir3
prepend-path	FOOPATHCB /path/to/dir1 /path/to/d{r2 /path/to/dir3
prepend-path	FOOPATHDUP /path/to/dir1 /path/to/dir2 /path/to/dir3 {/path/to dir4}
prepend-path	FOOPATHDUPEM {} /path/to/dir1 /path/to/dir2 /path/to/dir3
prepend-path	FOOPATHDUPMIX {} /path/to/dir1 {/path/to/dir1 /path/to/dir2 /path/to/dir1} /path/to/dir3
prepend-path	FOOPATHDUPSP {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to} {dir4 /path/to/dir3}
prepend-path	FOOPATHEM {} /path/to/dir1 /path/to/dir2 /path/to/dir3
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv		FOO value
setenv		FOOARG1 arg1
setenv		FOOARG2 arg2
setenv		FOOCB va{ue
setenv		FOOEM {}
setenv		FOOPATHDUPSPEM {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to/dir3 }
setenv		FOOPATHSP {/path/to/dir1 /path/to/dir2 /path/to/dir3}
setenv		FOOPATHSPEM {/path/to/dir1 /path/to/dir2 /path/to/dir3 }
setenv		FOOSP {value }
prepend-path	FOOPATH /path/to/mini
set-alias	almini {echo mini}
setenv		FOOMINI value
append-path	FOOPATHDUPMIX /path/to/dir3 {}
chdir		$mp
set-alias\talcb {echo\ f\{o}
set-alias\talem {}
set-alias\talfoo {echo \$(grep \"report .Modules \" ../../modulecmd.tcl | tr -d \\\\ 2>/dev/null | awk '\{print \$3\}')}
set-alias\talsp {echo f\\\"o; echo b\\\\\\\"r; echo f\\'o}
set-function\tfunccb {
    echo f\{o}
set-function\tfuncfoo {
    echo foo}
set-function\tfuncnl {
    echo foo;
    echo bar}
set-function\tfuncsp {
    echo f\\\"o;
    echo b\\\\\\\"r;
    echo f\\'o}
setenv		FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3
setenv		FOOPATHDUP {/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3:/path/to dir4:/path/to/dir3}
setenv		FOOPATHDUPEM :/path/to/dir1:/path/to/dir1:/path/to/dir2:/path/to/dir1:/path/to/dir3::/path/to/dir3
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/5.1} OK $tserr_disp4

#
# erroneous call or script
#

# test bad source-sh call
if {[cmpversion $tclsh_version 8.5] == -1} {
    set msgtcl args
} elseif {[cmpversion $tclsh_version 8.6] == -1} {
    set msgtcl ...
} else {
    set msgtcl {?arg ...?}
}
set tserr "$moderr_msgs: wrong # args: should be \"source-sh shell script $msgtcl\"
    invoked from within
\"source-sh sh\"
    (file \"$mp/source-sh/4.0\" line 2)
$err_contactns"
testouterr_cmd sh {load source-sh/4.0} ERR [msg_load source-sh/4.0 $tserr]
set tserr "$moderr_msgs: wrong # args: should be \"source-sh shell script $msgtcl\"
    invoked from within
\"source-sh\"
    (file \"$mp/source-sh/4.1\" line 2)
$err_contactns"
testouterr_cmd sh {load source-sh/4.1} ERR [msg_load source-sh/4.1 $tserr]
set tserr [msg_moderr {Shell 'unk' not supported} {source-sh unk testsuite/example/sh-to-mod.sh} $mp/source-sh/4.2 2]
testouterr_cmd sh {load source-sh/4.2} ERR [msg_load source-sh/4.2 $tserr]
set tserr [msg_moderr {Script 'testsuite/example/unk-to-mod.sh' cannot be found} {source-sh sh testsuite/example/unk-to-mod.sh} $mp/source-sh/4.3 2]
testouterr_cmd sh {load source-sh/4.3} ERR [msg_load source-sh/4.3 $tserr]

# error during script evaluation
setenv_var TESTSUITE_SHTOMOD_FUZZYOUT1 1
set tserr [msg_moderr {Unexpected output when sourcing 'testsuite/example/sh-to-mod.sh' in shell 'bash'} {source-sh bash testsuite/example/sh-to-mod.sh} $mp/source-sh/1 2]
testouterr_cmd sh {load source-sh/1} ERR [msg_load source-sh/1 $tserr]


#
# empty script or duplicate source-sh calls
#

# test 'source-sh' script producing no output
unsetenv_var TESTSUITE_SHTOMOD_FUZZYOUT1
unsetenv_var TESTSUITE_SHTOMOD_PATHDUP
setenv_var TESTSUITE_SHTOMOD_NOVAR 1
setenv_var TESTSUITE_SHTOMOD_NOPATH 1
setenv_var TESTSUITE_SHTOMOD_NOALIAS 1
setenv_var TESTSUITE_SHTOMOD_NOFUNC 1
setenv_var TESTSUITE_SHTOMOD_NOCD 1
set ans [list]
lappend ans [list setpath LOADEDMODULES source-sh/1]
lappend ans [list setpath _LMFILES_ $mp/source-sh/1]
lappend ans [list setpath MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|]
testouterr_cmd sh {load source-sh/1} $ans {}
set ans [list]
lappend ans [list setpath LOADEDMODULES source-sh/1:source-sh/2]
lappend ans [list setpath _LMFILES_ $mp/source-sh/1:$mp/source-sh/2]
lappend ans [list setpath MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|:source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value]
lappend ans [list setpath FOOPATH /path/to/mini:]
lappend ans [list set FOOMINI value]
lappend ans [list alias almini echo\ mini]
testouterr_cmd_re sh {load source-sh/1 source-sh/2} $ans {}

setenv_loaded_module [list source-sh/1 source-sh/2] [list $mp/source-sh/1 $mp/source-sh/2]
setenv_path_var MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|:source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value
set ans [list]
lappend ans [list setpath LOADEDMODULES source-sh/2]
lappend ans [list setpath _LMFILES_ $mp/source-sh/2]
lappend ans [list setpath MODULES_LMSOURCESH source-sh/2\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value]
testouterr_cmd sh {unload source-sh/1} $ans {}

unsetenv_loaded_module
unsetenv_path_var MODULES_LMSOURCESH
unsetenv_var TESTSUITE_SHTOMOD_NOVAR

set ans [list]
lappend ans [list set FOOMINI value]
lappend ans [list set LOADEDMODULES source-sh/5.0]
lappend ans [list set _LMFILES_ $mp/source-sh/5.0]
lappend ans [list set FOOEM {}]
lappend ans [list set FOOSP {value }]
lappend ans [list set FOOARG1 arg1]
lappend ans [list set FOOCB va\{ue]
lappend ans [list set FOOPATH /path/to/mini:]
lappend ans [list set FOOPATH_modshare :1:/path/to/mini:1]
lappend ans [list set FOO value]
lappend ans [list set LOADEDMODULES_modshare source-sh/5.0:1]
lappend ans [list set _LMFILES__modshare $mp/source-sh/5.0:1]
lappend ans [list set MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1:1]
lappend ans [list alias almini echo\ mini]
testouterr_cmd sh {load source-sh/5.0} $ans {}

set ans [list]
lappend ans [list set FOOMINI value]
lappend ans [list set LOADEDMODULES source-sh/5.1]
lappend ans [list set _LMFILES_ $mp/source-sh/5.1]
lappend ans [list set FOOEM {}]
lappend ans [list set FOOARG1 arg1]
lappend ans [list set FOOSP {value }]
lappend ans [list set FOOARG2 arg2]
lappend ans [list set FOOCB va\{ue]
lappend ans [list set FOOPATH /path/to/mini:]
lappend ans [list set FOOPATH_modshare :1:/path/to/mini:1]
lappend ans [list set _LMFILES__modshare $mp/source-sh/5.1:1]
lappend ans [list set FOO value]
lappend ans [list set LOADEDMODULES_modshare source-sh/5.1:1]
lappend ans [list set MODULES_LMSOURCESH source-sh/5.1\&bash\ testsuite/example/sh-to-mod.sh\ arg1\ arg2\|setenv\ FOO\ value\|setenv\ FOOARG1\ arg1\|setenv\ FOOARG2\ arg2\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/5.1\&bash\ testsuite/example/sh-to-mod.sh\ arg1\ arg2\|setenv\ FOO\ value\|setenv\ FOOARG1\ arg1\|setenv\ FOOARG2\ arg2\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value:1]
lappend ans [list alias almini echo\ mini]
testouterr_cmd sh {load source-sh/5.1} $ans {}


#
# variable definition relying on a variable defined in sourced script
#

set tserr "-------------------------------------------------------------------
$mp/source-sh/6.0:

prepend-path	FOOPATH /path/to/mini {}
set-alias	almini {echo mini}
setenv		FOOMINI value
setenv		TS1 \$FOOMINI
setenv		TS2 value
module-whatis	source-sh/6.0
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/6.0} OK $tserr
if {[cmpversion $tclsh_version 8.5] == -1} {
    set msgtcl "can't read \"env(FOOMINI)\": no such variable
      while executing"
} else {
    set msgtcl "no such variable
      (read trace on \"env(FOOMINI)\")
      invoked from within"
}
set tserr "-------------------------------------------------------------------
Module Specific Help for $mp/source-sh/6.0:

Module ERROR: $msgtcl
  \"setenv TS2 \$env(FOOMINI)\"
      (file \"$mp/source-sh/6.0\" line 4)
  $err_contactns
-------------------------------------------------------------------"
testouterr_cmd sh {help source-sh/6.0} ERR $tserr
set tserr "-------------------------------------------------------------------
Module Specific Test for $mp/source-sh/6.0:

Module ERROR: $msgtcl
  \"setenv TS2 \$env(FOOMINI)\"
      (file \"$mp/source-sh/6.0\" line 4)
  $err_contactns
-------------------------------------------------------------------"
testouterr_cmd sh {test source-sh/6.0} ERR $tserr
testouterr_cmd sh {whatis source-sh/6.0} OK {}

# try evaluation with variable pre-defined
setenv_var FOOMINI value

set tserr "-------------------------------------------------------------------
$mp/source-sh/6.0:

prepend-path	FOOPATH /path/to/mini {}
set-alias	almini {echo mini}
setenv		TS1 \$FOOMINI
setenv		TS2 value
module-whatis	source-sh/6.0
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/6.0} OK $tserr
set tserr "-------------------------------------------------------------------
Module Specific Help for $mp/source-sh/6.0:

$warn_msgs: Unable to find ModulesHelp in $mp/source-sh/6.0.
-------------------------------------------------------------------"
testouterr_cmd sh {help source-sh/6.0} OK $tserr
set tserr "-------------------------------------------------------------------
Module Specific Test for $mp/source-sh/6.0:

$warn_msgs: Unable to find ModulesTest in $mp/source-sh/6.0.
-------------------------------------------------------------------"
testouterr_cmd sh {test source-sh/6.0} OK $tserr

set tserr "$modlin $mpre $modlin
\\s*source-sh/6.0: source-sh/6.0"
testouterr_cmd_re sh {whatis source-sh/6.0} OK $tserr

unsetenv_var FOOMINI


#
# inconsistent environment
#

# module loaded, but no MODULES_LMSOURCESH
setenv_loaded_module [list source-sh/1] [list $mp/source-sh/1]
setenv_path_var FOOPATHDUP "/path/to/dir1:/path/to/dir2:/path/to/dir3:/path/to dir4"
setenv_path_var FOOPATHEM :/path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_path_var FOOPATHCB /path/to/dir1:/path/to/d\{r2:/path/to/dir3
setenv_path_var FOOPATHDUPMIX ":/path/to/dir1:/path/to/dir1 /path/to/dir2 /path/to/dir1:/path/to/dir3"
setenv_path_var FOOPATH /path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_path_var FOOPATHDUPEM :/path/to/dir1:/path/to/dir2:/path/to/dir3
setenv_path_var FOOPATHDUPSP "/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to:dir4 /path/to/dir3"
setenv_var FOOPATHSP {/path/to/dir1 /path/to/dir2 /path/to/dir3}
setenv_var FOOEM {}
setenv_var FOOSP {value }
setenv_var FOOPATHDUPSPEM {/path/to/dir1 /path/to/dir1 /path/to/dir2 /path/to/dir1 /path/to/dir3 /path/to/dir3 }
setenv_var FOOCB va\{ue
setenv_var FOO value
setenv_var FOOPATHSPEM {/path/to/dir1 /path/to/dir2 /path/to/dir3 }

set ans [list]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]
testouterr_cmd sh {unload source-sh/1} $ans {}

# partial MODULES_LMSOURCESH
setenv_path_var MODULES_LMSOURCESH source-sh/1\&bash\ testsuite/example/sh-to-mod.sh\|chdir\ $mp\|prepend-path\ FOOPATH\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHCB\ /path/to/dir1\ /path/to/d\\\{r2\ /path/to/dir3\|prepend-path\ FOOPATHDUP\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \{/path/to\ dir4\}\|prepend-path\ FOOPATHDUPEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|prepend-path\ FOOPATHDUPMIX\ \{\}\ /path/to/dir1\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir1\}\ /path/to/dir3\|prepend-path\ FOOPATHDUPSP\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to\}\ \{dir4\ /path/to/dir3\}\|prepend-path\ FOOPATHEM\ \{\}\ /path/to/dir1\ /path/to/dir2\ /path/to/dir3\|set-alias\ alcb\ \{\}\|set-alias\ alem\ \{\}\|set-alias\ alsp\ \{\}\|set-function\ funccb\ \{\}\|set-function\ funcnl\ \{\}\|set-function\ funcsp\ \{\}\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOPATHDUPSPEM\ \{/path/to/dir1\ /path/to/dir1\ /path/to/dir2\ /path/to/dir1\ /path/to/dir3\ /path/to/dir3\ \}\|setenv\ FOOPATHSP\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\}\|setenv\ FOOPATHSPEM\ \{/path/to/dir1\ /path/to/dir2\ /path/to/dir3\ \}
set ans [list]
lappend ans [list unset FOOPATHCB_modshare]
lappend ans [list unset _LMFILES_]
lappend ans [list unset LOADEDMODULES]
lappend ans [list unset FOOPATHDUP]
lappend ans [list unset FOOPATHDUPMIX_modshare]
lappend ans [list unset FOOPATHEM]
lappend ans [list unset FOOPATHSP]
lappend ans [list unset FOOPATHEM_modshare]
lappend ans [list unset FOOEM]
lappend ans [list unset FOOPATHCB]
lappend ans [list unset FOOPATHDUPEM_modshare]
lappend ans [list unset FOOPATHDUPSPEM]
lappend ans [list unset FOOPATHDUPMIX]
lappend ans [list unset FOOCB]
lappend ans [list unset FOOPATH]
lappend ans [list unset FOOPATH_modshare]
lappend ans [list unset _LMFILES__modshare]
lappend ans [list unset LOADEDMODULES_modshare]
lappend ans [list unset FOO]
lappend ans [list unset FOOPATHDUP_modshare]
lappend ans [list unset FOOPATHDUPEM]
lappend ans [list unset MODULES_LMSOURCESH]
lappend ans [list unset FOOPATHDUPSP]
lappend ans [list unset FOOPATHSPEM]
lappend ans [list unset MODULES_LMSOURCESH_modshare]
lappend ans [list unset FOOPATHDUPSP_modshare]
lappend ans [list unalias alsp]
lappend ans [list unalias alcb]
lappend ans [list unalias alem]
lappend ans [list "unset -f funccb;"]
lappend ans [list "unset -f funcnl;"]
lappend ans [list "unset -f funcsp;"]
testouterr_cmd sh {unload source-sh/1} $ans {}

unsetenv_path_var MODULES_LMSOURCESH
unsetenv_path_var FOOPATHDUP
unsetenv_path_var FOOPATHEM
unsetenv_path_var FOOPATHCB
unsetenv_path_var FOOPATHDUPMIX
unsetenv_path_var FOOPATHDUPEM
unsetenv_path_var FOOPATHDUPSP
unsetenv_var FOOPATHSP
unsetenv_var FOOPATHDUPSPEM
unsetenv_var FOOPATHSPEM

# a LMSOURCESH entry with shtomodargs but no modcontent
setenv_loaded_module [list source-sh/5.0] [list $mp/source-sh/5.0]
setenv_var FOOMINI value
setenv_var FOOARG1 arg1
setenv_path_var FOOPATH /path/to/mini:
setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1

set ans [list]
lappend ans [list unset _LMFILES__modshare]
lappend ans [list unset LOADEDMODULES_modshare]
# re-serialized entry of MODULES_LMSOURCESH is not equal to the one recorded in environment, so variable is not unset
lappend ans [list set MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1]
lappend ans [list unset FOOMINI]
lappend ans [list unset FOOPATH]
lappend ans [list unset _LMFILES_]
lappend ans [list unset LOADEDMODULES]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1:1]
lappend ans [list unset FOOARG1]
lappend ans [list unset FOOPATH_modshare]
lappend ans [list unalias almini]
testouterr_cmd sh {unload source-sh/5.0} $ans {}

setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1
set ans [list]
lappend ans [list unset _LMFILES__modshare]
lappend ans [list unset LOADEDMODULES_modshare]
lappend ans [list unset MODULES_LMSOURCESH]
lappend ans [list unset FOOMINI]
lappend ans [list unset FOOPATH]
lappend ans [list unset _LMFILES_]
lappend ans [list unset LOADEDMODULES]
lappend ans [list unset MODULES_LMSOURCESH_modshare]
lappend ans [list unset FOOARG1]
lappend ans [list unset FOOPATH_modshare]
lappend ans [list unalias almini]
testouterr_cmd sh {unload source-sh/5.0} $ans {}

# bad modulefile command call in MODULES_LMSOURCESH (missing alias body arg)
setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1
set ans [list]
lappend ans [list unset _LMFILES__modshare]
lappend ans [list unset LOADEDMODULES_modshare]
# value set-alias and set-function is rewritten when parsed
lappend ans [list set MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1]
lappend ans [list unset FOOMINI]
lappend ans [list unset FOOPATH]
lappend ans [list unset _LMFILES_]
lappend ans [list unset LOADEDMODULES]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1:1]
lappend ans [list unset FOOARG1]
lappend ans [list unset FOOPATH_modshare]
lappend ans [list unalias almini]
testouterr_cmd sh {unload source-sh/5.0} $ans {}

# bad modulefile command call in MODULES_LMSOURCESH (missing alias name and body args)
setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1
set msgtcl [expr {[cmpversion $tclsh_version 8.5] == -1 ? {-un} : {}}]
set tserr "$moderr_msgs: wrong # args: should be \"set-alias$msgtcl alias what\"
    invoked from within
\"set-alias {}\"
    invoked from within
\"interp eval \$itrp \$modcmd\"
    (procedure \"source-sh-un\" line 17)
    invoked from within
\"source-sh sh testsuite/example/mini-sh-to-mod.sh\"
    (file \"$mp/source-sh/5.0\" line 3)
$err_contactns"
testouterr_cmd sh {unload source-sh/5.0} ERR [msg_unload source-sh/5.0 $tserr]

# bad modulefile command call in MODULES_LMSOURCESH (missing variable value arg)
setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1
set tserr "$moderr_msgs: wrong # args: should be \"setenv$msgtcl var val\"
    invoked from within
\"setenv FOOARG1\"
    invoked from within
\"interp eval \$itrp \$modcmd\"
    (procedure \"source-sh-un\" line 17)
    invoked from within
\"source-sh bash testsuite/example/sh-to-mod.sh arg1\"
    (file \"$mp/source-sh/5.0\" line 4)
$err_contactns"
testouterr_cmd sh {unload source-sh/5.0} ERR [msg_unload source-sh/5.0 $tserr]

# unknown modulefile command in MODULES_LMSOURCESH
setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-foo\ almini\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1
set tserr "$moderr_msgs: invalid command name \"set-foo\"
    while executing
\"set-foo almini\"
    invoked from within
\"interp eval \$itrp \$modcmd\"
    (procedure \"source-sh-un\" line 17)
    invoked from within
\"source-sh sh testsuite/example/mini-sh-to-mod.sh\"
    (file \"$mp/source-sh/5.0\" line 3)
$err_contactns"
testouterr_cmd sh {unload source-sh/5.0} ERR [msg_unload source-sh/5.0 $tserr]

# alias and function defined in MODULES_LMSOURCESH but not in script when modulefile is displayed
setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOPATH\ /path/to/mini\ \{\}\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1|set-alias\ alunk\ \{\}\|set-function\ funcunk\ \{\}
set tserr_disp3 "-------------------------------------------------------------------
$mp/source-sh/5.0:

setenv		FOO value
setenv		FOOCB va{ue
setenv		FOOEM {}
setenv		FOOSP {value }
prepend-path	FOOPATH /path/to/mini {}
set-alias	almini {echo mini}
setenv		FOOMINI value
setenv		FOOARG1 arg1
set-alias	alunk {}
set-function	funcunk {}
-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/5.0} OK $tserr_disp3

# clear source-sh details recorded in env yet module is still loaded
unsetenv_path_var MODULES_LMSOURCESH
set tserr_disp3 "-------------------------------------------------------------------
$mp/source-sh/5.0:

-------------------------------------------------------------------"
testouterr_cmd sh {display source-sh/5.0} OK $tserr_disp3


unsetenv_loaded_module
unsetenv_path_var FOOPATH
unsetenv_var FOOEM
unsetenv_var FOOSP
unsetenv_var FOO
unsetenv_var FOOMINI
unsetenv_var FOOARG1
unsetenv_var FOOCB


#
# escaping special chars
#

setenv_var TESTSUITE_SOURCESH_ESCCHAR 1

set ans [list]
lappend ans [list set FOOESC_modshare :1]
lappend ans [list set FOOMINI value]
lappend ans [list set _LMFILES_ $mp/source-sh/5.0]
lappend ans [list set LOADEDMODULES source-sh/5.0]
lappend ans [list set FOOEM {}]
lappend ans [list set FOOSP {value }]
lappend ans [list set FOOARG1 arg1]
lappend ans [list set FOOCB va\{ue]
lappend ans [list set FOOPATH /path/\{\|:/path/to/mini::/path/\}\&]
lappend ans [list set FOOPATH_modshare :1:/path/\{\|:1:/path/to/mini:1:/path/\}\&:1]
lappend ans [list set _LMFILES__modshare $mp/source-sh/5.0:1]
lappend ans [list set FOO value]
lappend ans [list set LOADEDMODULES_modshare source-sh/5.0:1]
lappend ans [list set MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOESC\ \{\}\|prepend-path\ FOOPATH\ /path/\\\{\<EnvModEscS2\>\ /path/to/mini\ \{\}\ /path/\\\}\<EnvModEscS1\>\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1]
lappend ans [list set MODULES_LMSOURCESH_modshare source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOESC\ \{\}\|prepend-path\ FOOPATH\ /path/\\\{\<EnvModEscS2\>\ /path/to/mini\ \{\}\ /path/\\\}\<EnvModEscS1\>\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1:1]
lappend ans [list set FOOESC {}]
lappend ans [list alias almini echo\ mini]
testouterr_cmd sh {load source-sh/5.0} $ans {}

setenv_loaded_module [list source-sh/5.0] [list $mp/source-sh/5.0]
setenv_var FOOMINI value
setenv_var FOOEM {}
setenv_var FOOSP {value }
setenv_var FOOARG1 arg1
setenv_var FOOCB va\{ue
setenv_path_var FOOPATH /path/\{\|:/path/to/mini::/path/\}\&
setenv_var FOO value
setenv_path_var MODULES_LMSOURCESH source-sh/5.0\&bash\ testsuite/example/sh-to-mod.sh\|setenv\ FOO\ value\|setenv\ FOOCB\ va\\\{ue\|setenv\ FOOEM\ \{\}\|setenv\ FOOSP\ \{value\ \}\&sh\ testsuite/example/mini-sh-to-mod.sh\|prepend-path\ FOOESC\ \{\}\|prepend-path\ FOOPATH\ /path/\\\{\<EnvModEscS2\>\ /path/to/mini\ \{\}\ /path/\\\}\<EnvModEscS1\>\|set-alias\ almini\ \{\}\|setenv\ FOOMINI\ value\&bash\ testsuite/example/sh-to-mod.sh\ arg1\|setenv\ FOOARG1\ arg1
setenv_path_var FOOESC {}
set ans [list]
lappend ans [list unset FOOESC_modshare]
lappend ans [list unset FOOMINI]
lappend ans [list unset _LMFILES_]
lappend ans [list unset LOADEDMODULES]
lappend ans [list unset FOOEM]
lappend ans [list unset FOOSP]
lappend ans [list unset FOOARG1]
lappend ans [list unset FOOCB]
lappend ans [list unset FOOPATH]
lappend ans [list unset FOOPATH_modshare]
lappend ans [list unset _LMFILES__modshare]
lappend ans [list unset FOO]
lappend ans [list unset LOADEDMODULES_modshare]
lappend ans [list unset MODULES_LMSOURCESH]
lappend ans [list unset MODULES_LMSOURCESH_modshare]
lappend ans [list unset FOOESC]
lappend ans [list unalias almini]
testouterr_cmd sh {unload source-sh/5.0} $ans {}

unsetenv_loaded_module
unsetenv_var FOOMINI
unsetenv_var FOOEM
unsetenv_var FOOSP
unsetenv_var FOOARG1
unsetenv_var FOOCB
unsetenv_path_var FOOPATH
unsetenv_var FOO
unsetenv_path_var MODULES_LMSOURCESH
unsetenv_path_var FOOESC


#
#  Cleanup
#

reset_test_env
