Added pendantic option to validate-strings-file command and hid errors for keys without tags behind it.
This commit is contained in:
parent
cb285dfc32
commit
1d4e0aeb9b
4 changed files with 28 additions and 12 deletions
|
@ -89,6 +89,9 @@ module Twine
|
|||
end
|
||||
options[:output_encoding] = e
|
||||
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
|
||||
opts.on('-h', '--help', 'Show this message.') do |h|
|
||||
puts opts.help
|
||||
exit
|
||||
|
|
|
@ -179,10 +179,12 @@ module Twine
|
|||
errors << "Found duplicate string key(s):\n#{join_keys.call(duplicate_keys)}"
|
||||
end
|
||||
|
||||
if keys_without_tags.length == total_strings
|
||||
errors << "None of your strings have tags."
|
||||
elsif keys_without_tags.length > 0
|
||||
errors << "Found strings without tags:\n#{join_keys.call(keys_without_tags)}"
|
||||
if @options[:pedantic]
|
||||
if keys_without_tags.length == total_strings
|
||||
errors << "None of your strings have tags."
|
||||
elsif keys_without_tags.length > 0
|
||||
errors << "Found strings without tags:\n#{join_keys.call(keys_without_tags)}"
|
||||
end
|
||||
end
|
||||
|
||||
unless invalid_keys.empty?
|
||||
|
|
|
@ -21,6 +21,11 @@ class CLITestCase < TwineTestCase
|
|||
assert_equal @strings_file_path, @options[:strings_file]
|
||||
end
|
||||
|
||||
def test_pedantic
|
||||
parse "validate-strings-file #{@strings_file_path} --pedantic"
|
||||
assert @options[:pedantic]
|
||||
end
|
||||
|
||||
def test_missing_parameter
|
||||
assert_raises Twine::Error do
|
||||
parse 'validate-strings-file'
|
||||
|
|
|
@ -37,14 +37,6 @@ class TestValidateStringsFile < CommandTestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_reports_missing_tags
|
||||
random_row.tags.clear
|
||||
|
||||
assert_raises Twine::Error do
|
||||
Twine::Runner.new(@options, @twine_file).validate_strings_file
|
||||
end
|
||||
end
|
||||
|
||||
def test_reports_invalid_characters_in_keys
|
||||
random_row.key[0] = "!?;:,^`´'\"\\|/(){}[]~-+*=#$%".chars.to_a.sample
|
||||
|
||||
|
@ -52,4 +44,18 @@ class TestValidateStringsFile < CommandTestCase
|
|||
Twine::Runner.new(@options, @twine_file).validate_strings_file
|
||||
end
|
||||
end
|
||||
|
||||
def test_does_not_reports_missing_tags_by_default
|
||||
random_row.tags.clear
|
||||
|
||||
Twine::Runner.new(@options, @twine_file).validate_strings_file
|
||||
end
|
||||
|
||||
def test_reports_missing_tags
|
||||
random_row.tags.clear
|
||||
|
||||
assert_raises Twine::Error do
|
||||
Twine::Runner.new(@options.merge(pedantic: true), @twine_file).validate_strings_file
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Reference in a new issue