diff --git a/lib/twine/runner.rb b/lib/twine/runner.rb index fab6d18..bd1aca4 100644 --- a/lib/twine/runner.rb +++ b/lib/twine/runner.rb @@ -197,6 +197,7 @@ module Twine raise Twine::Error.new("File does not exist: #{@options[:input_path]}") end + error_encountered = false Dir.mktmpdir do |temp_dir| Zip::File.open(@options[:input_path]) do |zipfile| zipfile.each do |entry| @@ -209,6 +210,7 @@ module Twine read_localization_file(real_path) rescue Twine::Error => e Twine::stderr.puts "#{e.message}" + error_encountered = true end end end @@ -216,6 +218,10 @@ module Twine output_path = @options[:output_path] || @options[:twine_file] write_twine_data(output_path) + + if error_encountered + raise Twine::Error.new("At least one file could not be consumed") + end end def validate_twine_file diff --git a/test/fixtures/consume_localization_archive.zip b/test/fixtures/consume_localization_archive.zip index 5efca14..44619c8 100644 Binary files a/test/fixtures/consume_localization_archive.zip and b/test/fixtures/consume_localization_archive.zip differ diff --git a/test/test_consume_localization_archive.rb b/test/test_consume_localization_archive.rb index 21ac4ef..84280b4 100644 --- a/test/test_consume_localization_archive.rb +++ b/test/test_consume_localization_archive.rb @@ -4,24 +4,30 @@ class TestConsumeLocalizationArchive < CommandTest def setup super - options = {} - options[:input_path] = fixture_path 'consume_localization_archive.zip' - options[:output_path] = @output_path - options[:format] = 'apple' - @twine_file = build_twine_file 'en', 'es' do add_section 'Section' do add_definition key1: 'value1' end end + end - @runner = Twine::Runner.new(options, @twine_file) + def new_runner(options = {}) + options[:input_path] = fixture_path 'consume_localization_archive.zip' + options[:output_path] = @output_path + + Twine::Runner.new(options, @twine_file) end def test_consumes_zip_file - @runner.consume_localization_archive + new_runner(format: 'android').consume_localization_archive assert @twine_file.definitions_by_key['key1'].translations['en'], 'value1-english' assert @twine_file.definitions_by_key['key1'].translations['es'], 'value1-spanish' end + + def test_raises_error_if_format_ambiguous + assert_raises Twine::Error do + new_runner.consume_localization_archive + end + end end