Skip to content

Commit

Permalink
Merge pull request #1095 from presidentbeef/friendlier_tests
Browse files Browse the repository at this point in the history
Friendlier tests
  • Loading branch information
presidentbeef committed Sep 18, 2017
2 parents 6678262 + d282d68 commit 85261d0
Show file tree
Hide file tree
Showing 34 changed files with 67 additions and 19 deletions.
9 changes: 7 additions & 2 deletions Rakefile
@@ -1,3 +1,8 @@
task :default do
sh "ruby test/test.rb --pride"
require 'bundler/setup'
require 'rake/testtask'

Rake::TestTask.new do |t|
t.pattern = 'test/tests/*.rb'
end

task default: :test
12 changes: 10 additions & 2 deletions test/README.md
@@ -1,9 +1,17 @@
## Testing

Run `rake` or if you want to avoid bundler `cd test && ruby test.rb`.
Run `bundle` then `rake` or if you want to avoid bundler `ruby test/test.rb`.

This runs Brakeman against full apps in the `apps` directory and checks the results against what is expected.

## Test Generation

Run `cd test && ruby to_test.rb apps/some_app > tests/test_some_app.rb` to generate a test suite with tests for each warning reported.
Run `cd test && ruby to_test.rb apps/some_app > tests/some_app.rb` to generate a test suite with tests for each warning reported.

## Single File

Run `ruby test/tests/some_file.rb` to run a single file of tests.

## Single Test

Ruby `ruby test/test.rb --name test_something` to run a single test.
13 changes: 9 additions & 4 deletions test/test.rb
@@ -1,6 +1,8 @@
#Set paths
TEST_PATH = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift "#{TEST_PATH}/../lib"
unless defined? TEST_PATH
TEST_PATH = File.expand_path(File.dirname(__FILE__))
$LOAD_PATH.unshift "#{TEST_PATH}/../lib"
end

begin
require 'simplecov'
Expand All @@ -13,6 +15,7 @@
require 'brakeman'
require 'brakeman/scanner'
require 'minitest/autorun'
require 'minitest/pride'

class Minitest::Test
def assert_nothing_raised *args
Expand Down Expand Up @@ -257,6 +260,8 @@ def assert_new expected, diff = @diff
end
end

Dir.glob "#{TEST_PATH}/tests/*.rb" do |file|
require file
if __FILE__ == $0
Dir.glob "#{TEST_PATH}/tests/*.rb" do |file|
require file
end
end
2 changes: 2 additions & 0 deletions test/tests/alias_processor.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class AliasProcessorTests < Minitest::Test
def assert_alias expected, original, full = false
original_sexp = RubyParser.new.parse original
Expand Down
1 change: 1 addition & 0 deletions test/tests/brakeman.rb
@@ -1,4 +1,5 @@
require 'tempfile'
require_relative '../test'

class BrakemanTests < Minitest::Test
def test_exception_on_no_application
Expand Down
1 change: 1 addition & 0 deletions test/tests/call_index.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/processors/lib/find_all_calls'

class CallIndexTests < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/tests/codeclimate_output.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class TestCodeClimateOutput < Minitest::Test
def setup
@@report ||= Brakeman.run("#{TEST_PATH}/apps/rails2").report.to_codeclimate
Expand Down
1 change: 1 addition & 0 deletions test/tests/commandline.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/commandline'

class CLExit < StandardError
Expand Down
2 changes: 2 additions & 0 deletions test/tests/constants.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class ConstantTests < Minitest::Test
def setup
@constants = Brakeman::Constants.new
Expand Down
1 change: 1 addition & 0 deletions test/tests/cves.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/rescanner'

class CVETests < Minitest::Test
Expand Down
1 change: 1 addition & 0 deletions test/tests/differ.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/differ'

class DifferTests < Minitest::Test
Expand Down
1 change: 1 addition & 0 deletions test/tests/find_return_value.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/processors/lib/find_return_value'

class FindReturnValueTests < Minitest::Test
Expand Down
1 change: 1 addition & 0 deletions test/tests/json_compare.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'json'

