##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2006/06/01
#   Last Mod.:		%U%, %G%
#
#   Authors:		R.K. Owen, <rk@owen.sj.ca.us>
#
#   Description:	Testuite testsequence
#   Command:		unload
#   Modulefiles:	append/1.0
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the reverse 'append-path' module subcommand with
#			an arbitrary delimiter
#		}C%
#
##############################################################################

#
#  Variables. This test forces a module load command. It will result in the
#    environment variables "_LMFILES_", "LOADEDMODULES" and "testsuite" to
#    be set up
#

set ts_1 "http://foobar.org"
set ts_2 "http://foobar.net"
set ts_3 "http://foobar.com"
set ts_new "$ts_1 $ts_2"
# test colon char is correctly escaped in _modshare var
set tsmod_new "http\\://foobar.net:1:http\\://foobar.org:1"
set module "append/1.0"
set modulefile "$modpath/$module"

#
# Set up the environment for reversal ...
#

set env(testsuite) "$ts_1 $ts_2 $ts_3"
set env(testsuite_modshare)	"http\\://foobar.com:1:http\\://foobar.org:1:http\\://foobar.net:1"
setenv_loaded_module $module $modulefile

#
#  For the different shells ...
#

lappend ans [list set testsuite_modshare $tsmod_new]
lappend ans [list set testsuite $ts_new]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]

#
#  The tests
#

test_cmd_re "ALL" "unload $module" $ans

#
# Try bad argument list: missing variable name
#

set module "append/1.3"
set modulefile "$modpath/$module"
setenv_loaded_module $module $modulefile
set ts_err [msg_moderr "unload-path $msg_needenvvarname" {append-path -d : } $modulefile 24]
testouterr_cmd "sh" "unload $module" "ERR" [msg_unload $module $ts_err]

#
# Try bad argument list: missing variable value
#

set module "append/1.4"
set modulefile "$modpath/$module"
setenv_loaded_module $module $modulefile
set ts_err [msg_moderr "unload-path $msg_needenvvarval PATH" {append-path -d : PATH} $modulefile 24]
testouterr_cmd "sh" "unload $module" "ERR" [msg_unload $module $ts_err]

#
# Try bad argument list: empty variable name
#

set module "append/1.5"
set modulefile "$modpath/$module"
setenv_loaded_module $module $modulefile
set ts_err [msg_moderr "unload-path $msg_validenvvarname" {append-path -d : {} /path/to} $modulefile 24]
testouterr_cmd "sh" "unload $module" "ERR" [msg_unload $module $ts_err]

#
# Append multiple paths passed as one string
#

set module "append/1.6"
set modulefile "$modpath/$module"

set env(testsuite) "$ts_1 $ts_2 $ts_3 http://foobar.io "
set env(testsuite_modshare) ":1:http\\://foobar.com:1:http\\://foobar.net:1:http\\://foobar.io:1:http\\://foobar.org:1"
setenv_loaded_module $module $modulefile

set ans [list]
lappend ans [list set testsuite_modshare $tsmod_new]
lappend ans [list set testsuite $ts_new]
lappend ans [list unsetpath LOADEDMODULES]
lappend ans [list unsetpath _LMFILES_]

testouterr_cmd_re "sh" "unload $module" $ans ""

#
# Append multiple paths passed as multiple strings
#

set module "append/1.7"
set modulefile "$modpath/$module"

setenv_loaded_module $module $modulefile

testouterr_cmd_re "sh" "unload $module" $ans ""

#
# Try pass invalid option to append-path
#

set module append/8.0
set modulefile $modpath/$module
setenv_loaded_module $module $modulefile
set ts_err [msg_moderr {invalid option '-delim=,' for unload-path} {append-path -delim=, FOO bar} $modulefile 2]
testouterr_cmd sh "unload $module" ERR [msg_unload $module $ts_err]

#
#  Cleanup
#

reset_test_env
