Skip to content

Commit

Permalink
Start migrating to test-unit from rspec
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkn committed Mar 9, 2021
1 parent a5f4233 commit f6ed836
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 19 deletions.
80 changes: 61 additions & 19 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,73 @@
require "bundler"
Bundler::GemHelper.install_tasks
require "bundler/gem_helper"
require "rake/clean"

require "rake"
require "rake/extensiontask"
require "rspec/core/rake_task"
base_dir = File.join(File.dirname(__FILE__))

helper = Bundler::GemHelper.new(base_dir)
helper.install
spec = helper.gemspec

def run_extconf(build_dir, extension_dir, *arguments)
cd(build_dir) do
ruby(File.join(extension_dir, "extconf.rb"), *arguments)
end
end

Dir[File.expand_path('../tasks/**/*.rake', __FILE__)].each {|f| load f }

gem_spec = eval(File.read('pycall.gemspec'))
Rake::ExtensionTask.new('pycall', gem_spec) do |ext|
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
ext.cross_compile = true
ext.cross_platform = %w[x86-mingw32 x64-mingw32]
ext.cross_compiling do |s|
s.files.concat %w[lib/2.2/pycall.so lib/2.3/pycall.so lib/2.4/pycall.so]
spec.extensions.each do |extension|
extension_dir = File.join(base_dir, File.dirname(extension))
build_dir = ENV["BUILD_DIR"]
if build_dir
build_dir = File.join(build_dir, "pycall")
directory build_dir
else
build_dir = extension_dir
end

makefile = File.join(build_dir, "Makefile")
file makefile => build_dir do
run_extconf(build_dir, extension_dir)
end

CLOBBER << makefile
CLOBBER << File.join(build_dir, "mkmf.log")

desc "Configure"
task configure: makefile

desc "Compile"
task compile: makefile do
cd(build_dir) do
sh("make")
end
end

task :clean do
cd(build_dir) do
sh("make", "clean") if File.exist?("Makefile")
end
end
end

Rake::ExtensionTask.new('pycall/spec_helper')
require "rake/extensiontask"
Rake::ExtensionTask.new("pycall/spec_helper")

desc "Compile binaries for mingw platform using rake-compiler-dock"
task 'build:mingw' do
require 'rake_compiler_dock'
RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.1.6:2.2.2:2.3.0:2.4.0"
desc "Run tests"
task :test do
cd(base_dir) do
ruby("test/run-test.rb")
end
end

RSpec::Core::RakeTask.new(:spec)
task default: :test

require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec) do |t|
ext_dir = File.join(base_dir, "ext/pycall")
t.ruby_opts = "-I#{ext_dir}"
t.verbose = true
end

task :default => :spec
task default: :spec
task spec: :compile
1 change: 1 addition & 0 deletions pycall.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "launchy"
spec.add_development_dependency "pry"
spec.add_development_dependency "pry-byebug"
spec.add_development_dependency "test-unit"
end
2 changes: 2 additions & 0 deletions test/helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
require "pycall"
require "test-unit"
50 changes: 50 additions & 0 deletions test/run-test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env ruby

$VERBOSE = true

require "fileutils"
require "pathname"

base_dir = Pathname.new(__dir__).parent.expand_path

lib_dir = base_dir + "lib"
ext_dir = base_dir + "ext" + "pycall"
test_dir = base_dir + "test"

build_dir = ENV["BUILD_DIR"]
if build_dir
build_dir = File.join(build_dir, "memory-view-test-helper")
FileUtils.mkdir_p(build_dir)
else
build_dir = ext_dir
end

make = nil
if ENV["NO_MAKE"] != "yes"
if ENV["MAKE"]
make = ENV["MAKE"]
elsif system("which gmake > #{File::NULL} 2>&1")
make = "gmake"
elsif system("which make > #{File::NULL} 2>&1")
make = "make"
end
end
if make
Dir.chdir(build_dir.to_s) do
unless File.exist?("Makefile")
system(RbConfig.ruby,
(ext_dir + "extconf.rb").to_s,
"--enable-debug-build") or exit(false)
end
system(make) or exit(false)
end
end

$LOAD_PATH.unshift(build_dir.to_s)
$LOAD_PATH.unshift(lib_dir.to_s)

require_relative "helper"

ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "10000"

exit(Test::Unit::AutoRunner.run(true, test_dir.to_s))
5 changes: 5 additions & 0 deletions test/test-pycall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class PyCallTest < Test::Unit::TestCase
def test_VERSION
assert_not_nil(PyCall::VERSION)
end
end

0 comments on commit f6ed836

Please sign in to comment.