test_diff 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Rakefile +2 -2
- data/lib/test_diff/build_coverage.rb +13 -19
- data/lib/test_diff/build_coverage_diff.rb +10 -44
- data/lib/test_diff/run_diff.rb +6 -36
- data/lib/test_diff/runable_tests.rb +56 -0
- data/lib/test_diff/test_runner/rspec.rb +1 -1
- data/lib/test_diff/test_runner/spec.rb +1 -1
- data/lib/test_diff/version.rb +1 -1
- data/lib/test_diff.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YzM0ZGZjYzBmMWNhMDI0YzhlNTQ5ZDFhODkxYWI4ZDgzY2EzOTViNg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ODllMWE5OTg2MjIyZTk5MmNiOTZlYzZkNjMzNTRkMmMwMDYyMmUzYg==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ZjMzOTBiOWMzOWQ5MDA5ZGFmNTM5M2ZkNzFiZGJjMjA2Y2FlOTk1YmVkNzAy
|
10
|
+
YzFkZjFkZDU3YmU3NDljMzVkNjNkOTA5NjViNjhhYjA1NzIzZDExMzk4YmFi
|
11
|
+
ZmZkMzc2MGI0OTAyY2M4ODE5Y2ZlMjk5NTFhOTViNjcxNGI1NWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZDMyODgxZGI4OTdjMTZlZTU0NjFiYWY1YTc5NWVhYTQ2ZGJhNjk1ZWE4M2Zj
|
14
|
+
NGI0ZTljNTY5MzVmMDRjOTFiNjUwNGM4MGU1MjhkMTQ4MmE4NjYzZDkzNmQy
|
15
|
+
MzI3ZDA3NGQ2ZDAxZWY0YTE3YjBkZDgwZTU5NGMyYWE0OWQ2Zjc=
|
data/Rakefile
CHANGED
@@ -10,15 +10,7 @@ module TestDiff
|
|
10
10
|
@batch_queue = Queue.new
|
11
11
|
@storage = Storage.new
|
12
12
|
@continue = continue
|
13
|
-
|
14
|
-
@batch_queue << spec_folder
|
15
|
-
else
|
16
|
-
Dir["#{spec_folder}/**/*_spec.rb"].each do |spec_name|
|
17
|
-
if !continue || @storage.get(spec_name).empty?
|
18
|
-
@batch_queue << spec_name
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
13
|
+
RunableTests.add_all(@batch_queue, continue)
|
22
14
|
end
|
23
15
|
|
24
16
|
def run
|
@@ -74,16 +66,18 @@ module TestDiff
|
|
74
66
|
puts "running #{main_spec_file}"
|
75
67
|
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
|
76
68
|
Time.zone_default = (Time.zone = 'UTC') if Time.respond_to?(:zone_default) && Time.zone_default.nil?
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
69
|
+
run_test(main_spec_file)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def run_test(main_spec_file)
|
74
|
+
s = Time.now
|
75
|
+
result = run_tests(main_spec_file)
|
76
|
+
if result
|
77
|
+
save_coverage_data(main_spec_file, Time.now - s)
|
78
|
+
else
|
79
|
+
Coverage.result # disable coverage
|
80
|
+
exit!(false) unless @continue
|
87
81
|
end
|
88
82
|
end
|
89
83
|
|
@@ -7,14 +7,14 @@ module TestDiff
|
|
7
7
|
def initialize(spec_folder, pre_load, continue)
|
8
8
|
@spec_folder = spec_folder
|
9
9
|
@sha1 = File.read('test_diff_coverage/sha')
|
10
|
-
@
|
10
|
+
@tests_to_run = []
|
11
11
|
@storage = Storage.new
|
12
12
|
@pre_load = pre_load
|
13
13
|
@continue = continue
|
14
14
|
end
|
15
15
|
|
16
16
|
def run
|
17
|
-
add_changed_files
|
17
|
+
RunableTests.new(@tests_to_run, @spec_folder).add_changed_files
|
18
18
|
remove_tests_that_do_not_exist
|
19
19
|
remove_tests_in_wrong_folder
|
20
20
|
require 'coverage.so'
|
@@ -32,9 +32,8 @@ module TestDiff
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def run_batch
|
35
|
-
puts "Running #{@
|
36
|
-
|
37
|
-
timing_thread = start_timing_thread(Time.now, @specs_to_run.size)
|
35
|
+
puts "Running #{@tests_to_run.size} tests"
|
36
|
+
timing_thread = start_timing_thread(Time.now, @tests_to_run.size)
|
38
37
|
start
|
39
38
|
timing_thread.join
|
40
39
|
puts 'Test done, compacting db'
|
@@ -43,8 +42,8 @@ module TestDiff
|
|
43
42
|
|
44
43
|
def start_timing_thread(start_time, original_size)
|
45
44
|
Thread.new do
|
46
|
-
until @
|
47
|
-
last_size = @
|
45
|
+
until @tests_to_run.empty?
|
46
|
+
last_size = @tests_to_run.size
|
48
47
|
completed = original_size - last_size
|
49
48
|
if completed > 0
|
50
49
|
time_per_spec = (Time.now - start_time).to_f / completed.to_f
|
@@ -57,8 +56,8 @@ module TestDiff
|
|
57
56
|
end
|
58
57
|
|
59
58
|
def start
|
60
|
-
until @
|
61
|
-
pid = start_process_fork(@
|
59
|
+
until @tests_to_run.empty?
|
60
|
+
pid = start_process_fork(@tests_to_run.pop)
|
62
61
|
pid, status = Process.waitpid2(pid)
|
63
62
|
fail 'Test Failed' unless status.success?
|
64
63
|
end
|
@@ -105,48 +104,15 @@ module TestDiff
|
|
105
104
|
end
|
106
105
|
|
107
106
|
def remove_tests_that_do_not_exist
|
108
|
-
@
|
107
|
+
@tests_to_run.delete_if do |s|
|
109
108
|
!File.exist?(s)
|
110
109
|
end
|
111
110
|
end
|
112
111
|
|
113
112
|
def remove_tests_in_wrong_folder
|
114
|
-
@
|
113
|
+
@tests_to_run.delete_if do |s|
|
115
114
|
!s.start_with?("#{spec_folder}/")
|
116
115
|
end
|
117
116
|
end
|
118
|
-
|
119
|
-
def add_changed_files
|
120
|
-
_build_specs_to_run
|
121
|
-
|
122
|
-
@specs_to_run.flatten!
|
123
|
-
@specs_to_run.sort!
|
124
|
-
@specs_to_run.uniq!
|
125
|
-
end
|
126
|
-
|
127
|
-
def _build_specs_to_run
|
128
|
-
files = []
|
129
|
-
`git diff --name-only #{sha1} HEAD`.split("\n").each do |file_name|
|
130
|
-
if file_name.end_with?('spec.rb') || file_name.end_with?('test.rb')
|
131
|
-
@specs_to_run << file_name
|
132
|
-
elsif !file_name.start_with?(@storage.folder)
|
133
|
-
files << file_name
|
134
|
-
_add_rails_view_spec(file_name)
|
135
|
-
end
|
136
|
-
end
|
137
|
-
_add_calculated_tests(files)
|
138
|
-
end
|
139
|
-
|
140
|
-
def _add_calculated_tests(files)
|
141
|
-
@specs_to_run << @storage.find_for(files, spec_folder)
|
142
|
-
end
|
143
|
-
|
144
|
-
def _add_rails_view_spec(file_name)
|
145
|
-
# try and find a matching view spec
|
146
|
-
return unless file_name.include?('app/views')
|
147
|
-
view_spec_name = file_name.gsub('app/views', "#{spec_folder}/views").gsub('.erb', '.erb_spec.rb')
|
148
|
-
return unless File.exist?(view_spec_name)
|
149
|
-
@specs_to_run << view_spec_name
|
150
|
-
end
|
151
117
|
end
|
152
118
|
end
|
data/lib/test_diff/run_diff.rb
CHANGED
@@ -12,7 +12,7 @@ module TestDiff
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def run
|
15
|
-
add_changed_files
|
15
|
+
RunableTests.new(@tests_to_run, @tests_folder).add_changed_files
|
16
16
|
remove_tests_that_do_not_exist
|
17
17
|
remove_tests_in_wrong_folder
|
18
18
|
select_test_group
|
@@ -27,8 +27,11 @@ module TestDiff
|
|
27
27
|
|
28
28
|
def select_test_group
|
29
29
|
return unless groups_of
|
30
|
-
|
31
|
-
@tests_to_run
|
30
|
+
new_set_of_tests_to_run = []
|
31
|
+
@tests_to_run.each_with_index do |test, i|
|
32
|
+
new_set_of_tests_to_run << test if i % groups_of.to_i == group.to_i
|
33
|
+
end
|
34
|
+
@tests_to_run = new_set_of_tests_to_run
|
32
35
|
end
|
33
36
|
|
34
37
|
def remove_tests_that_do_not_exist
|
@@ -42,38 +45,5 @@ module TestDiff
|
|
42
45
|
!s.filename.start_with?("#{tests_folder}/")
|
43
46
|
end
|
44
47
|
end
|
45
|
-
|
46
|
-
def add_changed_files
|
47
|
-
_build_tests_to_run
|
48
|
-
|
49
|
-
@tests_to_run.flatten!
|
50
|
-
@tests_to_run.sort!
|
51
|
-
@tests_to_run.uniq!
|
52
|
-
end
|
53
|
-
|
54
|
-
def _build_tests_to_run
|
55
|
-
files = []
|
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)
|
60
|
-
files << file_name
|
61
|
-
_add_rails_view_spec(file_name)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
_add_calculated_tests(files)
|
65
|
-
end
|
66
|
-
|
67
|
-
def _add_calculated_tests(files)
|
68
|
-
@tests_to_run << Config.storage.select_tests_for(files, tests_folder)
|
69
|
-
end
|
70
|
-
|
71
|
-
def _add_rails_view_spec(file_name)
|
72
|
-
# try and find a matching view spec
|
73
|
-
return unless file_name.include?('app/views')
|
74
|
-
view_spec_name = file_name.gsub('app/views', "#{tests_folder}/views").gsub('.erb', '.erb_spec.rb')
|
75
|
-
return unless File.exist?(view_spec_name)
|
76
|
-
@tests_to_run << view_spec_name
|
77
|
-
end
|
78
48
|
end
|
79
49
|
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
# TestDiff module
|
2
|
+
module TestDiff
|
3
|
+
# class used to find tests that are runable
|
4
|
+
class RunableTests
|
5
|
+
def self.add_all(list, continue = false)
|
6
|
+
if File.file?(spec_folder)
|
7
|
+
list << spec_folder
|
8
|
+
else
|
9
|
+
Dir["#{spec_folder}/**/*_spec.rb"].each do |spec_name|
|
10
|
+
has_no_data = Config.storage.get(spec_name).empty?
|
11
|
+
list << spec_name if has_no_data || !continue
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
attr_reader :tests_folder
|
17
|
+
|
18
|
+
def initialize(list_to_add_to, tests_folder)
|
19
|
+
@tests_to_run = list_to_add_to
|
20
|
+
@tests_folder = tests_folder
|
21
|
+
end
|
22
|
+
|
23
|
+
def add_changed_files
|
24
|
+
_build_tests_to_run
|
25
|
+
|
26
|
+
@tests_to_run.flatten!
|
27
|
+
@tests_to_run.sort!
|
28
|
+
@tests_to_run.uniq!
|
29
|
+
end
|
30
|
+
|
31
|
+
def _build_tests_to_run
|
32
|
+
files = []
|
33
|
+
Config.version_control.changed_files.each do |file_name|
|
34
|
+
if Config.test_pattern.match(file_name)
|
35
|
+
@tests_to_run << Config.storage.test_info_for(file_name)
|
36
|
+
elsif !file_name.start_with?(@tests_folder)
|
37
|
+
files << file_name
|
38
|
+
_add_rails_view_spec(file_name)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
_add_calculated_tests(files)
|
42
|
+
end
|
43
|
+
|
44
|
+
def _add_calculated_tests(files)
|
45
|
+
@tests_to_run << Config.storage.select_tests_for(files, tests_folder)
|
46
|
+
end
|
47
|
+
|
48
|
+
def _add_rails_view_spec(file_name)
|
49
|
+
# try and find a matching view spec
|
50
|
+
return unless file_name.include?('app/views')
|
51
|
+
view_spec_name = file_name.gsub('app/views', "#{tests_folder}/views").gsub('.erb', '.erb_spec.rb')
|
52
|
+
return unless File.exist?("#{Config.working_directory}/#{view_spec_name}")
|
53
|
+
@tests_to_run << Config.storage.test_info_for(view_spec_name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/test_diff/version.rb
CHANGED
data/lib/test_diff.rb
CHANGED
@@ -4,6 +4,7 @@ require 'test_diff/test_info'
|
|
4
4
|
require 'test_diff/version_control/git'
|
5
5
|
require 'test_diff/test_runner/rspec'
|
6
6
|
require 'test_diff/config'
|
7
|
+
require 'test_diff/runable_tests'
|
7
8
|
require 'test_diff/build_coverage'
|
8
9
|
require 'test_diff/run_diff'
|
9
10
|
require 'test_diff/build_coverage_diff'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test_diff
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Grant Speelman
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- lib/test_diff/build_coverage_diff.rb
|
134
134
|
- lib/test_diff/config.rb
|
135
135
|
- lib/test_diff/run_diff.rb
|
136
|
+
- lib/test_diff/runable_tests.rb
|
136
137
|
- lib/test_diff/storage.rb
|
137
138
|
- lib/test_diff/test_info.rb
|
138
139
|
- lib/test_diff/test_runner/rspec.rb
|