##############################################################################
#   Modules Release Tcl
#   Providing a flexible user environment
#
#   File:		modules.61-coll/%M%
#   Revision:		%I%
#   First Edition:	2016/08/09
#   Last Mod.:		%U%, %G%
#
#   Authors:		Xavier Delaruelle, xavier.delaruelle@cea.fr
#
#   Description:	Testuite testsequence
#   Command:
#   Modulefiles:
#   Sub-Command:
#
#   Comment:	%C{
#			Test the module 'saverm' command
#		}C%
#
##############################################################################


set cbadnerrmsg "$error_msgs: Collection $collbadn cannot be found"
set cbadterrmsg "$error_msgs: Collection $colld (for target \"$colltarget\") cannot be found"
set c1fperrmsg "$error_msgs: Command does not remove collection specified as filepath"
set rmcderrmsg "couldn't open \"$hometestdotmod/default\": no such file or directory"
set rmc1errmsg "couldn't open \"$hometestdotmod/$coll1\": no such file or directory"
set rmc4ferrmsg "couldn't open \"$hometestdotmod/$coll4f\": no such file or directory"

#
# test removing nonexistent collection
#

# set home to directory where collections have been
# recorded during the 030-save tests. try the saverm
# command on these tests collections.
if { $verbose > 0 } {
    send_user "\tSetup HOME = $hometestcoll\n"
}
set env(HOME) "$hometestcoll"

testouterr_cmd "ALL" "saverm $collbadn" "ERR" "$cbadnerrmsg"


#
# test removing default collection
#

# test only sh shell as this test does not produce shell output
testoutfile_cmd "sh" "saverm" "OK" "$hometestdotmod/default" "$rmcderrmsg"


#
# test removing named collection
#

# test only sh shell as this test does not produce shell output
testoutfile_cmd "sh" "saverm $coll1" "OK" "$hometestdotmod/$coll1" "$rmc1errmsg"


#
# test removing collection specified as filepath
# should raise an error, saverm is not made to delete filepath
#

testouterr_cmd "ALL" "saverm $coll1fp" "ERR" "$c1fperrmsg"


#
# test removing named collection when MODULES_COLLECTION_TARGET is set
#

# setup environment state
if { $verbose > 0 } {
    send_user "\tSetup MODULES_COLLECTION_TARGET = $colltarget\n"
}
set env(MODULES_COLLECTION_TARGET) "$colltarget"

# test only sh shell as this test does not produce shell output
testoutfile_cmd "sh" "saverm $coll4" "OK" "$hometestdotmod/$coll4f" "$rmc4ferrmsg"


#
# test removing nonexistent default collection when
# MODULES_COLLECTION_TARGET is set
#

testouterr_cmd "ALL" "saverm" "ERR" "$cbadterrmsg"


#
# test unsetting HOME
#

if { $verbose > 0 } {
    send_user "\tUnset HOME \n"
}
unset env(HOME)

testouterr_cmd "sh" "saverm" "ERR" $nohomeerrmsg


#
# Cleanup
#

reset_test_env
