File: 390-function.exp

package info (click to toggle)
modules 5.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,036 kB
  • sloc: exp: 79,659; sh: 6,142; tcl: 5,900; makefile: 1,492; ansic: 474; python: 265; csh: 202; perl: 47; ruby: 44; lisp: 13
file content (188 lines) | stat: -rw-r--r-- 6,817 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
##############################################################################
#   Modules Revision 3.0
#   Providing a flexible user environment
#
#   File:		modules.50-cmds/%M%
#   Revision:		%I%
#   First Edition:	2018/10/14
#   Last Mod.:		%U%, %G%
#
#   Authors:		nanobowers <nanobowers@gmail.com>
#
#   Description:	Testsuite testsequence
#   Command:		load
#   Modulefiles:	function/1.0 function/2.0
#   Sub-Command:
#
#   Comment:	%C{
#			Tests 'set-function' command
#		}C%
#
##############################################################################

# ensure auto symbolic versions are not set for these tests
setenv_var MODULES_ADVANCED_VERSION_SPEC 0

#
#  Variables. This test forces a module load command. It will result in the
#    environment variables "_LMFILES_", "LOADEDMODULES" and "testsuite" to
#    be set up
#

set module "function/1.0"
set modulefile "$modpath/$module"

# strictly speaking, this function is only valid for sh shells, not fish
set function_sh {eval $(echo cd $1)}
set function2_sh {echo $1}
set function3_sh {echo $1
    echo $2}
set function_fish {eval (echo cd $argv[1])}
set function2_fish {echo $argv[1]}
set function3_fish {echo $argv[1]
    echo $argv[2]}
set function_pwsh {Param([Parameter(Mandatory=$true, Position=0)] [string] $arg1); Invoke-Expression (echo cd $arg1)}
set function2_pwsh {Param([Parameter(Mandatory=$true, Position=0)] [string] $arg1); echo $arg1}
set function3_pwsh {Param(
        [Parameter(Mandatory=$true, Position=0)] [string] $arg1,
        [Parameter(Mandatory=$true, Position=1)] [string] $arg2
    )
    echo $arg1
    echo $arg2}

#
#  For the different shells ...
#

#lappend ans_empty [list function testsuite $function]
lappend ans_empty [list set __MODULES_LMREFRESH $module]
lappend ans_empty [list set _LMFILES_ $modulefile]
lappend ans_empty [list set LOADEDMODULES $module]

lappend ans_sh [list set __MODULES_LMREFRESH $module]
lappend ans_sh [list set _LMFILES_ $modulefile]
lappend ans_sh [list set LOADEDMODULES $module]
lappend ans_sh [list testsuite2 "() {" "$function2_sh; };"]
lappend ans_sh [list testsuite3 "() {" "$function2_sh; };"]
lappend ans_sh [list testsuite4 "() {" "$function2_sh; };"]
lappend ans_sh [list testsuite "() {" "$function_sh; };"]
lappend ans_sh [list testsuite5 "() {" "$function3_sh; };"]

lappend ans_bash [list set __MODULES_LMREFRESH $module]
lappend ans_bash [list set _LMFILES_ $modulefile]
lappend ans_bash [list set LOADEDMODULES $module]
lappend ans_bash [list testsuite2 "() {" "$function2_sh; };" "export -f testsuite2;"]
lappend ans_bash [list testsuite3 "() {" "$function2_sh; };" "export -f testsuite3;"]
lappend ans_bash [list testsuite4 "() {" "$function2_sh; };" "export -f testsuite4;"]
lappend ans_bash [list testsuite "() {" "$function_sh; };" "export -f testsuite;"]
lappend ans_bash [list testsuite5 "() {" "$function3_sh; };" "export -f testsuite5;"]

lappend ans_fish [list set __MODULES_LMREFRESH $module]
lappend ans_fish [list set _LMFILES_ $modulefile]
lappend ans_fish [list set LOADEDMODULES $module]
lappend ans_fish [list function "testsuite2;" "$function2_fish;" "end;"]
lappend ans_fish [list function "testsuite3;" "$function2_fish;" "end;"]
lappend ans_fish [list function "testsuite4;" "$function2_fish;" "end;"]
lappend ans_fish [list function "testsuite;" "$function_fish;" "end;"]
lappend ans_fish [list function "testsuite5;" "$function3_fish;" "end;"]

