Apply PIE to nghttpx
[platform/upstream/nghttp2.git] / third-party / mruby / mrbgems / mruby-bin-mruby / bintest / mruby.rb
1 require 'tempfile'
2
3 assert('regression for #1564') do
4   o = `#{cmd('mruby')} -e #{shellquote('<<')} 2>&1`
5   assert_include o, "-e:1:2: syntax error"
6   o = `#{cmd('mruby')} -e #{shellquote('<<-')} 2>&1`
7   assert_include o, "-e:1:3: syntax error"
8 end
9
10 assert('regression for #1572') do
11   script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
12   File.write script.path, 'p "ok"'
13   system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
14   o = `#{cmd('mruby')} -b #{bin.path}`.strip
15   assert_equal '"ok"', o
16 end
17
18 assert '$0 value' do
19   script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
20
21   # .rb script
22   script.write "p $0\n"
23   script.flush
24   assert_equal "\"#{script.path}\"", `#{cmd('mruby')} "#{script.path}"`.chomp
25
26   # .mrb file
27   `#{cmd('mrbc')} -o "#{bin.path}" "#{script.path}"`
28   assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} -b "#{bin.path}"`.chomp
29
30   # one liner
31   assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp
32 end
33
34 assert('float literal') do
35   script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb')
36   File.write script.path, 'p [3.21, 2e308.infinite?, -2e308.infinite?]'
37   system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}"
38   assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} -b #{bin.path}`.chomp!
39 end
40
41 assert '__END__', '8.6' do
42   script = Tempfile.new('test.rb')
43
44   script.write <<EOS
45 p 'test'
46   __END__ = 'fin'
47 p __END__
48 __END__
49 p 'legend'
50 EOS
51   script.flush
52   assert_equal "\"test\"\n\"fin\"\n", `#{cmd('mruby')} #{script.path}`
53 end
54
55 assert('garbage collecting built-in classes') do
56   script = Tempfile.new('test.rb')
57
58   script.write <<RUBY
59 NilClass = nil
60 GC.start
61 Array.dup
62 print nil.class.to_s
63 RUBY
64   script.flush
65   assert_equal "NilClass", `#{cmd('mruby')} #{script.path}`
66   assert_equal 0, $?.exitstatus
67 end
68
69 assert('mruby -d option') do
70   o = `#{cmd('mruby')} -e #{shellquote('p $DEBUG')}`
71   assert_equal "false\n", o
72   o = `#{cmd('mruby')} -d -e #{shellquote('p $DEBUG')}`
73   assert_equal "true\n", o
74 end
75
76 assert('mruby -r option') do
77   lib = Tempfile.new('lib.rb')
78   lib.write <<EOS
79 class Hoge
80   def hoge
81     :hoge
82   end
83 end
84 EOS
85   lib.flush
86
87   script = Tempfile.new('test.rb')
88   script.write <<EOS
89 print Hoge.new.hoge
90 EOS
91   script.flush
92   assert_equal 'hoge', `#{cmd('mruby')} -r #{lib.path} #{script.path}`
93   assert_equal 0, $?.exitstatus
94
95   assert_equal 'hogeClass', `#{cmd('mruby')} -r #{lib.path} -r #{script.path} -e #{shellquote('print Hoge.class')}`
96   assert_equal 0, $?.exitstatus
97 end