test_diff 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Rakefile +1 -1
- data/lib/test_diff.rb +4 -0
- data/lib/test_diff/build_coverage.rb +16 -11
- data/lib/test_diff/config.rb +48 -0
- data/lib/test_diff/run_diff.rb +23 -30
- data/lib/test_diff/storage.rb +34 -0
- data/lib/test_diff/test_info.rb +26 -0
- data/lib/test_diff/test_runner/rspec.rb +18 -0
- data/lib/test_diff/test_runner/spec.rb +18 -0
- data/lib/test_diff/version.rb +1 -1
- data/lib/test_diff/version_control/git.rb +19 -0
- metadata +7 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjhjNGZlMzgzODhmN2M0ZjMxZTg5NWM5YTEyMGE4ZTMxOTZhMGQzMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NTU0N2FmM2VlOTZiOGU3MWRlMGZjZjU3YmE3YzJiZmQ3MjY4YmZhNw==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
OWZmMTEzMDdmNzcxN2UzOTc2YzdlMDg1MjdmNzVjMDFmNWQwOTg2MjA5MDJm
|
10
|
+
ZTA2MTFiNDk2MWZkZTNlZWVjMGVmNjFkODhlYjgwNGI5OGY0OTQwOTNjNGU2
|
11
|
+
M2RkMjExODFhOWU4M2IxYTgzYTk1NTY0OWJmYTcxMTdhZGRjNmE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YmJiOWY1NTIxYjA1NDYzMWZhZTY3ZTNkZjI2MDBkNWRjYjg0ZmI2YjMwNDFi
|
14
|
+
YWJmNzk2NDM2NWY1Y2IwNDAwMjRkOGI3YzZhZjZjNWVlNjI4YTc1NzljNjY4
|
15
|
+
NTJjOTIzYWUzNzg1ZDJkZGIyMTdiMjUxY2Y5OGIwNWFlMDY2M2U=
|
data/Rakefile
CHANGED
data/lib/test_diff.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
1
|
require 'test_diff/version'
|
2
2
|
require 'test_diff/storage'
|
3
|
+
require 'test_diff/test_info'
|
4
|
+
require 'test_diff/version_control/git'
|
5
|
+
require 'test_diff/test_runner/rspec'
|
6
|
+
require 'test_diff/config'
|
3
7
|
require 'test_diff/build_coverage'
|
4
8
|
require 'test_diff/run_diff'
|
5
9
|
require 'test_diff/build_coverage_diff'
|
@@ -38,7 +38,6 @@ module TestDiff
|
|
38
38
|
|
39
39
|
def run_batch
|
40
40
|
puts "Running #{@batch_queue.size} tests"
|
41
|
-
require 'spec'
|
42
41
|
timing_thread = start_timing_thread(Time.now, @batch_queue.size)
|
43
42
|
start
|
44
43
|
timing_thread.join
|
@@ -76,8 +75,10 @@ module TestDiff
|
|
76
75
|
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
|
77
76
|
Time.zone_default = (Time.zone = 'UTC') if Time.respond_to?(:zone_default) && Time.zone_default.nil?
|
78
77
|
# ARGV = ['-b',main_spec_file]
|
79
|
-
|
80
|
-
|
78
|
+
s = Time.now
|
79
|
+
result = run_tests(main_spec_file)
|
80
|
+
if result
|
81
|
+
save_coverage_data(main_spec_file, Time.now - s)
|
81
82
|
else
|
82
83
|
Coverage.result # disable coverage
|
83
84
|
exit!(false) unless @continue
|
@@ -87,17 +88,21 @@ module TestDiff
|
|
87
88
|
end
|
88
89
|
|
89
90
|
def run_tests(main_spec_file)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
if defined?(::RSpec::Core::Runner)
|
92
|
+
::RSpec::Core::Runner.run([main_spec_file], $stderr, $stdout) == 0
|
93
|
+
else
|
94
|
+
options ||= begin
|
95
|
+
parser = ::Spec::Runner::OptionParser.new($stderr, $stdout)
|
96
|
+
parser.order!(['-b', main_spec_file])
|
97
|
+
parser.options
|
98
|
+
end
|
99
|
+
Spec::Runner.use options
|
100
|
+
options.run_examples
|
94
101
|
end
|
95
|
-
Spec::Runner.use options
|
96
|
-
options.run_examples
|
97
102
|
end
|
98
103
|
|
99
|
-
def save_coverage_data(main_spec_file)
|
100
|
-
data = {}
|
104
|
+
def save_coverage_data(main_spec_file, execution_time)
|
105
|
+
data = { '__execution_time__' => execution_time }
|
101
106
|
Coverage.result.each do |file_name, stats|
|
102
107
|
relative_file_name = file_name.gsub("#{FileUtils.pwd}/", '')
|
103
108
|
if file_name.include?(FileUtils.pwd)
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
# TestDiff module
|
3
|
+
module TestDiff
|
4
|
+
# Holds all the configuration details
|
5
|
+
class Config
|
6
|
+
include Singleton
|
7
|
+
attr_accessor :working_directory, :map_subfolder,
|
8
|
+
:current_tracking_filename, :test_pattern
|
9
|
+
|
10
|
+
attr_writer :test_runner, :version_control, :storage
|
11
|
+
|
12
|
+
def initialize
|
13
|
+
self.working_directory = '.'
|
14
|
+
self.map_subfolder = 'test_diff_coverage'
|
15
|
+
self.current_tracking_filename = 'sha'
|
16
|
+
self.test_pattern = /spec.rb\z/
|
17
|
+
end
|
18
|
+
|
19
|
+
def version_control
|
20
|
+
@version_control ||= VersionControl::Git.new(working_directory,
|
21
|
+
File.read(current_tracking_file))
|
22
|
+
end
|
23
|
+
|
24
|
+
def storage
|
25
|
+
@storage ||= Storage.new(map_folder)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_runner
|
29
|
+
@test_runner ||= TestRunner::Rspec.new
|
30
|
+
end
|
31
|
+
|
32
|
+
def map_folder
|
33
|
+
"#{working_directory}/#{map_subfolder}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def current_tracking_file
|
37
|
+
"#{map_folder}/#{current_tracking_filename}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.method_missing(method, *args)
|
41
|
+
if instance.respond_to?(method)
|
42
|
+
instance.send(method, *args)
|
43
|
+
else
|
44
|
+
super
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/test_diff/run_diff.rb
CHANGED
@@ -2,13 +2,11 @@
|
|
2
2
|
module TestDiff
|
3
3
|
# Class used to calculate the tests than need to be run
|
4
4
|
class RunDiff
|
5
|
-
attr_reader :
|
5
|
+
attr_reader :tests_folder, :groups_of, :group
|
6
6
|
|
7
|
-
def initialize(
|
8
|
-
@
|
9
|
-
@
|
10
|
-
@specs_to_run = []
|
11
|
-
@storage = Storage.new
|
7
|
+
def initialize(tests_folder, groups_of, group)
|
8
|
+
@tests_folder = tests_folder
|
9
|
+
@tests_to_run = []
|
12
10
|
@groups_of = groups_of
|
13
11
|
@group = group
|
14
12
|
end
|
@@ -24,46 +22,41 @@ module TestDiff
|
|
24
22
|
private
|
25
23
|
|
26
24
|
def run_test_group
|
27
|
-
|
28
|
-
puts "bundle exec spec -fo #{@specs_to_run.join(' ')}"
|
29
|
-
exec "bundle exec spec -fo #{@specs_to_run.join(' ')}"
|
30
|
-
else
|
31
|
-
puts 'no specs found to run'
|
32
|
-
end
|
25
|
+
Config.test_runner.run_tests(@tests_to_run.map(&:filename))
|
33
26
|
end
|
34
27
|
|
35
28
|
def select_test_group
|
36
29
|
return unless groups_of
|
37
|
-
groups_size = (@
|
38
|
-
@
|
30
|
+
groups_size = (@tests_to_run.length / groups_of.to_f).ceil
|
31
|
+
@tests_to_run = @tests_to_run.slice(group.to_i * groups_size, groups_size) || []
|
39
32
|
end
|
40
33
|
|
41
34
|
def remove_tests_that_do_not_exist
|
42
|
-
@
|
43
|
-
!File.exist?(s)
|
35
|
+
@tests_to_run.delete_if do |s|
|
36
|
+
!File.exist?("#{Config.working_directory}/#{s.filename}")
|
44
37
|
end
|
45
38
|
end
|
46
39
|
|
47
40
|
def remove_tests_in_wrong_folder
|
48
|
-
@
|
49
|
-
!s.start_with?("#{
|
41
|
+
@tests_to_run.delete_if do |s|
|
42
|
+
!s.filename.start_with?("#{tests_folder}/")
|
50
43
|
end
|
51
44
|
end
|
52
45
|
|
53
46
|
def add_changed_files
|
54
|
-
|
47
|
+
_build_tests_to_run
|
55
48
|
|
56
|
-
@
|
57
|
-
@
|
58
|
-
@
|
49
|
+
@tests_to_run.flatten!
|
50
|
+
@tests_to_run.sort!
|
51
|
+
@tests_to_run.uniq!
|
59
52
|
end
|
60
53
|
|
61
|
-
def
|
54
|
+
def _build_tests_to_run
|
62
55
|
files = []
|
63
|
-
|
64
|
-
if
|
65
|
-
@
|
66
|
-
elsif !file_name.start_with?(@
|
56
|
+
Config.version_control.changed_files.each do |file_name|
|
57
|
+
if Config.test_pattern.match(file_name)
|
58
|
+
@tests_to_run << Config.storage.test_info_for(file_name)
|
59
|
+
elsif !file_name.start_with?(@tests_folder)
|
67
60
|
files << file_name
|
68
61
|
_add_rails_view_spec(file_name)
|
69
62
|
end
|
@@ -72,15 +65,15 @@ module TestDiff
|
|
72
65
|
end
|
73
66
|
|
74
67
|
def _add_calculated_tests(files)
|
75
|
-
@
|
68
|
+
@tests_to_run << Config.storage.select_tests_for(files, tests_folder)
|
76
69
|
end
|
77
70
|
|
78
71
|
def _add_rails_view_spec(file_name)
|
79
72
|
# try and find a matching view spec
|
80
73
|
return unless file_name.include?('app/views')
|
81
|
-
view_spec_name = file_name.gsub('app/views', "#{
|
74
|
+
view_spec_name = file_name.gsub('app/views', "#{tests_folder}/views").gsub('.erb', '.erb_spec.rb')
|
82
75
|
return unless File.exist?(view_spec_name)
|
83
|
-
@
|
76
|
+
@tests_to_run << view_spec_name
|
84
77
|
end
|
85
78
|
end
|
86
79
|
end
|
data/lib/test_diff/storage.rb
CHANGED
@@ -41,6 +41,27 @@ module TestDiff
|
|
41
41
|
results
|
42
42
|
end
|
43
43
|
|
44
|
+
def select_tests_for(files, sub_folder = nil)
|
45
|
+
results = []
|
46
|
+
root_folder = @folder
|
47
|
+
root_folder += "/#{sub_folder}" if sub_folder
|
48
|
+
Dir["#{root_folder}/**/*.yml"].each do |storage_file|
|
49
|
+
select_tests_for_storage_file(results, storage_file, files)
|
50
|
+
end
|
51
|
+
results
|
52
|
+
end
|
53
|
+
|
54
|
+
def test_info_for(file)
|
55
|
+
result = TestInfo.new(file, nil)
|
56
|
+
YAML::Store.new("#{file}.yml").transaction(true) do |store|
|
57
|
+
result = TestInfo.new(file, store['__execution_time__'])
|
58
|
+
end
|
59
|
+
result
|
60
|
+
rescue PStore::Error => e
|
61
|
+
STDERR.puts e.message
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
44
65
|
def clear
|
45
66
|
Dir["#{@folder}/**/*.yml"].each do |storage_file|
|
46
67
|
File.delete(storage_file)
|
@@ -60,6 +81,19 @@ module TestDiff
|
|
60
81
|
end
|
61
82
|
end
|
62
83
|
|
84
|
+
def select_tests_for_storage_file(results, storage_file, files)
|
85
|
+
YAML::Store.new(storage_file).transaction(true) do |store|
|
86
|
+
found_files = files & store.roots
|
87
|
+
found_files.each do |file|
|
88
|
+
next unless _active_file?(store[file])
|
89
|
+
results << TestInfo.new(
|
90
|
+
storage_file.gsub('.yml', '').gsub("#{@folder}/", ''),
|
91
|
+
store['__execution_time__']
|
92
|
+
)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
63
97
|
def _active_file?(file)
|
64
98
|
!file.to_s.split(',').delete_if { |s| s == '' || s == '0' }.empty?
|
65
99
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# TestDiff module
|
2
|
+
module TestDiff
|
3
|
+
# class used to hold infomation about the test
|
4
|
+
class TestInfo
|
5
|
+
include Comparable
|
6
|
+
attr_reader :execution_time, :filename
|
7
|
+
FIXNUM_MAX = (2**(0.size * 8 - 2) - 1)
|
8
|
+
|
9
|
+
def initialize(f, et)
|
10
|
+
@filename = f
|
11
|
+
@execution_time = et
|
12
|
+
end
|
13
|
+
|
14
|
+
def compare_execution_time
|
15
|
+
@execution_time || FIXNUM_MAX
|
16
|
+
end
|
17
|
+
|
18
|
+
def <=>(other)
|
19
|
+
if compare_execution_time == other.compare_execution_time
|
20
|
+
filename <=> other.filename
|
21
|
+
else
|
22
|
+
compare_execution_time <=> other.compare_execution_time
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'git'
|
2
|
+
# TestDiff module
|
3
|
+
module TestDiff
|
4
|
+
# module for test runners
|
5
|
+
module TestRunner
|
6
|
+
# class to run rspec tests
|
7
|
+
class Rspec
|
8
|
+
def run_tests(specs)
|
9
|
+
if specs.any?
|
10
|
+
puts "bundle exec rspec #{specs.join(' ')}"
|
11
|
+
exec "bundle exec rspec #{specs.join(' ')}"
|
12
|
+
else
|
13
|
+
puts 'no specs found to run'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'git'
|
2
|
+
# TestDiff module
|
3
|
+
module TestDiff
|
4
|
+
# module for test runners
|
5
|
+
module TestRunner
|
6
|
+
# class to run rspec tests
|
7
|
+
class Spec
|
8
|
+
def run_tests(specs)
|
9
|
+
if specs.any?
|
10
|
+
puts "bundle exec spec #{specs.join(' ')}"
|
11
|
+
exec "bundle exec spec #{specs.join(' ')}"
|
12
|
+
else
|
13
|
+
puts 'no specs found to run'
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/test_diff/version.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'git'
|
2
|
+
# TestDiff module
|
3
|
+
module TestDiff
|
4
|
+
# module for version control adapters
|
5
|
+
module VersionControl
|
6
|
+
# class to find changed files for git
|
7
|
+
class Git
|
8
|
+
def initialize(wd, last_tracked, current = 'HEAD')
|
9
|
+
@git = ::Git.open(wd)
|
10
|
+
@last_tracked = last_tracked
|
11
|
+
@current = current
|
12
|
+
end
|
13
|
+
|
14
|
+
def changed_files
|
15
|
+
@git.diff(@last_tracked, @current).map(&:path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Speelman
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -131,10 +131,15 @@ files:
|
|
131
131
|
- lib/test_diff.rb
|
132
132
|
- lib/test_diff/build_coverage.rb
|
133
133
|
- lib/test_diff/build_coverage_diff.rb
|
134
|
+
- lib/test_diff/config.rb
|
134
135
|
- lib/test_diff/run_diff.rb
|
135
136
|
- lib/test_diff/storage.rb
|
137
|
+
- lib/test_diff/test_info.rb
|
138
|
+
- lib/test_diff/test_runner/rspec.rb
|
139
|
+
- lib/test_diff/test_runner/spec.rb
|
136
140
|
- lib/test_diff/track_build.rb
|
137
141
|
- lib/test_diff/version.rb
|
142
|
+
- lib/test_diff/version_control/git.rb
|
138
143
|
- test_diff.gemspec
|
139
144
|
homepage: https://github.com/grantspeelman/test_diff
|
140
145
|
licenses:
|