diff options
author | Sebastian Ludwig <sebastian@lurado.de> | 2016-02-28 07:28:48 +0300 |
---|---|---|
committer | Sebastian Ludwig <sebastian@lurado.de> | 2016-02-28 18:14:25 +0300 |
commit | 430bc1bac21025772786c803da5450a5e67ec072 (patch) | |
tree | 4ae97323f13c833f765bb6c0a4912577bfee3c31 | |
parent | 1e63a8986007dfd5cb7c0423a00fac8c57d8095a (diff) |
Raising an error if generate_string_file would create an empty file.
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | lib/twine/runner.rb | 2 | ||||
-rw-r--r-- | test/test_generate_string_file.rb | 9 |
3 files changed, 12 insertions, 1 deletions
@@ -100,7 +100,7 @@ If you would like to enable twine to create language files in another format, cr #### `generate-string-file` -This command creates an Apple or Android strings file from the master strings data file. +This command creates an Apple or Android strings file from the master strings data file. If the output file would not contain any translations, twine will exit with an error. $ twine generate-string-file /path/to/strings.txt values-ja.xml --tags common,app1 $ twine generate-string-file /path/to/strings.txt Localizable.strings --lang ja --tags mytag diff --git a/lib/twine/runner.rb b/lib/twine/runner.rb index 17b68ce..e87432e 100644 --- a/lib/twine/runner.rb +++ b/lib/twine/runner.rb @@ -51,6 +51,8 @@ module Twine formatter, lang = prepare_read_write(@options[:output_path], lang) output = formatter.format_file(lang) + raise Twine::Error.new "Nothing to generate! The resulting file would not contain any strings." unless output + IO.write(@options[:output_path], output, encoding: encoding) end diff --git a/test/test_generate_string_file.rb b/test/test_generate_string_file.rb index a9efe55..d6d3835 100644 --- a/test/test_generate_string_file.rb +++ b/test/test_generate_string_file.rb @@ -49,6 +49,15 @@ class TestGenerateStringFile < CommandTestCase new_runner(nil, "#{random_language}.xml").generate_string_file end + def test_returns_error_if_nothing_written + formatter = prepare_mock_formatter Twine::Formatters::Android + formatter.expects(:format_file).returns(false) + + assert_raises Twine::Error do + new_runner('fr', 'fr.xml').generate_string_file + end + end + class TestValidate < CommandTestCase def new_runner(validate) options = {} |