##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2017/11/25
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:		load
#   Modulefiles:    modbad
#   Sub-Command:
#
#   Comment:	%C{
#			Tests 'module' sub-commands that cannot be called
#           outside of command line
#		}C%
#
##############################################################################


foreach subcmd [list append-path prepend-path remove-path autoinit help is-loaded is-saved is-used is-avail path paths info-loaded clear config sh-to-mod edit] {
    set module "modbad/$subcmd"
    set modulefile "$modpath/$module"
    set modulefilere "$modpathre/$module"

    switch -- $subcmd {
        {append-path} - {prepend-path} - {remove-path} {
            set subcmdargs " FOO bar"
        }
        {is-loaded} - {is-saved} - {is-used} - {is-avail} - {info-loaded} - {path} - {paths} {
            set subcmdargs " bar"
        }
        default {
            set subcmdargs ""
        }
    }
    if {$subcmd eq {config} || [cmpversion $tclsh_version 8.5] != -1} {
        set moderr [msg_moderr "module: Command '$subcmd' not supported" "module $subcmd$subcmdargs" $modulefile 27]
        testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $moderr]
    } else {
        set moderr [msg_moderr "module: Command '$subcmd' not supported" "<EXM>module $subcmd$subcmdargs" $modulefile 27]
        testouterr_cmd_re "sh" "load $module" "ERR" [escre [msg_load $module $moderr]]
    }

    # no subcommand check on display, so no error
    testouterr_cmd_re "sh" "display $module" "OK" "$modlin\n$modulefilere:\n\nmodule\t\t$subcmd$subcmdargs\nmodule\t\thelp\n$modlin"
}

set module "modbad/foo"
set modulefile "$modpath/$module"
set modulefilere "$modpathre/$module"
set moderr [msg_moderr {module: Invalid command 'foo'} {module foo} $modulefile 27]

testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $moderr]
testouterr_cmd_re "sh" "display $module" "OK" "$modlin\n$modulefilere:\n\nmodule\t\tfoo\nmodule\t\thelp\n$modlin"

set module "modbad/empty"
set modulefile "$modpath/$module"
set modulefilere "$modpathre/$module"

if {[cmpversion $tclsh_version 8.5] == -1} {
    set moderr [msg_moderr {module: Command 'help' not supported} "<EXM>module {}" $modulefile 27]
    testouterr_cmd_re "sh" "load $module" "ERR" [escre [msg_load $module $moderr]]
} else {
    set moderr [msg_moderr {module: Command 'help' not supported} "module {}" $modulefile 27]
    testouterr_cmd "sh" "load $module" "ERR" [msg_load $module $moderr]
}

testouterr_cmd_re "sh" "display $module" "OK" "$modlin\n$modulefilere:\n\nmodule\t\t{}\nmodule\t\thelp\n$modlin"


#
#  Cleanup
#

reset_test_env
