Debian Codegraph @

vendor/mruby-source/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb

raw
1 require 'tempfile'
2
3 assert('no files') do
4 o = `#{cmd('mruby-strip')} 2>&1`
5 assert_equal 1, $?.exitstatus
6 assert_equal "no files to strip", o.split("\n")[0]
7 end
8
9 assert('file not found') do
10 o = `#{cmd('mruby-strip')} not_found.mrb 2>&1`
11 assert_equal 1, $?.exitstatus
12 assert_equal "can't open file for reading not_found.mrb\n", o
13 end
14
15 assert('not irep file') do
16 t = Tempfile.new('script.rb')
17 t.write 'p test\n'
18 t.flush
19 o = `#{cmd('mruby-strip')} #{t.path} 2>&1`
20 assert_equal 1, $?.exitstatus
21 assert_equal "can't read irep file #{t.path}\n", o
22 end
23
24 assert('success') do
25 script_file, compiled1, compiled2 =
26 Tempfile.new('script.rb'), Tempfile.new('c1.mrb'), Tempfile.new('c2.mrb')
27 script_file.write "p 'test'\n"
28 script_file.flush
29 `#{cmd('mrbc')} -g -o #{compiled1.path} #{script_file.path}`
30 `#{cmd('mrbc')} -g -o #{compiled2.path} #{script_file.path}`
31
32 o = `#{cmd('mruby-strip')} #{compiled1.path}`
33 assert_equal 0, $?.exitstatus
34 assert_equal "", o
35 assert_equal `#{cmd('mruby')} #{script_file.path}`, `#{cmd('mruby')} #{compiled1.path}`
36
37 o = `#{cmd('mruby-strip')} #{compiled1.path} #{compiled2.path}`
38 assert_equal 0, $?.exitstatus
39 assert_equal "", o
40 end
41
42 assert('check debug section') do
43 script_file, with_debug, without_debug =
44 Tempfile.new('script.rb'), Tempfile.new('c1.mrb'), Tempfile.new('c2.mrb')
45 script_file.write "p 'test'\n"
46 script_file.flush
47 `#{cmd('mrbc')} -o #{without_debug.path} #{script_file.path}`
48 `#{cmd('mrbc')} -g -o #{with_debug.path} #{script_file.path}`
49
50 assert_true with_debug.size >= without_debug.size
51
52 `#{cmd('mruby-strip')} #{with_debug.path}`
53 assert_equal without_debug.size, with_debug.size
54 end
55
56 assert('check lv section') do
57 script_file, with_lv, without_lv =
58 Tempfile.new('script.rb'), Tempfile.new('c1.mrb'), Tempfile.new('c2.mrb')
59 script_file.write <<EOS
60 a, b = 0, 1
61 a += b
62 p Kernel.local_variables
63 EOS
64 script_file.flush
65 `#{cmd('mrbc')} -o #{with_lv.path} #{script_file.path}`
66 `#{cmd('mrbc')} -o #{without_lv.path} #{script_file.path}`
67
68 `#{cmd('mruby-strip')} -l #{without_lv.path}`
69 assert_true without_lv.size < with_lv.size
70 #
71 # assert_equal '[:a, :b]', `#{cmd('mruby')} -b #{with_lv.path}`.chomp
72 # assert_equal '[]', `#{cmd('mruby')} -b #{without_lv.path}`.chomp
73 end