Skip to content

Commit

Permalink
Fix rubocop lints
Browse files Browse the repository at this point in the history
  • Loading branch information
mschwager committed Jan 23, 2024
1 parent 03332f8 commit 2c9e3f8
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
10 changes: 6 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
require "rake/testtask"
require "rake/extensiontask"
# frozen_string_literal: true

require 'rake/testtask'
require 'rake/extensiontask'

Rake::TestTask.new do |t|
t.verbose = true
end

Rake::ExtensionTask.new "cruzzy" do |ext|
ext.lib_dir = "lib/cruzzy"
Rake::ExtensionTask.new 'cruzzy' do |ext|
ext.lib_dir = 'lib/cruzzy'
end
6 changes: 4 additions & 2 deletions bin/dummy.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "ruzzy"
# frozen_string_literal: true

dummy_test_one_input = lambda {|data| Ruzzy.c_dummy_test_one_input(data)}
require 'ruzzy'

dummy_test_one_input = ->(data) { Ruzzy.c_dummy_test_one_input(data) }

Ruzzy.fuzz(dummy_test_one_input)
2 changes: 2 additions & 0 deletions ext/cruzzy/extconf.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'mkmf'

create_makefile('cruzzy/cruzzy')
10 changes: 6 additions & 4 deletions lib/ruzzy.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

# A Ruby C extension fuzzer
module Ruzzy
require "cruzzy/cruzzy"
require 'cruzzy/cruzzy'

# $0 is the program name
DEFAULT_ARGS = [$0] + ARGV
DEFAULT_ARGS = [$PROGRAM_NAME] + ARGV

def fuzz(test_one_input, args = DEFAULT_ARGS)
self.c_fuzz(test_one_input, args)
c_fuzz(test_one_input, args)
end

module_function :fuzz
Expand Down
27 changes: 15 additions & 12 deletions ruzzy.gemspec
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
require "rake"
# frozen_string_literal: true

require 'rake'

Gem::Specification.new do |s|
s.name = "ruzzy"
s.version = "0.5.0"
s.summary = "A Ruby C extension fuzzer"
s.authors = ["Trail of Bits"]
s.email = "[email protected]"
s.files = FileList["lib/**/*.rb", "ext/**/*.{rb,c,h}"]
s.homepage = "https://rubygems.org/gems/ruzzy"
s.license = "AGPL-3.0"
s.extensions = %w[ext/cruzzy/extconf.rb]
s.name = 'ruzzy'
s.version = '0.5.0'
s.summary = 'A Ruby C extension fuzzer'
s.authors = ['Trail of Bits']
s.email = '[email protected]'
s.files = FileList['lib/**/*.rb', 'ext/**/*.{rb,c,h}']
s.homepage = 'https://rubygems.org/gems/ruzzy'
s.license = 'AGPL-3.0'
s.extensions = %w[ext/cruzzy/extconf.rb]
s.required_ruby_version = '>= 3.1.0'

s.add_development_dependency "rake", '~> 13.0'
s.add_development_dependency "rake-compiler", '~> 1.2'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rake-compiler', '~> 1.2'
end
18 changes: 10 additions & 8 deletions test/test_ruzzy.rb
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
require "ruzzy"
require "test/unit"
# frozen_string_literal: true

require 'ruzzy'
require 'test/unit'

class RuzzyTest < Test::Unit::TestCase
def test_c_libfuzzer_is_loaded
result = Ruzzy.c_libfuzzer_is_loaded()
result = Ruzzy.c_libfuzzer_is_loaded

assert_true(result)
end

def test_c_dummy_test_one_input_proc
dummy_test_one_input = proc {|data| Ruzzy.c_dummy_test_one_input(data)}
dummy_test_one_input = proc { |data| Ruzzy.c_dummy_test_one_input(data) }

result = dummy_test_one_input.call("test")
result = dummy_test_one_input.call('test')
expected = 0

assert_equal(result, expected)
end

def test_c_dummy_test_one_input_lambda
dummy_test_one_input = lambda {|data| Ruzzy.c_dummy_test_one_input(data)}
dummy_test_one_input = ->(data) { Ruzzy.c_dummy_test_one_input(data) }

result = dummy_test_one_input.call("test")
result = dummy_test_one_input.call('test')
expected = 0

assert_equal(result, expected)
end

def test_fuzz_without_proc
assert_raise(RuntimeError) do
Ruzzy.fuzz("not a proc")
Ruzzy.fuzz('not a proc')
end
end
end

0 comments on commit 2c9e3f8

Please sign in to comment.