From 430bc1bac21025772786c803da5450a5e67ec072 Mon Sep 17 00:00:00 2001 From: Sebastian Ludwig Date: Sat, 27 Feb 2016 22:28:48 -0600 Subject: Raising an error if generate_string_file would create an empty file. --- README.md | 2 +- lib/twine/runner.rb | 2 ++ test/test_generate_string_file.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 1 deletion(-) 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 = {} -- cgit v1.2.3