Added validate option to validate a strings file before generating any output.

This commit is contained in:
Sebastian Ludwig 2016-02-16 12:56:42 -06:00
parent 1d4e0aeb9b
commit 689ad2cd72
6 changed files with 117 additions and 0 deletions

View file

@ -89,6 +89,9 @@ module Twine
end
options[:output_encoding] = e
end
opts.on('--validate', 'Validate the strings file before formatting it') do
options[:validate] = true
end
opts.on('-p', '--pedantic', 'When validating a strings file, perform additional checks that go beyond pure validity (like presence of tags)') do
options[:pedantic] = true
end

View file

@ -43,6 +43,8 @@ module Twine
end
def generate_string_file
validate_strings_file if @options[:validate]
lang = nil
lang = @options[:languages][0] if @options[:languages]
@ -50,6 +52,8 @@ module Twine
end
def generate_all_string_files
validate_strings_file if @options[:validate]
if !File.directory?(@options[:output_path])
if @options[:create_folders]
FileUtils.mkdir_p(@options[:output_path])
@ -99,6 +103,8 @@ module Twine
end
def generate_loc_drop
validate_strings_file if @options[:validate]
require_rubyzip
if File.file?(@options[:output_path])

View file

@ -54,6 +54,11 @@ class CLITestCase < TwineTestCase
end
end
def test_validate
parse "generate-string-file #{@strings_file_path} #{@output_path} --validate"
assert @options[:validate]
end
def test_extra_parameter
assert_raises Twine::Error do
parse 'generate-string-file strings output extra'
@ -82,6 +87,11 @@ class CLITestCase < TwineTestCase
end
end
def test_validate
parse "generate-all-string-files #{@strings_file_path} #{@output_dir} --validate"
assert @options[:validate]
end
def test_extra_parameter
assert_raises Twine::Error do
parse "generate-all-string-files strings output extra"
@ -154,6 +164,11 @@ class CLITestCase < TwineTestCase
end
end
def test_validate
parse "generate-loc-drop #{@strings_file_path} #{@output_path} --format apple --validate"
assert @options[:validate]
end
def test_extra_parameter
assert_raises Twine::Error do
parse "generate-loc-drop strings output extra --format apple"

View file

@ -41,4 +41,36 @@ class TestGenerateAllStringFiles < CommandTestCase
assert File.exists?(File.join(@output_dir, 'es.lproj')), "language folder 'es.lproj' should be created"
end
end
class TestDeliberate < CommandTestCase
def new_runner(validate)
Dir.mkdir File.join @output_dir, 'values-en'
options = {}
options[:output_path] = @output_dir
options[:format] = 'android'
options[:validate] = validate
twine_file = build_twine_file 'en' do
add_section 'Section' do
add_row key: 'value'
add_row key: 'value'
end
end
Twine::Runner.new(options, twine_file)
end
def test_does_not_validate_strings_file
prepare_mock_formatter Twine::Formatters::Android
new_runner(false).generate_all_string_files
end
def test_validates_strings_file_if_validate
assert_raises Twine::Error do
new_runner(true).generate_all_string_files
end
end
end
end

View file

@ -41,4 +41,34 @@ class TestGenerateLocDrop < CommandTestCase
@runner.generate_loc_drop
end
class TestDeliberate < CommandTestCase
def new_runner(validate)
options = {}
options[:output_path] = @output_path
options[:format] = 'android'
options[:validate] = validate
twine_file = build_twine_file 'en' do
add_section 'Section' do
add_row key: 'value'
add_row key: 'value'
end
end
Twine::Runner.new(options, twine_file)
end
def test_does_not_validate_strings_file
prepare_mock_formatter Twine::Formatters::Android
new_runner(false).generate_loc_drop
end
def test_validates_strings_file_if_validate
assert_raises Twine::Error do
new_runner(true).generate_loc_drop
end
end
end
end

View file

@ -48,4 +48,35 @@ class TestGenerateStringFile < CommandTestCase
new_runner(nil, "#{random_language}.xml").generate_string_file
end
class TestDeliberate < CommandTestCase
def new_runner(validate)
options = {}
options[:output_path] = @output_path
options[:languages] = ['en']
options[:format] = 'android'
options[:validate] = validate
twine_file = build_twine_file 'en' do
add_section 'Section' do
add_row key: 'value'
add_row key: 'value'
end
end
Twine::Runner.new(options, twine_file)
end
def test_does_not_validate_strings_file
prepare_mock_formatter Twine::Formatters::Android
new_runner(false).generate_string_file
end
def test_validates_strings_file_if_validate
assert_raises Twine::Error do
new_runner(true).generate_string_file
end
end
end
end