Skip to content

Commit

Permalink
add rubocop security test on emitted code
Browse files Browse the repository at this point in the history
  • Loading branch information
flavorjones committed Aug 6, 2019
1 parent 003297e commit 080b2fe
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Hoe.spec 'rexical' do
self.history_file = 'CHANGELOG.rdoc'
developer('Aaron Patterson', 'aaronp@rubyforge.org')
self.extra_rdoc_files = FileList['*.rdoc']
self.extra_dev_deps += [
["rubocop", "~> 0.74.0"]
]
end

namespace :gem do
Expand Down
24 changes: 24 additions & 0 deletions test/test_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require 'tempfile'
require 'rexical'
require 'stringio'
require 'open3'

class TestGenerator < Minitest::Test
def test_header_is_written_after_module
Expand All @@ -26,6 +27,29 @@ def test_header_is_written_after_module
assert_equal '#++', comments.last
end

def test_rubocop_security
rex = Rexical::Generator.new(
"--independent" => true
)
rex.grammar_file = File.join File.dirname(__FILE__), 'assets', 'test.rex'
rex.read_grammar
rex.parse

output = Tempfile.new(["rex_output", ".rb"])
begin
rex.write_scanner output
output.close

stdin, stdoe, wait_thr = Open3.popen2e "rubocop --only Security #{output.path}"
if ! wait_thr.value.success?
fail stdoe.read
end
ensure
output.close
output.unlink
end
end

def test_read_non_existent_file
rex = Rexical::Generator.new(nil)
rex.grammar_file = 'non_existent_file'
Expand Down

0 comments on commit 080b2fe

Please sign in to comment.