[rubygems/rubygems] Use a constant empty tar header to avoid extra allocations
[ruby.git] / test / dtrace / test_array_create.rb
blob1bf20085bae3a2bee7e1b0d4380905d65f357620
1 # frozen_string_literal: false
2 require_relative 'helper'
4 module DTrace
5   class TestArrayCreate < TestCase
6     def test_lit
7       trap_probe(probe, '[]') { |_,rbfile,saw|
8         saw = saw.map(&:split).find_all { |num, file, line|
9           file == rbfile && num == '0'
10         }
11         assert_equal([rbfile], saw.map { |line| line[1] })
12         assert_equal(['1'], saw.map { |line| line[2] })
13       }
14     end
16     def test_many_lit
17       trap_probe(probe, '[1,2,3,4]') { |_,rbfile,orig|
18         saw = orig.map(&:split).find_all { |num, file, line|
19           file == rbfile && num == '4' && line == '1'
20         }
21         assert_operator saw.length, :>, 0, orig
22       }
23     end
25     private
26     def probe type = 'array'
27       <<-eoprobe
28 ruby$target:::#{type}-create
29 /arg1 && arg2/
31   printf("%d %s %d\\n", arg0, copyinstr(arg1), arg2);
33       eoprobe
34     end
35   end
36 end if defined?(DTrace::TestCase)