class JSONCompareTests < Minitest::Test
Expand Down
1 change: 1 addition & 0 deletions test/tests/json_output.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'json'

class JSONOutputTests < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/tests/markdown_output.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class TestMarkdownOutput < Minitest::Test
def setup
@@report ||= Brakeman.run(
Expand Down
2 changes: 2 additions & 0 deletions test/tests/mass_assign_disable.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class MassAssignDisableTest < Minitest::Test
include BrakemanTester::RescanTestHelper

Expand Down
2 changes: 1 addition & 1 deletion test/tests/only_files_option.rb
@@ -1,4 +1,4 @@
abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class OnlyFilesOptionTests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
1 change: 1 addition & 0 deletions test/tests/options.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/options'

class BrakemanOptionsTest < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/tests/output_processor.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class OutputProcessorTests < Minitest::Test
def assert_output expected, original
output = Brakeman::OutputProcessor.new.format original
Expand Down
4 changes: 2 additions & 2 deletions test/tests/rails2.rb
@@ -1,9 +1,9 @@
# NOTE: Please do not add any further tests to the Rails 2 application unless
# the issue being tested specifically applies to Rails 2 and not the other
# versions.
# If possible, please use the rails3, rails3.1, or rails4 apps.
# If possible, please use the rails5 app.

abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class Rails2Tests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
2 changes: 1 addition & 1 deletion test/tests/rails3.rb
@@ -1,4 +1,4 @@
abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class Rails3Tests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
2 changes: 1 addition & 1 deletion test/tests/rails31.rb
@@ -1,4 +1,4 @@
abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class Rails31Tests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
4 changes: 2 additions & 2 deletions test/tests/rails32.rb
@@ -1,9 +1,9 @@
# NOTE: Please do not add any further tests to the Rails 3.2 application unless
# the issue being tested specifically applies to Rails 3.2 and not the other
# versions.
# If possible, please use the rails3, rails3.1, or rails4 apps.
# If possible, please use the rails5 app.

abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class Rails32Tests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
2 changes: 1 addition & 1 deletion test/tests/rails4.rb
@@ -1,4 +1,4 @@
abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class Rails4Tests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
2 changes: 1 addition & 1 deletion test/tests/rails4_with_engines.rb
@@ -1,4 +1,4 @@
abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class Rails4WithEnginesTests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
2 changes: 1 addition & 1 deletion test/tests/rails5.rb
@@ -1,4 +1,4 @@
abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class Rails5Tests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
1 change: 1 addition & 0 deletions test/tests/rails_lts.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/rescanner'

class RailsLTSTests < Minitest::Test
Expand Down
2 changes: 1 addition & 1 deletion test/tests/rails_with_xss_plugin.rb
@@ -1,4 +1,4 @@
abort "Please run using test/test.rb" unless defined? BrakemanTester
require_relative '../test'

class RailsWithXssPluginTests < Minitest::Test
include BrakemanTester::FindWarning
Expand Down
2 changes: 2 additions & 0 deletions test/tests/render_path.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class RenderPathTests < Minitest::Test
def setup
@r = Brakeman::RenderPath.new
Expand Down
1 change: 1 addition & 0 deletions test/tests/report_generation.rb
@@ -1,4 +1,5 @@
require 'json'
require_relative '../test'

class TestReportGeneration < Minitest::Test
def setup
Expand Down
1 change: 1 addition & 0 deletions test/tests/rescanner.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'tmpdir'
require 'brakeman/rescanner'

Expand Down
1 change: 1 addition & 0 deletions test/tests/sexp.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/processors/base_processor'

class SexpTests < Minitest::Test
Expand Down
2 changes: 2 additions & 0 deletions test/tests/tabs_output.rb
@@ -1,3 +1,5 @@
require_relative '../test'

class TestTabsOutput < Minitest::Test
def setup
@@report ||= Brakeman.run(
Expand Down
1 change: 1 addition & 0 deletions test/tests/warning.rb
@@ -1,3 +1,4 @@
require_relative '../test'
require 'brakeman/warning'

class WarningTests < Minitest::Test
Expand Down

0 comments on commit 85261d0

Please sign in to comment.