Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions gems/native-tracer/codetracer-ruby-recorder.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ Gem::Specification.new do |spec|
spec.license = 'MIT'
spec.homepage = 'https://github.com/metacraft-labs/codetracer-ruby-recorder'

spec.files = Dir['lib/**/*', 'ext/native_tracer/**/{Cargo.toml,*.rs}',
'ext/native_tracer/extconf.rb', '../../README.md', '../../LICENSE']
spec.files = Dir[
'lib/**/*',
'ext/native_tracer/**/{Cargo.toml,*.rs}',
'ext/native_tracer/extconf.rb',
'ext/native_tracer/target/release/*'
]
spec.require_paths = ['lib']
spec.extensions = ['ext/native_tracer/extconf.rb']
spec.extensions = []
spec.bindir = 'bin'
spec.executables = ['codetracer-ruby-recorder']

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
spec.license = 'MIT'
spec.homepage = 'https://github.com/metacraft-labs/codetracer-ruby-recorder'

spec.files = Dir['lib/**/*', 'bin/*', '../../README.md', '../../LICENSE']
spec.files = Dir['lib/**/*', 'bin/*']
spec.require_paths = ['lib']
spec.bindir = 'bin'
spec.executables = ['codetracer-pure-ruby-recorder']
Expand Down
47 changes: 47 additions & 0 deletions test/test_tracer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
require 'json'
require 'fileutils'
require 'open3'
require 'tmpdir'

class TraceTest < Minitest::Test
TMP_DIR = File.expand_path('tmp', __dir__)
Expand Down Expand Up @@ -60,4 +61,50 @@ def program_args(base)
assert_equal expected, native_out
end
end

def test_gem_installation
Dir.chdir(File.expand_path('..', __dir__)) do
system('just', 'build-extension', exception: true)

dlext = RbConfig::CONFIG['DLEXT']
ext_path = File.join('gems', 'native-tracer', 'ext', 'native_tracer', 'target', 'release', "codetracer_ruby_recorder.#{dlext}")
FileUtils.rm_f(ext_path)

Dir.mktmpdir('gemhome') do |gem_home|
gem_build = IO.popen(%w[gem -C gems/native-tracer build codetracer-ruby-recorder.gemspec], err: [:child, :out]) { |io| io.read }
gem_file = gem_build.lines.grep(/File:/).first.split.last
gem_file = File.expand_path(File.join('gems/native-tracer', gem_file))

env = { 'GEM_HOME' => gem_home, 'GEM_PATH' => gem_home, 'PATH' => "#{gem_home}/bin:#{ENV['PATH']}" }
system(env, 'gem', 'install', '--local', gem_file, exception: true)

out_dir = File.join('test', 'tmp', 'gem_install')
FileUtils.rm_rf(out_dir)
stdout, stderr, status = Open3.capture3(env, 'ruby', '-S', 'codetracer-ruby-recorder', '--out-dir', out_dir, File.join('test', 'programs', 'addition.rb'))
raise "native_trace failed: #{stderr}" unless status.success?
assert_equal "3\n", stdout
assert File.exist?(File.join(out_dir, 'trace.json'))
end
end
end

def test_pure_gem_installation
Dir.chdir(File.expand_path('..', __dir__)) do
Dir.mktmpdir('gemhome') do |gem_home|
gem_build = IO.popen(%w[gem -C gems/pure-ruby-tracer build codetracer_pure_ruby_recorder.gemspec], err: [:child, :out]) { |io| io.read }
gem_file = gem_build.lines.grep(/File:/).first.split.last
gem_file = File.expand_path(File.join('gems/pure-ruby-tracer', gem_file))

env = { 'GEM_HOME' => gem_home, 'GEM_PATH' => gem_home, 'PATH' => "#{gem_home}/bin:#{ENV['PATH']}" }
system(env, 'gem', 'install', '--local', gem_file, exception: true)

out_dir = File.join('test', 'tmp', 'gem_install_pure')
FileUtils.rm_rf(out_dir)
stdout, stderr, status = Open3.capture3(env, 'ruby', '-S', 'codetracer-pure-ruby-recorder', '--out-dir', out_dir, File.join('test', 'programs', 'addition.rb'))
raise "pure_trace failed: #{stderr}" unless status.success?
assert_equal "3\n", stdout
assert File.exist?(File.join(out_dir, 'trace.json'))
end
end
end
end
Loading