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