test_bisect 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in test_bisect.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jon Guymon
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # TestBisect
2
+
3
+ Don't you just hate this?
4
+
5
+ $ rake test TEST=some_test.rb
6
+ .
7
+ 1 test, 2 assertions, 0 failures, 0 errors
8
+ 100% passed
9
+
10
+ $ rake test
11
+ ....F..
12
+ 7 tests, 14 assertions, 1 failure, 0 errors
13
+ 93% passed
14
+
15
+ By using TestBisect you can search through your test suite to find out which leaky test is causing the failure.
16
+
17
+ ## Installation
18
+
19
+ Add this line to your application's Gemfile:
20
+
21
+ gem 'test_bisect'
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install test_bisect
30
+
31
+ ## Usage
32
+
33
+ Add this to your Rakefile or tests.rake:
34
+
35
+ namespace :test do
36
+ TestBisect::BisectTask.new
37
+ end
38
+
39
+ And now, to find which leaky test file is causing, eg. some_test.rb to fail, you can do:
40
+
41
+ rake test:bisect[test/some_test.rb]
42
+
43
+ It will do a binary search through your test files until it finds one (or more) that cause your test/some_test.rb to fail.
44
+
45
+ ## Contributing
46
+
47
+ 1. Fork it
48
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
49
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
50
+ 4. Push to the branch (`git push origin my-new-feature`)
51
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ module TestBisect
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+ require 'rake/tasklib'
3
+
4
+ module TestBisect
5
+ class BisectTask < Rake::TaskLib
6
+ attr_accessor :name
7
+
8
+ # We assume the task used to run the tests is "test" but if not,
9
+ # specify here
10
+ attr_accessor :test_task_name
11
+
12
+ # We try to get the list of suspects from the test task, but they
13
+ # can be manually specified here
14
+ attr_accessor :suspects
15
+
16
+ # Create a test bisect task
17
+ # if the test task which runs the tests is not "test" then specify
18
+ # is as the second arg.
19
+ def initialize(name=:bisect)
20
+ @name = name
21
+ @test_task_name = :test
22
+ # might as well take the last one
23
+ ObjectSpace.each_object(Rake::TestTask) do |obj|
24
+ @test_task = obj if obj != self
25
+ end
26
+ @suspects = @test_task.instance_variable_get(:@test_files) || []
27
+ @suspects += FileList[@test_task.pattern]
28
+ yield self if block_given?
29
+ define
30
+ end
31
+
32
+ def define
33
+ desc "Bisect test suite files to find file which makes victim fail"
34
+ task @name, [:victim] do |task, args|
35
+ @test_task.pattern = nil
36
+ criminal = bisect(@suspects, args.victim)
37
+ puts "FOUND: #{criminal}"
38
+ end
39
+ self
40
+ end
41
+
42
+ def bisect(suspects, victim)
43
+ return suspects[0] if suspects.size == 1
44
+
45
+ pivot = suspects.size / 2
46
+ suspects.partition {|file| suspects.index(file) < pivot }.each do |part|
47
+ begin
48
+ @test_task.test_files = part
49
+ Rake::Task[@test_task_name].reenable
50
+ Rake::Task[@test_task_name].invoke
51
+ puts "------ PASSED -------"
52
+ next
53
+ rescue RuntimeError => e
54
+ if e.message =~ /Command failed with status/
55
+ puts "------ FAILED -------"
56
+ return bisect(part, victim)
57
+ else
58
+ raise
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'test_bisect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "test_bisect"
8
+ spec.version = TestBisect::VERSION
9
+ spec.authors = ["Jon Guymon"]
10
+ spec.email = ["jon@newrelic.com"]
11
+ spec.description = %q{If a leaky test is causing an unrelated test to fail, "rake test:bisect[victim]" will search though your test suite until it finds the leaky test that is causing the victim to fail.}
12
+ spec.summary = %q{Rake task to binary search through your test for leaky tests}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: test_bisect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jon Guymon
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: If a leaky test is causing an unrelated test to fail, "rake test:bisect[victim]"
47
+ will search though your test suite until it finds the leaky test that is causing
48
+ the victim to fail.
49
+ email:
50
+ - jon@newrelic.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - lib/test_bisect.rb
61
+ - lib/test_bisect/version.rb
62
+ - test_bisect.gemspec
63
+ homepage: ''
64
+ licenses:
65
+ - MIT
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ! '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 1.8.23
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Rake task to binary search through your test for leaky tests
88
+ test_files: []