Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/twine.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Ludwig <sebastian@lurado.de>2016-02-28 07:28:48 +0300
committerSebastian Ludwig <sebastian@lurado.de>2016-02-28 18:14:25 +0300
commit430bc1bac21025772786c803da5450a5e67ec072 (patch)
tree4ae97323f13c833f765bb6c0a4912577bfee3c31
parent1e63a8986007dfd5cb7c0423a00fac8c57d8095a (diff)
Raising an error if generate_string_file would create an empty file.
-rw-r--r--README.md2
-rw-r--r--lib/twine/runner.rb2
-rw-r--r--test/test_generate_string_file.rb9
3 files changed, 12 insertions, 1 deletions
diff --git a/README.md b/README.md
index 04d3653..6834b97 100644
--- a/README.md
+++ b/README.md
@@ -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 = {}