source: EcnlProtoTool/trunk/mruby-1.2.0/mrbgems/mruby-bin-strip/bintest/mruby-strip.rb@ 270

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

mruby版ECNLプロトタイピング・ツールを追加

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-ruby
File size: 2.2 KB
Line 
1require 'tempfile'
2
3assert('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]
7end
8
9assert('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
13end
14
15assert('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
22end
23
24assert('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')} -b #{compiled1.path}`
36
37 o = `#{cmd('mruby-strip')} #{compiled1.path} #{compiled2.path}`
38 assert_equal 0, $?.exitstatus
39 assert_equal "", o
40end
41
42assert('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
54end
55
56assert('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
60a, b = 0, 1
61a += b
62p Kernel.local_variables
63EOS
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
73end
Note: See TracBrowser for help on using the repository browser.