lappend ans_pwsh [list set __MODULES_LMREFRESH $module]
lappend ans_pwsh [list set _LMFILES_ $modulefile]
lappend ans_pwsh [list set LOADEDMODULES $module]
lappend ans_pwsh [list function global:testsuite2 "{" "$function2_pwsh" "}"]
lappend ans_pwsh [list function global:testsuite3 "{" "$function2_pwsh" "}"]
lappend ans_pwsh [list function global:testsuite4 "{" "$function2_pwsh" "}"]
lappend ans_pwsh [list function global:testsuite "{" "$function_pwsh" "}"]
lappend ans_pwsh [list function global:testsuite5 "{" "$function3_pwsh" "}"]

lappend ans_unsh [list set _LMFILES_ $modulefile]
lappend ans_unsh [list set LOADEDMODULES $module]
lappend ans_unsh [list unset "-g" testsuite]

#
#  set-function test via load
#

foreach sh $supported_shells {
    # only available for fish and sh derivatives
    # other shells do not get output for 'set-function'
    if {$sh eq "fish"} {
        test_cmd "$sh" "load $module" $ans_fish
    } elseif {$sh eq {bash}} {
        test_cmd "$sh" "load $module" $ans_bash
    } elseif { [lsearch {sh ksh zsh} $sh] >= 0 } {
        test_cmd "$sh" "load $module" $ans_sh
    } elseif {$sh eq "pwsh"} {
        test_cmd "$sh" "load $module" $ans_pwsh
    } else {
        test_cmd "$sh" "load $module" $ans_empty
    }
}

skip_if_quick_mode

#
# Test special characters handling.
# Currently we are not hacking the function-string.
# Recommended use is to use {} for quoting the function body
#

set module "function/2.0"
set modulefile "$modpath/$module"

set function_sh {echo $(grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'); echo $1}
set function_fish {echo (grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'); echo $argv[1]}
set function_pwsh {echo (grep "report .Modules " modulecmd.tcl | tr -d \\ | awk '{print $3}'); echo $argv[1]}

set ans_empty [list]
lappend ans_empty [list set __MODULES_LMREFRESH $module]
lappend ans_empty [list set _LMFILES_ $modulefile]
lappend ans_empty [list set LOADEDMODULES $module]

set ans_sh [list]
lappend ans_sh [list set __MODULES_LMREFRESH $module]
lappend ans_sh [list set _LMFILES_ $modulefile]
lappend ans_sh [list set LOADEDMODULES $module]
lappend ans_sh [list testsuite "() {" "$function_sh; };"]

set ans_bash [list]
lappend ans_bash [list set __MODULES_LMREFRESH $module]
lappend ans_bash [list set _LMFILES_ $modulefile]
lappend ans_bash [list set LOADEDMODULES $module]
lappend ans_bash [list testsuite "() {" "$function_sh; };" "export -f testsuite;"]

set ans_fish [list]
lappend ans_fish [list set __MODULES_LMREFRESH $module]
lappend ans_fish [list set _LMFILES_ $modulefile]
lappend ans_fish [list set LOADEDMODULES $module]
lappend ans_fish [list function "testsuite;" "$function_fish;" "end;"]

set ans_pwsh [list]
lappend ans_pwsh [list set __MODULES_LMREFRESH $module]
lappend ans_pwsh [list set _LMFILES_ $modulefile]
lappend ans_pwsh [list set LOADEDMODULES $module]
lappend ans_pwsh [list function global:testsuite "{" "$function_pwsh" "}"]

foreach sh $supported_shells {
    switch -- $sh {
        {bash} {
            test_cmd $sh "load $module" $ans_bash
        }
        {sh} - {ksh} - {zsh} {
            test_cmd $sh "load $module" $ans_sh
        }
        {fish} {
            test_cmd $sh "load $module" $ans_fish
        }
        {pwsh} {
            test_cmd $sh "load $module" $ans_pwsh
        }
    }
}


#
#  Cleanup
#

reset_test_env