############################################################################## # Modules Revision 3.0 # Providing a flexible user environment # # File: modules.00-init/%M% # Revision: %I% # First Edition: 2018/02/22 # Last Mod.: %U%, %G% # # Authors: Xavier Delaruelle, xavier.delaruelle@cea.fr # # Description: Testuite testsequence # Command: # Sub-Command: # # Comment: %C{ # Checks commands when stderr is attached to a TTY # }C% # ############################################################################## # activate potential siteconfig extension if {$verbose} { send_user "\tSetup TESTSUITE_ENABLE_SITECONFIG = '1'\n" } set env(TESTSUITE_ENABLE_SITECONFIG) 1 # check if stderr terminal attachment state is forced set is_stderr_tty [siteconfig_isStderrTty] if {$verbose} { send_user "\tIs STDERR a TTY? = '$is_stderr_tty'\n" } # test only if stderr is attached to TTY if {$is_stderr_tty} { if {$verbose} { send_user "\tChecking basic set of commands when STDERR is attached to TTY\n" } set bad_cmd "$error_msgs: Invalid command 'foo'" set bad_cmd_re "(envmodule: )?$bad_cmd" foreach shell $shell_list { switch -- $shell { {csh} - {tcsh} { testall_cmd_re "$shell" "module --version" "" "Modules Release \\S+ (\\S+)" 0 testall_cmd "$shell" "module foo" "" "$bad_cmd\n$type_help" 1 testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module list -t" "" "$cur_loaded\nnull" 0 testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module unload null\; module list -t" "" "$no_loaded" 0 testall_cmd "$shell" "module is-loaded unk" "" "" 1 testall_cmd "$shell" "module use $share_modpath\; module load null\; module is-loaded null" "" "" 0 testall_cmd "$shell" "module info-loaded unk" "" "" 0 testall_cmd "$shell" "module use $share_modpath\; module load null\; module info-loaded null" "null" "" 0 } default { testall_cmd_re "$shell" "module --version" "Modules Release \\S+ (\\S+)" "" 0 testall_cmd "$shell" "module foo" "$bad_cmd\n$type_help" "" 1 testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module list -t" "$cur_loaded\nnull" "" 0 testall_cmd "$shell" "module use $share_modpath\; module purge\; module load null\; module unload null\; module list -t" "$no_loaded" "" 0 testall_cmd "$shell" "module is-loaded unk" "" "" 1 testall_cmd "$shell" "module use $share_modpath\; module load null\; module is-loaded null" "" "" 0 testall_cmd "$shell" "module info-loaded unk" "" "" 0 testall_cmd "$shell" "module use $share_modpath\; module load null\; module info-loaded null" "null" "" 0 } } } foreach shell $othlang_list { switch -- $shell { pwsh { testall_cmd_re "$shell" "--version" "Modules Release \\S+ (\\S+)" "" 0 testall_cmd "$shell" "use,$share_modpath:purge:load,null:list,-t" "$cur_loaded\nnull" "" 0 testall_cmd "$shell" "use,$share_modpath:purge:load,null:unload,null:list,-t" "$no_loaded" "" 0 } default { testall_cmd_re "$shell" "--version" "" "Modules Release \\S+ (\\S+)" 0 testall_cmd "$shell" "use,$share_modpath:purge:load,null:list,-t" "" "$cur_loaded\nnull" 0 testall_cmd "$shell" "use,$share_modpath:purge:load,null:unload,null:list,-t" "" "$no_loaded" 0 } } testall_cmd_re "$shell" "foo" "" "$bad_cmd_re\n$type_help.*" 1 switch -- $shell { cmake - r { testall_cmd_re "$shell" "is-loaded,unk" "" ".*" 1 } default { testall_cmd_re "$shell" "is-loaded,unk" "" "" 1 } } testall_cmd "$shell" "use,$share_modpath:load,null:is-loaded,null" "" "" 0 switch -- $shell { r { testall_cmd "$shell" "info-loaded,unk" "\[1\] \"\"" {} 0 } python - ruby { testall_cmd "$shell" "info-loaded,unk" "\n" "" 0 } default { testall_cmd "$shell" "info-loaded,unk" "" "" 0 } } switch -- $shell { {cmake} { set anstxt "-- null" } {r} { set anstxt "\[1\] \"null\"" } default { set anstxt "null" } } testall_cmd "$shell" "use,$share_modpath:load,null:info-loaded,null" $anstxt "" 0 } # set a directory with name starting by '$' to check if shell arguments are correctly escaped set disruptive_dir1 "[pwd]/\$RE.BIN" set disruptive_dir2 "[pwd]/something (test)" if {$verbose} { send_user "\tCreate disruptive directory $disruptive_dir1\n" send_user "\tCreate disruptive directory $disruptive_dir2\n" } file mkdir $disruptive_dir1 file mkdir $disruptive_dir2 foreach shell $shell_list { switch -- $shell { {csh} - {tcsh} { testall_cmd_re "$shell" "module --version" "" "Modules Release \\S+ (\\S+)" 0 } default { testall_cmd_re "$shell" "module --version" "Modules Release \\S+ (\\S+)" "" 0 } } } foreach shell $othlang_list { switch -- $shell { pwsh { testall_cmd_re "$shell" "--version" "Modules Release \\S+ (\\S+)" "" 0 } default { testall_cmd_re "$shell" "--version" "" "Modules Release \\S+ (\\S+)" 0 } } } if {$verbose} { send_user "\tDelete disruptive directory $disruptive_dir1\n" send_user "\tDelete disruptive directory $disruptive_dir2\n" } file delete $disruptive_dir1 file delete $disruptive_dir2 } elseif {$verbose} { send_user "\tSkip most tests as STDERR is not attached to a TTY\n" } # test output redirection when shell is found or not attached to tty set tserr "Modules Release \\S+ (\\S+)" if {$is_stderr_tty} { set dflout $tserr set dflerr {} } else { set dflout {} set dflerr $tserr } foreach shell $shell_redir_list { set modcmd "module" if {$shell eq "pwsh"} { set modcmd "envmodule" } testall_cmd_re $shell "$modcmd --version" $dflout $dflerr 0 testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 if {$shell ne "pwsh"} { testall_cmd_re autoinit:$shell "$modcmd --version" $dflout $dflerr 0 testall_cmd_re autoinit:$shell "$modcmd --version --redirect" $tserr {} 0 testall_cmd_re autoinit:$shell "$modcmd --version --no-redirect" {} $tserr 0 } # if --no-redirect is part of arg list it wins even if --redirect is set after testall_cmd_re $shell "$modcmd --version --redirect --no-redirect" {} $tserr 0 testall_cmd_re $shell "$modcmd --version --no-redirect --redirect" {} $tserr 0 setenv_var MODULES_REDIRECT_OUTPUT 0 testall_cmd_re $shell "$modcmd --version" {} $tserr 0 testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 testall_cmd_re $shell "$modcmd --version --redirect --no-redirect" {} $tserr 0 testall_cmd_re $shell "$modcmd --version --no-redirect --redirect" {} $tserr 0 setenv_var MODULES_REDIRECT_OUTPUT 1 testall_cmd_re $shell "$modcmd --version" $tserr {} 0 testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 testall_cmd_re $shell "$modcmd --version --redirect --no-redirect" {} $tserr 0 testall_cmd_re $shell "$modcmd --version --no-redirect --redirect" {} $tserr 0 # bad value set on MODULES_REDIRECT_OUTPUT env var # any value different than 0 or 1 is ignored setenv_var MODULES_REDIRECT_OUTPUT foo testall_cmd_re $shell "$modcmd --version" $dflout $dflerr 0 testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 setenv_var MODULES_REDIRECT_OUTPUT {} testall_cmd_re $shell "$modcmd --version" $dflout $dflerr 0 testall_cmd_re $shell "$modcmd --version --redirect" $tserr {} 0 testall_cmd_re $shell "$modcmd --version --no-redirect" {} $tserr 0 unsetenv_var MODULES_REDIRECT_OUTPUT } # # Clean up variables used in this test case # reset_test_env