* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / misc / test_lldb_cruby.rb
blobbd58619ac2a9ecb6c927bc8ad42337b0d7ef87a2
1 #!/usr/bin/env ruby
2 require 'open3'
3 require 'tempfile'
4 require 'test/unit'
6 class TestLLDBInit < Test::Unit::TestCase
7   def assert_rp(expr, pattern, message=nil)
8     Tempfile.create('lldb') do |tf|
9       tf.puts <<eom
10 target create ./miniruby
11 command script import -r misc/lldb_cruby.py
12 b rb_inspect
13 run -e'p #{expr}'
14 rp obj
15 eom
16       tf.flush
17       o, s = Open3.capture2('lldb', '-b', '-s', tf.path)
18       assert_true s.success?, message
19       assert_match /^\(lldb\) rp obj\n#{pattern}/, o, message
20     end
21   end
23   def test_rp_object
24     assert_rp 'Object.new', 'T_OBJECT'
25   end
27   def test_rp_regex
28     assert_rp '/foo/', '[(]Regex'
29   end
31   def test_rp_symbol
32     assert_rp ':abcde', /T_SYMBOL: \(\h+\)/
33   end
35   def test_rp_string
36     assert_rp '"abc"', /\(char \[\d+\]\) ary = "abc"/
37     assert_rp "\"\u3042\"", /\(char \[\d+\]\) ary = "\u3042"/
38     assert_rp '"' + "\u3042"*10 + '"', /\(RString::\(anonymous struct\)\) heap = \{/
39   end
40 end