lib/snapshot/runner.rb in snapshot-0.8.0 vs lib/snapshot/runner.rb in snapshot-0.9.0

- old
+ new

@@ -12,11 +12,14 @@ @app_path = determine_app_path counter = 0 errors = [] - FileUtils.rm_rf SnapshotConfig.shared_instance.screenshots_path if (SnapshotConfig.shared_instance.clear_previous_screenshots and take_snapshots) + if (SnapshotConfig.shared_instance.clear_previous_screenshots and take_snapshots) + path_to_clear = (SnapshotConfig.shared_instance.screenshots_path + "/*-*/*.png") # languages always contain a `-` + Dir[path_to_clear].each { |a| File.delete(a) } # no idea why rm_rf doesn't work + end SnapshotConfig.shared_instance.devices.each do |device| SnapshotConfig.shared_instance.languages.each do |language_item| if language_item.instance_of?String @@ -24,21 +27,24 @@ locale = language_item else (language, locale) = language_item end - reinstall_app(device, language, locale) unless ENV["SNAPSHOT_SKIP_UNINSTALL"] prepare_simulator(device, language) + + reinstall_app(device, language, locale) unless ENV["SNAPSHOT_SKIP_UNINSTALL"] begin errors.concat(run_tests(device, language, locale)) - counter += copy_screenshots(language) if take_snapshots rescue => ex Helper.log.error(ex) end + # we also want to see the screenshots when something went wrong + counter += copy_screenshots(language) if take_snapshots + teardown_simulator(device, language) break if errors.any? && ENV["SNAPSHOT_BREAK_ON_FIRST_ERROR"] end @@ -85,18 +91,19 @@ end raise "Could not find simulator '#{name}' to install the app on." end def reinstall_app(device, language, locale) + Helper.log.info "Reinstalling app...".yellow unless $verbose app_identifier = ENV["SNAPSHOT_APP_IDENTIFIER"] app_identifier ||= @app_identifier def com(cmd) - puts cmd.magenta - result = `#{cmd}` - puts result if result.to_s.length > 0 + puts cmd.magenta if $verbose + result = `#{cmd} 2>&1` # to now show errors + puts result if (result.to_s.length > 0 and $verbose) end udid = udid_for_simulator(device) @@ -159,11 +166,11 @@ end end if retry_run - Helper.log.error "Instruments tool failed again. Re-trying..." + Helper.log.error "Instruments tool failed again. Re-trying..." if $verbose sleep 2 # We need enough sleep... that's an instruments bug errors = run_tests(device, language, locale) end return errors @@ -171,19 +178,22 @@ def determine_app_path # Determine the path to the actual app and not the WatchKit app build_dir = SnapshotConfig.shared_instance.build_dir || '/tmp/snapshot' Dir.glob("#{build_dir}/**/*.app/*.plist").each do |path| - watchkit_enabled = `/usr/libexec/PlistBuddy -c 'Print WKWatchKitApp' '#{path}'`.strip + # `2>&1` to hide the error if it's not there: http://stackoverflow.com/a/4783536/445598 + watchkit_enabled = `/usr/libexec/PlistBuddy -c 'Print WKWatchKitApp' '#{path}' 2>&1`.strip next if watchkit_enabled == 'true' # we don't care about WatchKit Apps - app_identifier = `/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' '#{path}'`.strip + app_identifier = `/usr/libexec/PlistBuddy -c 'Print CFBundleIdentifier' '#{path}' 2>&1`.strip if app_identifier and app_identifier.length > 0 # This seems to be the valid Info.plist @app_identifier = app_identifier return File.expand_path("..", path) # the app end end + + raise "Could not find app in '#{build_dir}'. Make sure you're following the README and set the build directory to the correct path.".red end def parse_test_line(line) if line =~ /.*Target failed to run.*/ return :retry