- Timestamp:
- Jul 9, 2020, 8:51:43 AM (4 years ago)
- Location:
- EcnlProtoTool/trunk/mruby-2.1.1
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/mruby-2.1.1/mrbgems/mruby-bin-debugger/bintest/print.rb
r331 r439 1 1 require 'open3' 2 2 require 'tempfile' 3 require 'strscan' 3 4 4 5 class BinTest_MrubyBinDebugger 5 @debug1=false6 @debug2=true6 # @debug1=false 7 # @debug2=true 7 8 def self.test(rubysource, testcase) 8 9 script, bin = Tempfile.new(['test', '.rb']), Tempfile.new(['test', '.mrb']) … … 20 21 stdin_data = testcase.map{|t| t[:cmd]}.join("\n") << "\n" 21 22 23 prompt = /^\(#{Regexp.escape(script.path)}:\d+\) / 22 24 ["bin/mrdb #{script.path}","bin/mrdb -b #{bin.path}"].each do |cmd| 23 25 o, s = Open3.capture2(cmd, :stdin_data => stdin_data) 24 25 exp_vals = testcase.map{|t| t.fetch(:exp, nil)} 26 scanner = StringScanner.new(o) 27 scanner.skip_until(prompt) 28 testcase.each do |tc| 29 exp = tc[:exp] 30 if exp 31 act = scanner.scan_until(/\n/) 32 break unless assert_operator act, :start_with?, exp 33 end 34 scanner.skip_until(prompt) 35 end 36 26 37 =begin 27 38 if @debug1 … … 42 53 end 43 54 =end 44 idx = 045 exp_vals.each do |exp|46 next if exp.nil?47 idx = o.index(exp, idx)48 assert_false idx.nil?49 break unless idx50 idx += 151 end52 55 end 53 56 end … … 91 94 # test case 92 95 tc = [] 93 tc << {:cmd=>"p (1+2", :exp=>'$1 = SyntaxError'}94 tc << {:cmd=>"p bar", :exp=>'$2 = NoMethodError'}96 tc << {:cmd=>"p (1+2", :exp=>'$1 = line 1: syntax error'} 97 tc << {:cmd=>"p bar", :exp=>'$2 = undefined method'} 95 98 96 99 BinTest_MrubyBinDebugger.test(src, tc) … … 318 321 SRC 319 322 320 # todo: wait for 'break' to be impl imented323 # todo: wait for 'break' to be implemented 321 324 tc = [] 322 325 9.times { tc << {:cmd=>"s"} } … … 342 345 tc << {:cmd=>"p 0x100", :exp=>'$4 = 256'} 343 346 tc << {:cmd=>"p 1_234", :exp=>'$5 = 1234'} 344 tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000 .to_s}"}345 tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000 .to_s}"}347 tc << {:cmd=>"p 0b1000_0000", :exp=>"$6 = #{0b1000_0000}"} 348 tc << {:cmd=>"p 0x1000_0000", :exp=>"$7 = #{0x1000_0000}"} 346 349 347 350 tc << {:cmd=>"p 3.14", :exp=>'$8 = 3.14'} 348 351 tc << {:cmd=>"p -12.3", :exp=>'$9 = -12.3'} 349 tc << {:cmd=>"p +12.000", :exp=>'$10 = 12 .0'}350 tc << {:cmd=>"p 1e4", :exp=>'$11 = 10000 .0'}352 tc << {:cmd=>"p +12.000", :exp=>'$10 = 12'} 353 tc << {:cmd=>"p 1e4", :exp=>'$11 = 10000'} 351 354 tc << {:cmd=>"p -0.1e-2", :exp=>'$12 = -0.001'} 352 355 … … 369 372 tc << {:cmd=>'p "str"', :exp=>'$1 = "str"'} 370 373 tc << {:cmd=>'p "s\tt\rr\n"', :exp=>'$2 = "s\\tt\\rr\\n"'} 371 tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\ 001\\032"'}374 tc << {:cmd=>'p "\C-a\C-z"', :exp=>'$3 = "\\x01\\x1a"'} 372 375 tc << {:cmd=>'p "#{foo+bar}"', :exp=>'$4 = "foobar"'} 373 376 … … 375 378 tc << {:cmd=>'p \'s\\tt\\rr\\n\'', :exp=>'$6 = "s\\\\tt\\\\rr\\\\n"'} 376 379 tc << {:cmd=>'p \'\\C-a\\C-z\'', :exp=>'$7 = "\\\\C-a\\\\C-z"'} 377 tc << {:cmd=>'p \'#{foo+bar}\'', :exp=>'$8 = " #{foo+bar}"'}380 tc << {:cmd=>'p \'#{foo+bar}\'', :exp=>'$8 = "\\#{foo+bar}"'} 378 381 379 382 tc << {:cmd=>'p %!str!', :exp=>'$9 = "str"'} 380 383 tc << {:cmd=>'p %!s\tt\rr\n!', :exp=>'$10 = "s\\tt\\rr\\n"'} 381 tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\ 001\\032"'}384 tc << {:cmd=>'p %!\C-a\C-z!', :exp=>'$11 = "\\x01\\x1a"'} 382 385 tc << {:cmd=>'p %!#{foo+bar}!', :exp=>'$12 = "foobar"'} 383 386 384 387 tc << {:cmd=>'p %Q!str!', :exp=>'$13 = "str"'} 385 388 tc << {:cmd=>'p %Q!s\tt\rr\n!', :exp=>'$14 = "s\\tt\\rr\\n"'} 386 tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\ 001\\032"'}389 tc << {:cmd=>'p %Q!\C-a\C-z!', :exp=>'$15 = "\\x01\\x1a"'} 387 390 tc << {:cmd=>'p %Q!#{foo+bar}!', :exp=>'$16 = "foobar"'} 388 391 … … 390 393 tc << {:cmd=>'p %q!s\\tt\\rr\\n!', :exp=>'$18 = "s\\\\tt\\\\rr\\\\n"'} 391 394 tc << {:cmd=>'p %q!\\C-a\\C-z!', :exp=>'$19 = "\\\\C-a\\\\C-z"'} 392 tc << {:cmd=>'p %q!#{foo+bar}!', :exp=>'$20 = " #{foo+bar}"'}395 tc << {:cmd=>'p %q!#{foo+bar}!', :exp=>'$20 = "\\#{foo+bar}"'} 393 396 394 397 BinTest_MrubyBinDebugger.test(src, tc) … … 411 414 tc << {:cmd=>'p [ 5, 12, 8, 10, ]', :exp=>'$2 = [5, 12, 8, 10]'} 412 415 tc << {:cmd=>'p [1,2.5,"#{foo+bar}"]', :exp=>'$3 = [1, 2.5, "foobar"]'} 413 tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", " #{foo}"]'}416 tc << {:cmd=>'p %w[3.14 A\ &\ B #{foo}]', :exp=>'$4 = ["3.14", "A & B", "\#{foo}"]'} 414 417 tc << {:cmd=>'p %W[3.14 A\ &\ B #{foo}]', :exp=>'$5 = ["3.14", "A & B", "foo"]'} 415 418 … … 589 592 590 593 tc << {:cmd=>'p undefined=-1', :exp=>'$3 = -1'} 591 tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = NoMethodError'}594 tc << {:cmd=>'p "#{undefined}"', :exp=>'$4 = undefined method'} 592 595 593 596 BinTest_MrubyBinDebugger.test(src, tc) … … 627 630 628 631 tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'} 629 tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = NoMethodError'}632 tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'} 630 633 631 634 BinTest_MrubyBinDebugger.test(src, tc) … … 695 698 696 699 tc << {:cmd=>'p undefined=-1', :exp=>'$14 = -1'} 697 tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = NoMethodError'} 698 699 BinTest_MrubyBinDebugger.test(src, tc) 700 end 701 700 tc << {:cmd=>'p "#{undefined}"', :exp=>'$15 = undefined method'} 701 702 BinTest_MrubyBinDebugger.test(src, tc) 703 end
Note:
See TracChangeset
for help on using the changeset viewer.