source: EcnlProtoTool/trunk/mruby-1.3.0/mrbgems/mruby-bin-debugger/bintest/mrdb.rb@ 331

Last change on this file since 331 was 331, checked in by coas-nagasima, 6 years ago

prototoolに関連するプロジェクトをnewlibからmuslを使うよう変更・更新
ntshellをnewlibの下位の実装から、muslのsyscallの実装に変更・更新
以下のOSSをアップデート
・mruby-1.3.0
・musl-1.1.18
・onigmo-6.1.3
・tcc-0.9.27
以下のOSSを追加
・openssl-1.1.0e
・curl-7.57.0
・zlib-1.2.11
以下のmrbgemsを追加
・iij/mruby-digest
・iij/mruby-env
・iij/mruby-errno
・iij/mruby-iijson
・iij/mruby-ipaddr
・iij/mruby-mock
・iij/mruby-require
・iij/mruby-tls-openssl

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby;charset=UTF-8
File size: 8.5 KB
Line 
1require 'open3'
2require 'tempfile'
3
4class BinTest_MrubyBinDebugger
5 @debug1=false
6 @debug2=true
7 @debug3=true
8 def self.test(rubysource, testcase)
9 script, bin = Tempfile.new(['test', '.rb']), Tempfile.new(['test', '.mrb'])
10
11 # .rb
12 script.write rubysource
13 script.flush
14
15 # compile
16 `./bin/mrbc -g -o "#{bin.path}" "#{script.path}"`
17
18 # add mrdb quit
19 testcase << {:cmd=>"quit"}
20
21 stdin_data = testcase.map{|t| t[:cmd]}.join("\n") << "\n"
22
23 ["bin/mrdb #{script.path}","bin/mrdb -b #{bin.path}"].each do |cmd|
24 o, s = Open3.capture2(cmd, :stdin_data => stdin_data)
25
26 exp_vals = testcase.map{|t| t.fetch(:exp, nil)}
27 unexp_vals = testcase.map{|t| t.fetch(:unexp, nil)}
28
29if @debug1
30 o.split("\n").each_with_index do |i,actual|
31 p [i,actual]
32 end
33end
34 # compare actual / expected
35 o.split("\n").each do |actual|
36 next if actual.empty?
37 exp = exp_vals.shift
38if @debug2
39 a = true
40 a = actual.include?(exp) unless exp.nil?
41 p [actual, exp] unless a
42end
43 assert_true actual.include?(exp) unless exp.nil?
44 end
45 # compare actual / unexpected
46 o.split("\n").each do |actual|
47 next if actual.empty?
48 unexp = unexp_vals.shift
49if @debug3
50 a = false
51 a = actual.include?(unexp) unless unexp.nil?
52 p [actual, unexp] if a
53end
54 assert_false actual.include?(unexp) unless unexp.nil?
55 end
56 end
57 end
58end
59
60INVCMD = "invalid command"
61
62assert('mruby-bin-debugger(mrdb) command line') do
63 # ruby source
64 src = "foo = 'foo'\n"
65
66 str = ""
67 103.times {
68 str += "1234567890"
69 }
70 cmd = "p a=#{str}"
71
72 # test case
73 BinTest_MrubyBinDebugger.test(src, [{:cmd=>cmd[0...1023], :unexp=>'command line too long.'}])
74 BinTest_MrubyBinDebugger.test(src, [{:cmd=>cmd[0...1024], :unexp=>'command line too long.'}])
75 BinTest_MrubyBinDebugger.test(src, [{:cmd=>cmd[0...1025], :exp=>'command line too long.'}])
76end
77
78assert('mruby-bin-debugger(mrdb) command: "break"') do
79 # ruby source
80 src = "foo = 'foo'\n"
81
82 # test case
83 tc = []
84 tc << {:cmd=>"b", :unexp=>INVCMD}
85 tc << {:cmd=>"br", :unexp=>INVCMD}
86 tc << {:cmd=>"brea", :unexp=>INVCMD}
87 tc << {:cmd=>"break", :unexp=>INVCMD}
88 BinTest_MrubyBinDebugger.test(src, tc)
89
90 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"bl", :exp=>INVCMD}])
91 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"breaka", :exp=>INVCMD}])
92end
93
94assert('mruby-bin-debugger(mrdb) command: "continue"') do
95 # ruby source
96 src = "foo = 'foo'\n"
97
98 # test case
99 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"c", :unexp=>INVCMD}])
100 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"co", :unexp=>INVCMD}])
101 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"continu", :unexp=>INVCMD}])
102 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"continue", :unexp=>INVCMD}])
103
104 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"cn", :exp=>INVCMD}])
105 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"continuee", :exp=>INVCMD}])
106end
107
108assert('mruby-bin-debugger(mrdb) command: "delete"') do
109 # ruby source
110 src = "foo = 'foo'\n"
111
112 # test case
113 tc = []
114 tc << {:cmd=>"d 1", :unexp=>INVCMD}
115 tc << {:cmd=>"de 1", :unexp=>INVCMD}
116 tc << {:cmd=>"delet 1", :unexp=>INVCMD}
117 tc << {:cmd=>"delete 1", :unexp=>INVCMD}
118 BinTest_MrubyBinDebugger.test(src, tc)
119
120 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"dd 1", :exp=>INVCMD}])
121 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"deletee 1", :exp=>INVCMD}])
122end
123
124assert('mruby-bin-debugger(mrdb) command: "disable"') do
125 # ruby source
126 src = "foo = 'foo'\n"
127
128 # test case
129 tc = []
130 tc << {:cmd=>"dis", :unexp=>INVCMD}
131 tc << {:cmd=>"disa", :unexp=>INVCMD}
132 tc << {:cmd=>"disabl", :unexp=>INVCMD}
133 tc << {:cmd=>"disable", :unexp=>INVCMD}
134 BinTest_MrubyBinDebugger.test(src, tc)
135
136 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"di", :exp=>INVCMD}])
137 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"disb", :exp=>INVCMD}])
138 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"disablee", :exp=>INVCMD}])
139end
140
141assert('mruby-bin-debugger(mrdb) command: "enable"') do
142 # ruby source
143 src = "foo = 'foo'\n"
144
145 # test case
146 tc = []
147 tc << {:cmd=>"en", :unexp=>INVCMD}
148 tc << {:cmd=>"ena", :unexp=>INVCMD}
149 tc << {:cmd=>"enabl", :unexp=>INVCMD}
150 tc << {:cmd=>"enable", :unexp=>INVCMD}
151 BinTest_MrubyBinDebugger.test(src, tc)
152
153 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"e", :exp=>INVCMD}])
154 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"enb", :exp=>INVCMD}])
155 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"enablee", :exp=>INVCMD}])
156end
157
158assert('mruby-bin-debugger(mrdb) command: "eval"') do
159 # ruby source
160 src = "foo = 'foo'\n"
161
162 # test case
163 tc = []
164 tc << {:cmd=>"ev", :unexp=>INVCMD}
165 tc << {:cmd=>"eva", :unexp=>INVCMD}
166 tc << {:cmd=>"eval", :unexp=>INVCMD}
167 BinTest_MrubyBinDebugger.test(src, tc)
168
169 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"e", :exp=>INVCMD}])
170 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"evl", :exp=>INVCMD}])
171 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"evall", :exp=>INVCMD}])
172end
173
174assert('mruby-bin-debugger(mrdb) command: "help"') do
175 # ruby source
176 src = "foo = 'foo'\n"
177
178 # test case
179 tc = []
180 tc << {:cmd=>"h", :unexp=>INVCMD}
181 tc << {:cmd=>"he", :unexp=>INVCMD}
182 tc << {:cmd=>"hel", :unexp=>INVCMD}
183 tc << {:cmd=>"help", :unexp=>INVCMD}
184 BinTest_MrubyBinDebugger.test(src, tc)
185
186 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"hl", :exp=>INVCMD}])
187 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"helpp", :exp=>INVCMD}])
188end
189
190assert('mruby-bin-debugger(mrdb) command: "info breakpoints"') do
191 # ruby source
192 src = "foo = 'foo'\n"
193
194 # test case
195 tc = []
196 tc << {:cmd=>"i b", :unexp=>INVCMD}
197 tc << {:cmd=>"in b", :unexp=>INVCMD}
198 tc << {:cmd=>"i br", :unexp=>INVCMD}
199 tc << {:cmd=>"inf breakpoint", :unexp=>INVCMD}
200 tc << {:cmd=>"info breakpoints", :unexp=>INVCMD}
201 BinTest_MrubyBinDebugger.test(src, tc)
202
203 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ii b", :exp=>INVCMD}])
204 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"i bb", :exp=>INVCMD}])
205 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"infoo breakpoints", :exp=>INVCMD}])
206 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"info breakpointss", :exp=>INVCMD}])
207end
208
209assert('mruby-bin-debugger(mrdb) command: "list"') do
210 # ruby source
211 src = "foo = 'foo'\n"
212
213 # test case
214 tc = []
215 tc << {:cmd=>"l", :unexp=>INVCMD}
216 tc << {:cmd=>"li", :unexp=>INVCMD}
217 tc << {:cmd=>"lis", :unexp=>INVCMD}
218 tc << {:cmd=>"list", :unexp=>INVCMD}
219 BinTest_MrubyBinDebugger.test(src, tc)
220
221 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ll", :exp=>INVCMD}])
222 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"listt", :exp=>INVCMD}])
223end
224
225assert('mruby-bin-debugger(mrdb) command: "print"') do
226 # ruby source
227 src = "foo = 'foo'\n"
228
229 # test case
230 tc = []
231 tc << {:cmd=>"p", :unexp=>INVCMD}
232 tc << {:cmd=>"pr", :unexp=>INVCMD}
233 tc << {:cmd=>"prin", :unexp=>INVCMD}
234 tc << {:cmd=>"print", :unexp=>INVCMD}
235 BinTest_MrubyBinDebugger.test(src, tc)
236
237 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"pp", :exp=>INVCMD}])
238 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"printt", :exp=>INVCMD}])
239end
240
241assert('mruby-bin-debugger(mrdb) command: "quit"') do
242 # ruby source
243 src = "foo = 'foo'\n"
244
245 # test case
246 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"q", :unexp=>INVCMD}])
247 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"qu", :unexp=>INVCMD}])
248 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"qui", :unexp=>INVCMD}])
249 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"quit", :unexp=>INVCMD}])
250
251 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"qq", :exp=>INVCMD}])
252 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"quitt", :exp=>INVCMD}])
253end
254
255assert('mruby-bin-debugger(mrdb) command: "run"') do
256 # ruby source
257 src = "foo = 'foo'\n"
258
259 # test case
260 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"r", :unexp=>INVCMD}])
261 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ru", :unexp=>INVCMD}])
262 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"run", :unexp=>INVCMD}])
263
264 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"rr", :exp=>INVCMD}])
265 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"runn", :exp=>INVCMD}])
266end
267
268assert('mruby-bin-debugger(mrdb) command: "step"') do
269 # ruby source
270 src = <<"SRC"
271while true
272 foo = 'foo'
273end
274SRC
275
276 # test case
277 tc = []
278 tc << {:cmd=>"s", :unexp=>INVCMD}
279 tc << {:cmd=>"st", :unexp=>INVCMD}
280 tc << {:cmd=>"ste", :unexp=>INVCMD}
281 tc << {:cmd=>"step", :unexp=>INVCMD}
282 BinTest_MrubyBinDebugger.test(src, tc)
283
284 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"ss", :exp=>INVCMD}])
285 BinTest_MrubyBinDebugger.test(src, [{:cmd=>"stepp", :exp=>INVCMD}])
286end
Note: See TracBrowser for help on using the repository browser.