test/rake_test.rb in ruboto-1.4.1 vs test/rake_test.rb in ruboto-1.5.0

- old
+ new

@@ -1,6 +1,7 @@ require File.expand_path('test_helper', File.dirname(__FILE__)) +require_relative '../assets/rakelib/ruboto.device' class RakeTest < Minitest::Test def setup generate_app end @@ -18,42 +19,45 @@ test_filename = 'test/src/ruboto_test_app_activity_test.rb' s2 = File.read(test_filename) s2.gsub!(/What hath Matz wrought\?/, 'This text was changed by script!') File.open(test_filename, 'w') { |f| f << s2 } - - apk_timestamp = File.mtime("bin/#{APP_NAME}-debug.apk") end run_app_tests # FIXME(uwe): Uncomment this when we can build the test package without building the main package # assert_equal apk_timestamp, File.mtime("bin/#{APP_NAME}-debug.apk"), 'APK should not have been rebuilt' # EMXIF - assert_match %r{^/sdcard/Android/data/#{PACKAGE}/files/scripts$}, `adb shell ls -d /sdcard/Android/data/#{PACKAGE}/files/scripts`.chomp + assert_match %r{^#{scripts_path(PACKAGE)}$}, `adb shell ls -d #{scripts_path(PACKAGE)}`.chomp end + def test_that_apk_is_not_built_if_nothing_has_changed + Dir.chdir APP_DIR do + apk_timestamp = apk_mtime + system 'rake debug' + assert apk_timestamp == apk_mtime, 'APK should not have been rebuilt' + end + end + # FIXME(uwe): This is actually a case where we want to just update the Ruby # source file instead of rebuilding the apk. def test_that_apk_is_built_if_only_one_ruby_source_file_has_changed Dir.chdir APP_DIR do - apk_timestamp = File.mtime("bin/#{APP_NAME}-debug.apk") - sleep 1 - FileUtils.touch 'src/ruboto_test_app_activity.rb' - sleep 1 + apk_timestamp = apk_mtime + FileUtils.touch 'src/ruboto_test_app_activity.rb', mtime: apk_timestamp + 1 system 'rake debug' - assert apk_timestamp != File.mtime("bin/#{APP_NAME}-debug.apk"), - 'APK should have been rebuilt' + assert apk_timestamp != apk_mtime, 'APK should have been rebuilt' end end def test_that_apk_is_built_if_only_one_non_ruby_source_file_has_changed Dir.chdir APP_DIR do - apk_timestamp = File.mtime("bin/#{APP_NAME}-debug.apk") - FileUtils.touch 'src/not_ruby_source.properties' + apk_timestamp = apk_mtime + FileUtils.touch 'src/not_ruby_source.properties', mtime: apk_timestamp + 1 system 'rake debug' - assert apk_timestamp != File.mtime("bin/#{APP_NAME}-debug.apk"), + assert apk_timestamp != apk_mtime, 'APK should have been rebuilt' end end def test_that_manifest_is_updated_when_project_properties_are_changed @@ -85,8 +89,14 @@ system 'adb kill-server' system 'rake install' raise "'rake install' exited with code #$?" unless $? == 0 end system 'adb logcat >> adb_logcat.log&' if File.exists?('adb_logcat.log') + end + + private + + def apk_mtime + File.mtime("bin/#{APP_NAME}-debug.apk") end end