Skip to content

Commit f6ed836

Browse files
committed
Start migrating to test-unit from rspec
1 parent a5f4233 commit f6ed836

File tree

5 files changed

+119
-19
lines changed

5 files changed

+119
-19
lines changed

Rakefile

Lines changed: 61 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,73 @@
1-
require "bundler"
2-
Bundler::GemHelper.install_tasks
1+
require "bundler/gem_helper"
2+
require "rake/clean"
33

4-
require "rake"
5-
require "rake/extensiontask"
6-
require "rspec/core/rake_task"
4+
base_dir = File.join(File.dirname(__FILE__))
5+
6+
helper = Bundler::GemHelper.new(base_dir)
7+
helper.install
8+
spec = helper.gemspec
9+
10+
def run_extconf(build_dir, extension_dir, *arguments)
11+
cd(build_dir) do
12+
ruby(File.join(extension_dir, "extconf.rb"), *arguments)
13+
end
14+
end
715

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

10-
gem_spec = eval(File.read('pycall.gemspec'))
11-
Rake::ExtensionTask.new('pycall', gem_spec) do |ext|
12-
ext.lib_dir = File.join(*['lib', ENV['FAT_DIR']].compact)
13-
ext.cross_compile = true
14-
ext.cross_platform = %w[x86-mingw32 x64-mingw32]
15-
ext.cross_compiling do |s|
16-
s.files.concat %w[lib/2.2/pycall.so lib/2.3/pycall.so lib/2.4/pycall.so]
18+
spec.extensions.each do |extension|
19+
extension_dir = File.join(base_dir, File.dirname(extension))
20+
build_dir = ENV["BUILD_DIR"]
21+
if build_dir
22+
build_dir = File.join(build_dir, "pycall")
23+
directory build_dir
24+
else
25+
build_dir = extension_dir
26+
end
27+
28+
makefile = File.join(build_dir, "Makefile")
29+
file makefile => build_dir do
30+
run_extconf(build_dir, extension_dir)
31+
end
32+
33+
CLOBBER << makefile
34+
CLOBBER << File.join(build_dir, "mkmf.log")
35+
36+
desc "Configure"
37+
task configure: makefile
38+
39+
desc "Compile"
40+
task compile: makefile do
41+
cd(build_dir) do
42+
sh("make")
43+
end
44+
end
45+
46+
task :clean do
47+
cd(build_dir) do
48+
sh("make", "clean") if File.exist?("Makefile")
49+
end
1750
end
1851
end
1952

20-
Rake::ExtensionTask.new('pycall/spec_helper')
53+
require "rake/extensiontask"
54+
Rake::ExtensionTask.new("pycall/spec_helper")
2155

22-
desc "Compile binaries for mingw platform using rake-compiler-dock"
23-
task 'build:mingw' do
24-
require 'rake_compiler_dock'
25-
RakeCompilerDock.sh "bundle && rake cross native gem RUBY_CC_VERSION=2.1.6:2.2.2:2.3.0:2.4.0"
56+
desc "Run tests"
57+
task :test do
58+
cd(base_dir) do
59+
ruby("test/run-test.rb")
60+
end
2661
end
2762

28-
RSpec::Core::RakeTask.new(:spec)
63+
task default: :test
64+
65+
require "rspec/core/rake_task"
66+
RSpec::Core::RakeTask.new(:spec) do |t|
67+
ext_dir = File.join(base_dir, "ext/pycall")
68+
t.ruby_opts = "-I#{ext_dir}"
69+
t.verbose = true
70+
end
2971

30-
task :default => :spec
72+
task default: :spec
3173
task spec: :compile

pycall.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ Gem::Specification.new do |spec|
4444
spec.add_development_dependency "launchy"
4545
spec.add_development_dependency "pry"
4646
spec.add_development_dependency "pry-byebug"
47+
spec.add_development_dependency "test-unit"
4748
end

test/helper.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
require "pycall"
2+
require "test-unit"

test/run-test.rb

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env ruby
2+
3+
$VERBOSE = true
4+
5+
require "fileutils"
6+
require "pathname"
7+
8+
base_dir = Pathname.new(__dir__).parent.expand_path
9+
10+
lib_dir = base_dir + "lib"
11+
ext_dir = base_dir + "ext" + "pycall"
12+
test_dir = base_dir + "test"
13+
14+
build_dir = ENV["BUILD_DIR"]
15+
if build_dir
16+
build_dir = File.join(build_dir, "memory-view-test-helper")
17+
FileUtils.mkdir_p(build_dir)
18+
else
19+
build_dir = ext_dir
20+
end
21+
22+
make = nil
23+
if ENV["NO_MAKE"] != "yes"
24+
if ENV["MAKE"]
25+
make = ENV["MAKE"]
26+
elsif system("which gmake > #{File::NULL} 2>&1")
27+
make = "gmake"
28+
elsif system("which make > #{File::NULL} 2>&1")
29+
make = "make"
30+
end
31+
end
32+
if make
33+
Dir.chdir(build_dir.to_s) do
34+
unless File.exist?("Makefile")
35+
system(RbConfig.ruby,
36+
(ext_dir + "extconf.rb").to_s,
37+
"--enable-debug-build") or exit(false)
38+
end
39+
system(make) or exit(false)
40+
end
41+
end
42+
43+
$LOAD_PATH.unshift(build_dir.to_s)
44+
$LOAD_PATH.unshift(lib_dir.to_s)
45+
46+
require_relative "helper"
47+
48+
ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "10000"
49+
50+
exit(Test::Unit::AutoRunner.run(true, test_dir.to_s))

test/test-pycall.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class PyCallTest < Test::Unit::TestCase
2+
def test_VERSION
3+
assert_not_nil(PyCall::VERSION)
4+
end
5+
end

0 commit comments

Comments
 (0)