Debian Codegraph @

testsuite/modules.50-cmds/390-function.exp

raw
1 ##############################################################################
2 # Modules Revision 3.0
3 # Providing a flexible user environment
4 #
5 # File: modules.50-cmds/%M%
6 # Revision: %I%
7 # First Edition: 2018/10/14
8 # Last Mod.: %U%, %G%
9 #
10 # Authors: nanobowers <[email protected]>
11 #
12 # Description: Testsuite testsequence
13 # Command: load
14 # Modulefiles: function/1.0 function/2.0
15 # Sub-Command:
16 #
17 # Comment: %C{
18 # Tests 'set-function' command
19 # }C%
20 #
21 ##############################################################################
22
23 # ensure auto symbolic versions are not set for these tests
24 setenv_var MODULES_ADVANCED_VERSION_SPEC 0
25
26 #
27 # Variables. This test forces a module load command. It will result in the
28 # environment variables "_LMFILES_", "LOADEDMODULES" and "testsuite" to
29 # be set up
30 #
31
32 set module "function/1.0"
33 set modulefile "$modpath/$module"
34
35 # strictly speaking, this function is only valid for sh shells, not fish
36 set function_sh {eval $(echo cd $1)}
37 set function2_sh {echo $1}
38 set function3_sh {echo $1
39 echo $2}
40 set function_fish {eval (echo cd $argv[1])}
41 set function2_fish {echo $argv[1]}
42 set function3_fish {echo $argv[1]
43 echo $argv[2]}
44 set function_pwsh {Param([Parameter(Mandatory=$true, Position=0)] [string] $arg1); Invoke-Expression (echo cd $arg1)}
45 set function2_pwsh {Param([Parameter(Mandatory=$true, Position=0)] [string] $arg1); echo $arg1}
46 set function3_pwsh {Param(
47 [Parameter(Mandatory=$true, Position=0)] [string] $arg1,
48 [Parameter(Mandatory=$true, Position=1)] [string] $arg2
49 )
50 echo $arg1
51 echo $arg2}
52
53 #
54 # For the different shells ...
55 #
56
57 #lappend ans_empty [list function testsuite $function]
58 lappend ans_empty [list set __MODULES_LMREFRESH $module]
59 lappend ans_empty [list set _LMFILES_ $modulefile]
60 lappend ans_empty [list set LOADEDMODULES $module]
61
62 lappend ans_sh [list set __MODULES_LMREFRESH $module]
63 lappend ans_sh [list set _LMFILES_ $modulefile]
64 lappend ans_sh [list set LOADEDMODULES $module]
65 lappend ans_sh [list testsuite2 "() {" "$function2_sh; };"]
66 lappend ans_sh [list testsuite3 "() {" "$function2_sh; };"]
67 lappend ans_sh [list testsuite4 "() {" "$function2_sh; };"]
68 lappend ans_sh [list testsuite "() {" "$function_sh; };"]
69 lappend ans_sh [list testsuite5 "() {" "$function3_sh; };"]
70
71 lappend ans_bash [list set __MODULES_LMREFRESH $module]
72 lappend ans_bash [list set _LMFILES_ $modulefile]
73 lappend ans_bash [list set LOADEDMODULES $module]
74 lappend ans_bash [list testsuite2 "() {" "$function2_sh; };" "export -f testsuite2;"]
75 lappend ans_bash [list testsuite3 "() {" "$function2_sh; };" "export -f testsuite3;"]
76 lappend ans_bash [list testsuite4 "() {" "$function2_sh; };" "export -f testsuite4;"]
77 lappend ans_bash [list testsuite "() {" "$function_sh; };" "export -f testsuite;"]
78 lappend ans_bash [list testsuite5 "() {" "$function3_sh; };" "export -f testsuite5;"]
79
80 lappend ans_fish [list set __MODULES_LMREFRESH $module]
81 lappend ans_fish [list set _LMFILES_ $modulefile]
82 lappend ans_fish [list set LOADEDMODULES $module]
83 lappend ans_fish [list function "testsuite2;" "$function2_fish;" "end;"]
84 lappend ans_fish [list function "testsuite3;" "$function2_fish;" "end;"]
85 lappend ans_fish [list function "testsuite4;" "$function2_fish;" "end;"]
86 lappend ans_fish [list function "testsuite;" "$function_fish;" "end;"]
87 lappend ans_fish [list function "testsuite5;" "$function3_fish;" "end;"]
88
89 lappend ans_pwsh [list set __MODULES_LMREFRESH $module]
90 lappend ans_pwsh [list set _LMFILES_ $modulefile]
91 lappend ans_pwsh [list set LOADEDMODULES $module]
92 lappend ans_pwsh [list function global:testsuite2 "{" "$function2_pwsh" "}"]
93 lappend ans_pwsh [list function global:testsuite3 "{" "$function2_pwsh" "}"]
94 lappend ans_pwsh [list function global:testsuite4 "{" "$function2_pwsh" "}"]
95 lappend ans_pwsh [list function global:testsuite "{" "$function_pwsh" "}"]
96 lappend ans_pwsh [list function global:testsuite5 "{" "$function3_pwsh" "}"]
97
98 lappend ans_unsh [list set _LMFILES_ $modulefile]
99 lappend ans_unsh [list set LOADEDMODULES $module]
100 lappend ans_unsh [list unset "-g" testsuite]
101
102 #
103 # set-function test via load
104 #
105
106 foreach sh $supported_shells {
107 # only available for fish and sh derivatives
108 # other shells do not get output for 'set-function'
109 if {$sh eq "fish"} {
110 test_cmd "$sh" "load $module" $ans_fish
111 } elseif {$sh eq {bash}} {
112 test_cmd "$sh" "load $module" $ans_bash
113 } elseif { [lsearch {sh ksh zsh} $sh] >= 0 } {
114 test_cmd "$sh" "load $module" $ans_sh
115 } elseif {$sh eq "pwsh"} {
116 test_cmd "$sh" "load $module" $ans_pwsh
117 } else {
118 test_cmd "$sh" "load $module" $ans_empty
119 }
120 }
121
122 skip_if_quick_mode
123
124 #
125 # Test special characters handling.
126 # Currently we are not hacking the function-string.
127 # Recommended use is to use {} for quoting the function body
128 #
129
130 set module "function/2.0"
131 set modulefile "$modpath/$module"
132
133 set function_sh {echo $(grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'); echo $1}
134 set function_fish {echo (grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'); echo $argv[1]}
135 set function_pwsh {echo (grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'); echo $argv[1]}
136
137 set ans_empty [list]
138 lappend ans_empty [list set __MODULES_LMREFRESH $module]
139 lappend ans_empty [list set _LMFILES_ $modulefile]
140 lappend ans_empty [list set LOADEDMODULES $module]
141
142 set ans_sh [list]
143 lappend ans_sh [list set __MODULES_LMREFRESH $module]
144 lappend ans_sh [list set _LMFILES_ $modulefile]
145 lappend ans_sh [list set LOADEDMODULES $module]
146 lappend ans_sh [list testsuite "() {" "$function_sh; };"]
147
148 set ans_bash [list]
149 lappend ans_bash [list set __MODULES_LMREFRESH $module]
150 lappend ans_bash [list set _LMFILES_ $modulefile]
151 lappend ans_bash [list set LOADEDMODULES $module]
152 lappend ans_bash [list testsuite "() {" "$function_sh; };" "export -f testsuite;"]
153
154 set ans_fish [list]
155 lappend ans_fish [list set __MODULES_LMREFRESH $module]
156 lappend ans_fish [list set _LMFILES_ $modulefile]
157 lappend ans_fish [list set LOADEDMODULES $module]
158 lappend ans_fish [list function "testsuite;" "$function_fish;" "end;"]
159
160 set ans_pwsh [list]
161 lappend ans_pwsh [list set __MODULES_LMREFRESH $module]
162 lappend ans_pwsh [list set _LMFILES_ $modulefile]
163 lappend ans_pwsh [list set LOADEDMODULES $module]
164 lappend ans_pwsh [list function global:testsuite "{" "$function_pwsh" "}"]
165
166 foreach sh $supported_shells {
167 switch -- $sh {
168 {bash} {
169 test_cmd $sh "load $module" $ans_bash
170 }
171 {sh} - {ksh} - {zsh} {
172 test_cmd $sh "load $module" $ans_sh
173 }
174 {fish} {
175 test_cmd $sh "load $module" $ans_fish
176 }
177 {pwsh} {
178 test_cmd $sh "load $module" $ans_pwsh
179 }
180 }
181 }
182
183
184 #
185 # Cleanup
186 #
187
188 reset_test_env