test/test_helper.rb in ruboto-0.5.3 vs test/test_helper.rb in ruboto-0.5.4
- old
+ new
@@ -5,45 +5,38 @@
module RubotoTest
PROJECT_DIR = File.expand_path('..', File.dirname(__FILE__))
$LOAD_PATH << PROJECT_DIR
- # FIXME(uwe): Simplify when we stop supporting rubygems < 1.8.0
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0')
- gem_spec = Gem::Specification.find_by_path 'jruby-jars'
- else
- gem_spec = Gem.searcher.find('jruby-jars')
- end
- # FIXME end
-
- raise StandardError.new("Can't find Gem specification jruby-jars.") unless gem_spec
- JRUBY_JARS_VERSION = gem_spec.version
+ GEM_PATH = File.join PROJECT_DIR, 'tmp', 'gems'
+ FileUtils.mkdir_p GEM_PATH
+ ENV['GEM_HOME'] = GEM_PATH
+ ENV['GEM_PATH'] = GEM_PATH
+ system 'gem install bundler'
+ system 'bundle'
- # FIXME(uwe): Remove when we stop supporting JRuby 1.5.6
- ON_JRUBY_JARS_1_5_6 = JRUBY_JARS_VERSION == Gem::Version.new('1.5.6')
-
- PACKAGE = 'org.ruboto.test_app'
- APP_NAME = 'RubotoTestApp'
- TMP_DIR = File.join PROJECT_DIR, 'tmp'
- APP_DIR = File.join TMP_DIR, APP_NAME
+ PACKAGE = 'org.ruboto.test_app'
+ APP_NAME = 'RubotoTestApp'
+ TMP_DIR = File.join PROJECT_DIR, 'tmp'
+ APP_DIR = File.join TMP_DIR, APP_NAME
ANDROID_TARGET = ENV['ANDROID_TARGET'] || 'android-7'
VERSION_TO_API_LEVEL = {
- '2.1' => 'android-7', '2.1-update1' => 'android-7', '2.2' => 'android-8',
- '2.3' => 'android-9', '2.3.1' => 'android-9', '2.3.2' => 'android-9',
+ '2.1' => 'android-7', '2.1-update1' => 'android-7', '2.2' => 'android-8',
+ '2.3' => 'android-9', '2.3.1' => 'android-9', '2.3.2' => 'android-9',
'2.3.3' => 'android-10', '2.3.4' => 'android-10',
- '3.0' => 'android-11', '3.1' => 'android-12', '3.2' => 'android-13',
+ '3.0' => 'android-11', '3.1' => 'android-12', '3.2' => 'android-13',
'4.0.1' => 'android-14', '4.0.3' => 'android-15',
}
def self.version_from_device
puts "Reading OS version from device/emulator"
system "adb wait-for-device"
start = Time.now
IO.popen('adb bugreport').each_line do |line|
if line =~ /sdk-eng (.*?) .*? .*? test-keys/
- version = $1
+ version = $1
api_level = VERSION_TO_API_LEVEL[version]
raise "Unknown version: #{version}" if api_level.nil?
puts "Getting version from device/emulator took #{(Time.now - start).to_i}s"
return api_level
end
@@ -52,18 +45,42 @@
end
end
raise "Unable to read device/emulator apilevel"
end
+ def install_jruby_jars_gem
+ system "gem install jruby-jars #{"-v #{ENV['JRUBY_JARS_VERSION']}" if ENV['JRUBY_JARS_VERSION']}"
+ raise "install of jruby-jars failed with return code #$?" unless $? == 0
+ system %Q{gem uninstall jruby-jars --all -v "!=#{ENV['JRUBY_JARS_VERSION']}"} if ENV['JRUBY_JARS_VERSION']
+ end
+
ANDROID_OS = ENV['ANDROID_OS'] || version_from_device
RUBOTO_CMD = "ruby -rubygems -I #{PROJECT_DIR}/lib #{PROJECT_DIR}/bin/ruboto"
puts "ANDROID_OS: #{ANDROID_OS}"
end
class Test::Unit::TestCase
include RubotoTest
+ extend RubotoTest
+
+ install_jruby_jars_gem
+
+ # FIXME(uwe): Simplify when we stop supporting rubygems < 1.8.0
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.8.0')
+ gem_spec = Gem::Specification.find_by_path 'jruby-jars'
+ else
+ gem_spec = Gem.searcher.find('jruby-jars')
+ end
+ # FIXME end
+
+ raise StandardError.new("Can't find Gem specification jruby-jars.") unless gem_spec
+ JRUBY_JARS_VERSION = gem_spec.version
+
+ # FIXME(uwe): Remove when we stop supporting JRuby 1.5.6
+ ON_JRUBY_JARS_1_5_6 = JRUBY_JARS_VERSION == Gem::Version.new('1.5.6')
+
alias old_run run
def run(*args, &block)
mark_test_start("#{self.class.name}\##{method_name}")
old_run(*args, &block)
@@ -89,11 +106,11 @@
puts message
system "adb shell log -t 'RUBOTO TEST' '#{message}'"
end
def generate_app(options = {})
- update = options.delete(:update) || false
+ update = options.delete(:update) || false
excluded_stdlibs = options.delete(:excluded_stdlibs)
raise "Unknown options: #{options.inspect}" unless options.empty?
Dir.mkdir TMP_DIR unless File.exists? TMP_DIR
if excluded_stdlibs
@@ -105,15 +122,17 @@
FileUtils.rm_rf 'tmp/RubotoCore'
fail 'Error (un)installing RubotoCore'
end
FileUtils.rm_rf APP_DIR if File.exists? APP_DIR
- template_dir = "#{APP_DIR}_template_#{$$}#{'_updated' if update}#{"_without_#{excluded_stdlibs.map{|ed| ed.gsub(/[.\/]/, '_')}.join('_')}" if excluded_stdlibs}"
+ template_dir = "#{APP_DIR}_template_#{$$}#{'_updated' if update}#{"_without_#{excluded_stdlibs.map { |ed| ed.gsub(/[.\/]/, '_') }.join('_')}" if excluded_stdlibs}"
if File.exists?(template_dir)
puts "Copying app from template #{template_dir}"
FileUtils.cp_r template_dir, APP_DIR, :preserve => true
else
+ install_jruby_jars_gem
+
if update
Dir.chdir TMP_DIR do
system "tar xzf #{PROJECT_DIR}/examples/RubotoTestApp_0.1.0_jruby_1.6.3.dev.tgz"
end
if ENV['ANDROID_HOME']
@@ -127,9 +146,13 @@
exclude_stdlibs(excluded_stdlibs) if excluded_stdlibs
system "#{RUBOTO_CMD} update app"
assert_equal 0, $?, "update app failed with return code #$?"
end
else
+ unless excluded_stdlibs
+ system 'gem uninstall jruby-jars --all'
+ assert_equal 0, $?, "uninstall of jruby-jars failed with return code #$?"
+ end
puts "Generating app #{APP_DIR}"
system "#{RUBOTO_CMD} gen app --package #{PACKAGE} --path #{APP_DIR} --name #{APP_NAME} --target #{ANDROID_TARGET}"
if $? != 0
FileUtils.rm_rf APP_DIR
raise "gen app failed with return code #$?"