##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.70-maint/%M%
#   Revision:		%I%
#   First Edition:	95/12/06
#   Last Mod.:		%U%, %G%
#
#   Authors:		Jens Hamisch, Jens.Hamisch@Strawberry.COM
#
#   Description:	Testuite testsequence
#   Command:		load
#   Modulefiles:	whatis/lines, whatis/multiple, whatis/none
#   Modulefiles:	whatis/single, whatis/string, bad
#   Sub-Command:
#
#   Comment:	%C{
#			Tests the 'module whatis' command for success
#			Tests the 'module whatis' command for failure
#		}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 header "$modlin $modpathre $modlin"

set module_1 "whatis/none"
set module_2 "whatis/single"
set module_3 "whatis/multiple"
set module_4 "whatis/string"
set module_5 "whatis/lines"
set module_6 "NonExistant"
set module_7 "bad"

set whatis_2 "       whatis/single"
set whatis_3 "     whatis/multiple"
set whatis_4 "       whatis/string"
set whatis_5 "        whatis/lines"
set whatis_7 "           bad/after"

#
#  Test only for the csh
#

set ts_csh_1 ""
set ts_csh_2 "$header\n$whatis_2: Testsuite-Modulefile"
# different behavior than C-version: on Tcl-version multiple arguments provided on a single
# module-whatis call produce a single module-whatis line, not one line per passed argument
set ts_csh_3 "$header\n$whatis_3: Testsuite Whatis Modulefile"
set ts_csh_4 "$header\n$whatis_4: Testsuite Whatis Modulefile"
set ts_csh_5 "$header\n$whatis_5: Testsuite Whatis Modulefile\n$whatis_5: Second line of whatis tokens"
set ts_csh_6 "$err_path'$module_6'"
set ts_csh_7 "$header\n$whatis_7: erroneous module test"

#
#  The tests
#

testouterr_cmd_re "csh" "--terse whatis $module_1" "OK" "$ts_csh_1"
testouterr_cmd_re "csh" "--terse whatis $module_2" "OK" "$ts_csh_2"
testouterr_cmd_re "csh" "--terse whatis $module_3" "OK" "$ts_csh_3"
testouterr_cmd_re "csh" "--terse whatis $module_4" "OK" "$ts_csh_4"
testouterr_cmd_re "csh" "--terse whatis $module_5" "OK" "$ts_csh_5"

# command nickname tests
testouterr_cmd_re "csh" "--terse wh $module_5" "OK" "$ts_csh_5"

# setup MODULEPATH with a trailing slash and an empty dir element
setenv_path_var MODULEPATH {} "$modpath/"
testouterr_cmd_re "csh" "--terse whatis $module_1" "OK" "$ts_csh_1"

# restore MODULEPATH
setenv_path_var MODULEPATH $modpath


#
# the fail case, return value false
#
testouterr_cmd "csh" "whatis $module_6" "ERR" "$ts_csh_6"


#
# test with erroneous modulefile
# should not produce error message
#
testouterr_cmd_re "csh" "whatis $module_7" "OK" "$ts_csh_7"


#
# test when loaded environment is inconsistent
#

setenv_loaded_module [list foo bar] "/path/to/foo"

# should not affect result
testouterr_cmd_re "csh" "--terse whatis $module_5" "OK" "$ts_csh_5"


#
#  Cleanup
#

reset_test_env
