##############################################################################
#   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:		load
#   Modulefiles:	prepend/1.0
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'prepend-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_3 $ts_1 $ts_2"
# test colon char is correctly escaped in _modshare var
set tsmod_new "http\\://foobar.com:1:http\\://foobar.net:1:http\\://foobar.org:1"
set env(testsuite)	"$ts_1 $ts_2"
set env(testsuite_modshare)	"http\\://foobar.org:1:http\\://foobar.net:1"
set module "prepend/1.0"
set modulefile "$modpath/$module"

#
#  For the different shells ...
#

lappend ans [list set testsuite_modshare $tsmod_new]
lappend ans [list set testsuite $ts_new]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]

#
#  The tests
#

test_cmd_re "ALL" "load $module" $ans

#
# Test the --delim=C argument form
#

set ts_new "$ts_3,$ts_1,$ts_2"
set env(testsuite)	"$ts_1,$ts_2"
set module "prepend/1.7"
set modulefile "$modpath/$module"

set ans [list]
lappend ans [list set testsuite_modshare $tsmod_new]
lappend ans [list set testsuite $ts_new]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]

test_cmd_re "sh" "load $module" $ans

#
# Try bad argument list: missing variable name
#

set module "prepend/1.3"
set modulefile "$modpath/$module"
set ts_err [msg_moderr "add-path $msg_needenvvarname" {prepend-path -d : } $modulefile 24]
testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $ts_err]

#
# Try bad argument list: missing variable value
#

set module "prepend/1.4"
set modulefile "$modpath/$module"
set ts_err [msg_moderr "add-path $msg_needenvvarval PATH" {prepend-path -d : PATH} $modulefile 24]
testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $ts_err]

#
# Try bad argument list: empty variable name
#

set module "prepend/1.5"
set modulefile "$modpath/$module"
set ts_err [msg_moderr "add-path $msg_validenvvarname" {prepend-path -d : {}} $modulefile 24]
testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $ts_err]

#
# Try bad argument list: empty delimiter value
#

set module "prepend/1.6"
set modulefile "$modpath/$module"
set ts_err [msg_moderr "add-path $msg_nonemptydelim" {prepend-path --delim= PATH /path/to} $modulefile 24]
testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $ts_err]

#
# Prepend multiple paths passed as one string
#

set module "prepend/1.8"
set modulefile "$modpath/$module"
set ts_new " http://foobar.io $ts_3 $ts_1 $ts_2"
set tsmod_new ":1:http\\://foobar.com:1:http\\://foobar.net:1:http\\://foobar.io:1:http\\://foobar.org:1"

set env(testsuite) "$ts_1 $ts_2"
set env(testsuite_modshare) "http\\://foobar.org:1:http\\://foobar.net:1"

set ans [list]
lappend ans [list set testsuite_modshare $tsmod_new]
lappend ans [list set testsuite $ts_new]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]

testouterr_cmd_re "sh" "load $module" $ans ""

#
# Prepend multiple paths passed as multiple strings
#

set module "prepend/1.9"
set modulefile "$modpath/$module"

set ans [list]
lappend ans [list set testsuite_modshare $tsmod_new]
lappend ans [list set testsuite $ts_new]
lappend ans [list setpath LOADEDMODULES $module]
lappend ans [list setpath _LMFILES_ $modulefile]

testouterr_cmd_re "sh" "load $module" $ans ""

#
# Try pass invalid option to prepend-path
#

set module prepend/8.0
set modulefile $modpath/$module
set ts_err [msg_moderr {invalid option '-delim=,' for add-path} {prepend-path -delim=, FOO bar} $modulefile 2]
testouterr_cmd sh "load $module" ERR [msg_load $module $ts_err]

#
#  Cleanup
#

reset_test_env
