benry-cmdapp 0.2.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +6 -0
- data/README.md +1693 -852
- data/benry-cmdapp.gemspec +3 -3
- data/doc/benry-cmdapp.html +1582 -906
- data/lib/benry/cmdapp.rb +1894 -1060
- data/test/app_test.rb +882 -1078
- data/test/config_test.rb +71 -0
- data/test/context_test.rb +382 -0
- data/test/func_test.rb +302 -82
- data/test/help_test.rb +1054 -553
- data/test/metadata_test.rb +191 -0
- data/test/misc_test.rb +175 -0
- data/test/registry_test.rb +402 -0
- data/test/run_all.rb +4 -3
- data/test/scope_test.rb +1210 -0
- data/test/shared.rb +112 -49
- data/test/util_test.rb +154 -99
- metadata +17 -9
- data/test/action_test.rb +0 -1038
- data/test/index_test.rb +0 -185
data/test/index_test.rb
DELETED
@@ -1,185 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
|
3
|
-
require 'oktest'
|
4
|
-
|
5
|
-
require 'benry/cmdapp'
|
6
|
-
require_relative './shared'
|
7
|
-
|
8
|
-
|
9
|
-
Oktest.scope do
|
10
|
-
|
11
|
-
|
12
|
-
topic Benry::CmdApp::ActionIndex do
|
13
|
-
include CommonTestingHelper
|
14
|
-
|
15
|
-
class IndexTestAction < Benry::CmdApp::ActionScope
|
16
|
-
@action.("lookup test #1")
|
17
|
-
@option.(:repeat, "-r <N>", "repeat", type: Integer)
|
18
|
-
def lookup1(user="world", repeat: nil); end
|
19
|
-
#
|
20
|
-
@action.("lookup test #2")
|
21
|
-
def lookup2(); end
|
22
|
-
#
|
23
|
-
private
|
24
|
-
@action.("lookup test #3") # hidden
|
25
|
-
def lookup3(); end
|
26
|
-
end
|
27
|
-
|
28
|
-
Benry::CmdApp.action_alias("findxx", "lookup2")
|
29
|
-
|
30
|
-
|
31
|
-
topic '.lookup_action()' do
|
32
|
-
|
33
|
-
spec "[!vivoa] returns action metadata object." do
|
34
|
-
x = Benry::CmdApp::INDEX.lookup_action("lookup1")
|
35
|
-
ok {x} != nil
|
36
|
-
ok {x}.is_a?(Benry::CmdApp::ActionMetadata)
|
37
|
-
ok {x.name} == "lookup1"
|
38
|
-
ok {x.klass} == IndexTestAction
|
39
|
-
ok {x.method} == :lookup1
|
40
|
-
end
|
41
|
-
|
42
|
-
spec "[!tnwq0] supports alias name." do
|
43
|
-
x = Benry::CmdApp::INDEX.lookup_action("findxx")
|
44
|
-
ok {x} != nil
|
45
|
-
ok {x}.is_a?(Benry::CmdApp::ActionMetadata)
|
46
|
-
ok {x.name} == "lookup2"
|
47
|
-
ok {x.klass} == IndexTestAction
|
48
|
-
ok {x.method} == :lookup2
|
49
|
-
end
|
50
|
-
|
51
|
-
spec "[!z15vu] returns ActionWithArgs object if alias has args and/or kwargs." do
|
52
|
-
Benry::CmdApp.action_alias("findyy1", "lookup1", "Alice", "-r3")
|
53
|
-
x = Benry::CmdApp::INDEX.lookup_action("findyy1")
|
54
|
-
ok {x} != nil
|
55
|
-
ok {x}.is_a?(Benry::CmdApp::ActionWithArgs)
|
56
|
-
ok {x.args} == ["Alice"]
|
57
|
-
ok {x.kwargs} == {repeat: 3}
|
58
|
-
ok {x.name} == "lookup1"
|
59
|
-
ok {x.klass} == IndexTestAction
|
60
|
-
ok {x.method} == :lookup1
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
topic '.each_action_name_and_desc()' do
|
67
|
-
|
68
|
-
before do
|
69
|
-
clear_index_except(IndexTestAction)
|
70
|
-
end
|
71
|
-
|
72
|
-
after do
|
73
|
-
restore_index()
|
74
|
-
end
|
75
|
-
|
76
|
-
spec "[!5lahm] yields action name, description, and important flag." do
|
77
|
-
arr = []
|
78
|
-
Benry::CmdApp::INDEX.each_action_name_and_desc(false) {|a| arr << a }
|
79
|
-
ok {arr} == [
|
80
|
-
["lookup1", "lookup test #1", nil],
|
81
|
-
["lookup2", "lookup test #2", nil],
|
82
|
-
]
|
83
|
-
#
|
84
|
-
with_important("lookup1"=>true, "lookup2"=>false) do
|
85
|
-
arr = []
|
86
|
-
Benry::CmdApp::INDEX.each_action_name_and_desc(false) {|a| arr << a }
|
87
|
-
ok {arr} == [
|
88
|
-
["lookup1", "lookup test #1", true],
|
89
|
-
["lookup2", "lookup test #2", false],
|
90
|
-
]
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
spec "[!27j8b] includes alias names when the first arg is true." do
|
95
|
-
arr = []
|
96
|
-
Benry::CmdApp::INDEX.each_action_name_and_desc(true) {|a| arr << a }
|
97
|
-
ok {arr} == [
|
98
|
-
["findxx", "alias of 'lookup2' action", nil],
|
99
|
-
["findyy1", "alias of 'lookup1 Alice -r3'", nil],
|
100
|
-
["lookup1", "lookup test #1", nil],
|
101
|
-
["lookup2", "lookup test #2", nil],
|
102
|
-
]
|
103
|
-
end
|
104
|
-
|
105
|
-
spec "[!8xt8s] rejects hidden actions if 'all: false' kwarg specified." do
|
106
|
-
arr = []
|
107
|
-
Benry::CmdApp::INDEX.each_action_name_and_desc(false, all: false) {|a| arr << a }
|
108
|
-
ok {arr} == [
|
109
|
-
["lookup1", "lookup test #1", nil],
|
110
|
-
["lookup2", "lookup test #2", nil],
|
111
|
-
]
|
112
|
-
end
|
113
|
-
|
114
|
-
spec "[!5h7s5] includes hidden actions if 'all: true' kwarg specified." do
|
115
|
-
arr = []
|
116
|
-
Benry::CmdApp::INDEX.each_action_name_and_desc(false, all: true) {|a| arr << a }
|
117
|
-
ok {arr} == [
|
118
|
-
["lookup1", "lookup test #1", nil],
|
119
|
-
["lookup2", "lookup test #2", nil],
|
120
|
-
["lookup3", "lookup test #3", false], # hidden action
|
121
|
-
]
|
122
|
-
end
|
123
|
-
|
124
|
-
spec "[!arcia] action names are sorted." do
|
125
|
-
arr = []
|
126
|
-
Benry::CmdApp::INDEX.each_action_name_and_desc(true) {|a| arr << a }
|
127
|
-
ok {arr} == arr.sort_by(&:first)
|
128
|
-
end
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
|
133
|
-
topic '#delete_action()' do
|
134
|
-
|
135
|
-
spec "[!08e1s] unregisters action." do
|
136
|
-
class DeleteActionTest < Benry::CmdApp::ActionScope
|
137
|
-
@action.("test")
|
138
|
-
def delaction1(); end
|
139
|
-
end
|
140
|
-
name = "delaction1"
|
141
|
-
ok {Benry::CmdApp::INDEX.action_exist?(name)} == true
|
142
|
-
Benry::CmdApp::INDEX.delete_action(name)
|
143
|
-
ok {Benry::CmdApp::INDEX.action_exist?(name)} == false
|
144
|
-
end
|
145
|
-
|
146
|
-
spec "[!zjpq0] raises error if action not registered." do
|
147
|
-
name = "delaction99"
|
148
|
-
ok {Benry::CmdApp::INDEX.action_exist?(name)} == false
|
149
|
-
pr = proc { Benry::CmdApp::INDEX.delete_action(name) }
|
150
|
-
ok {pr}.raise?(Benry::CmdApp::ActionNotFoundError,
|
151
|
-
"delete_action(\"delaction99\"): Action not found.")
|
152
|
-
end
|
153
|
-
|
154
|
-
end
|
155
|
-
|
156
|
-
|
157
|
-
topic '#delete_alias()' do
|
158
|
-
|
159
|
-
spec "[!8ls45] unregisters alias." do
|
160
|
-
class DeleteAliasTest < Benry::CmdApp::ActionScope
|
161
|
-
@action.("test")
|
162
|
-
def delalias1(); end
|
163
|
-
end
|
164
|
-
Benry::CmdApp.action_alias("delali1", "delalias1")
|
165
|
-
name = "delali1"
|
166
|
-
ok {Benry::CmdApp::INDEX.alias_exist?(name)} == true
|
167
|
-
Benry::CmdApp::INDEX.delete_alias(name)
|
168
|
-
ok {Benry::CmdApp::INDEX.alias_exist?(name)} == false
|
169
|
-
end
|
170
|
-
|
171
|
-
spec "[!fdfyq] raises error if alias not registered." do
|
172
|
-
name = "delalias99"
|
173
|
-
ok {Benry::CmdApp::INDEX.alias_exist?(name)} == false
|
174
|
-
pr = proc { Benry::CmdApp::INDEX.delete_alias(name) }
|
175
|
-
ok {pr}.raise?(Benry::CmdApp::ActionNotFoundError,
|
176
|
-
"delete_alias(\"delalias99\"): Alias not found.")
|
177
|
-
end
|
178
|
-
|
179
|
-
end
|
180
|
-
|
181
|
-
|
182
|
-
end
|
183
|
-
|
184
|
-
|
185
|
-
end
|