Ruby: generate tests for cmdline

This commit is contained in:
Alex Kotov 2022-06-08 02:23:13 +03:00
parent 619f7004e0
commit 51df4b9c20
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
2 changed files with 23 additions and 0 deletions

View File

@ -42,6 +42,10 @@ RSpec/FilePath:
RSpec/ExampleLength:
CountAsOne: ['array', 'hash', 'heredoc']
Security/Eval:
Exclude:
- 'spec/**/*_spec.rb'
Style/AndOr:
EnforcedStyle: conditionals

View File

@ -90,4 +90,23 @@ KernAux::Version.supports_cmdline? and RSpec.describe KernAux, '.cmdline' do
raise_error described_class::CmdlineError, 'buffer overflow'
end
end
context 'using common tests' do
cmdline_yml = File.expand_path('../../../../../common/cmdline.yml', __dir__)
YAML.safe_load_file(cmdline_yml).each do |test|
next unless test['argv_count_max'].nil? && test['buffer_size'].nil?
escape_str = lambda do |str|
eval "\"#{str}\"", binding, __FILE__, __LINE__ # "str"
end
cmdline = escape_str.call test['cmdline']
result = test['result'].map(&escape_str)
it "transforms #{cmdline.inspect} to #{result.inspect}" do
expect(described_class.cmdline(cmdline)).to eq result
end
end
end
end