about summary refs log tree commit diff
path: root/Test/V04features.ztst
blob: 2790456e2cea606a55ba682e344d00e0c0804905 (plain) (blame)
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
%prep

# Do some tests on handling of features.
# This also does some slightly more sophisticated loading and
# unloading tests than we did in V01zmodload.ztst.
#
# We use zsh/datetime because it has a list of features that is short
# but contains two types.

  if ! (zmodload zsh/datetime >/dev/null 2>/dev/null); then
    ZTST_unimplemented="can't load the zsh/datetime module for testing"
  fi

%test
  zmodload -F zsh/datetime
  zmodload -lF zsh/datetime
0:Loading modules with no features
>-b:strftime
>-p:EPOCHSECONDS
>-p:EPOCHREALTIME
>-p:epochtime

  zmodload -F zsh/datetime b:strftime
  zmodload -lF zsh/datetime
0:Enabling features
>+b:strftime
>-p:EPOCHSECONDS
>-p:EPOCHREALTIME
>-p:epochtime

  zmodload -F zsh/datetime +p:EPOCHSECONDS -b:strftime
  zmodload -lF zsh/datetime
0:Disabling features
>-b:strftime
>+p:EPOCHSECONDS
>-p:EPOCHREALTIME
>-p:epochtime

  zmodload -Fe zsh/datetime p:EPOCHSECONDS b:strftime
0:Testing existing features

  zmodload -Fe zsh/datetime +p:EPOCHSECONDS
0:Testing features are in given state (on feature is on)

  zmodload -Fe zsh/datetime -p:EPOCHSECONDS
1:Testing features are in given state (on feature is not off

  zmodload -Fe zsh/datetime +p:strftime
1:Testing features are in given state (off feature is not on)

  zmodload -Fe zsh/datetime -b:strftime
0:Testing features are in given state (off feature is off

  zmodload -Fe zsh/datetime p:EPOCHSECONDS b:strftime b:mktimebetter
1:Testing non-existent features

  zmodload -FlP dtf zsh/datetime
  for feature in b:strftime p:EPOCHSECONDS; do
    if [[ ${${dtf[(R)?$feature]}[1]} = + ]]; then
      print $feature is enabled
    else
      print $feature is disabled
    fi
  done
0:Testing features via array parameter
>b:strftime is disabled
>p:EPOCHSECONDS is enabled

  fn() {
    local EPOCHSECONDS=scruts
    print $EPOCHSECONDS
    print ${(t)EPOCHSECONDS}
  }
  fn
  if [[ $EPOCHSECONDS = <-> ]]; then
    print EPOCHSECONDS is a number
  else
    print EPOCHSECONDS is some random piece of junk
  fi
  print ${(t)EPOCHSECONDS}
0:Module special parameter is hidden by a local parameter
>scruts
>scalar-local
>EPOCHSECONDS is a number
>integer-readonly-hide-hideval-special

  typeset +h EPOCHSECONDS
  fn() {
    local EPOCHSECONDS=scruts
    print Didn\'t get here >&2
  }
  fn
1:Unhidden readonly special can't be assigned to when made local
?fn:1: read-only variable: EPOCHSECONDS

  zmodload -u zsh/datetime
0:Module unloaded

  zmodload -e zsh/datetime
1:Module doesn't exist when unloaded

  zmodload -Fe zsh/datetime p:EPOCHSECONDS
1:Module doesn't have features when unloaded

  fn() {
    local EPOCHSECONDS=scrimf
    zmodload zsh/datetime
  }
  fn
2:Failed to add parameter if local parameter present
?fn:2: Can't add module parameter `EPOCHSECONDS': local parameter exists
?fn:zsh/datetime:2: error when adding parameter `EPOCHSECONDS'

  zmodload -lF zsh/datetime
0:Feature state with loading after error enabling
>+b:strftime
>-p:EPOCHSECONDS
>+p:EPOCHREALTIME
>+p:epochtime

  zmodload -F zsh/datetime p:EPOCHSECONDS
  zmodload -Fe zsh/datetime +p:EPOCHSECONDS
0:Successfully added feature parameter that previously failed

  fn() {
    local EPOCHSECONDS=scrooble
    zmodload -u zsh/datetime
    print $EPOCHSECONDS
  }
  fn
  print ${+EPOCHSECONDS}
0:Successfully unloaded a module despite a parameter being hidden
>scrooble
>0

  EPOCHSECONDS=(any old parameter)
  print -l $EPOCHSECONDS
0:Using parameter as normal after unloading is OK
>any
>old
>parameter

  print strftime is ${builtins[strftime]:-undefined}
  zmodload -F zsh/datetime b:strftime
  print strftime is ${builtins[strftime]:-undefined}
  zmodload -F zsh/datetime -b:strftime
  print strftime is ${builtins[strftime]:-undefined}
0:Enabling and disabling of builtins as features
>strftime is undefined
>strftime is defined
>strftime is undefined

  zmodload -u zsh/datetime
  zmodload zsh/datetime
2:Loading won't override global parameter
?(eval):2: Can't add module parameter `EPOCHSECONDS': parameter already exists
?(eval):zsh/datetime:2: error when adding parameter `EPOCHSECONDS'

  unset EPOCHSECONDS
  zmodload -F zsh/datetime p:EPOCHSECONDS
  zmodload -Fe zsh/datetime +p:EPOCHSECONDS
0:unsetting a global parameter allows feature parameter to be enabled

  zmodload -F zsh/datetime -b:strftime -p:EPOCHSECONDS
  zmodload zsh/datetime
  zmodload -lF zsh/datetime
0:zmodload with no -F enables all features
>+b:strftime
>+p:EPOCHSECONDS
>+p:EPOCHREALTIME
>+p:epochtime