test_diff 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/lib/test_diff/coverage_data.rb +16 -0
- data/lib/test_diff/coverage_runner.rb +15 -12
- data/lib/test_diff/execution_times.rb +49 -0
- data/lib/test_diff/storage.rb +45 -36
- data/lib/test_diff/version.rb +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad2a0134d2a5f656ec7039d12ec01bd1684afb91e7bf0f67ef62a2396c7285df
|
4
|
+
data.tar.gz: e0627266c8e8e0ca9909e1fffd45ffeed387f40fb99656d33c0954106ae1f356
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61bb314ad64fb1659a2c4ddfd468b6017837f87688444b298efb5bb74d0b25b5ebb824260592a9eaa68f19b3043344c12eddd22af79765354cbdadb9bf9715b6
|
7
|
+
data.tar.gz: eea506cdb23716104ab4e0302b4a88ca9bd07c2d5ba8131b2053e4e18e7b2b8c4c1036ff3d8f875fe1a315986239f88d50d80362027390a0464ff545e2643a8a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
# Changelog
|
2
|
+
All notable changes to this project will be documented in this file.
|
3
|
+
|
4
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
5
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
6
|
+
|
7
|
+
## [Unreleased]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module TestDiff
|
2
|
+
# runs each spec and saves it to storage
|
3
|
+
module CoverageData
|
4
|
+
def self.get(result = ::Coverage.result)
|
5
|
+
data = {}
|
6
|
+
result.each do |file_name, stats|
|
7
|
+
relative_file_name = file_name.gsub("#{FileUtils.pwd}/", '')
|
8
|
+
is_active = stats.map(&:to_i).any?(&:nonzero?)
|
9
|
+
if file_name.start_with?(FileUtils.pwd) && is_active
|
10
|
+
data[relative_file_name] = stats.join(',')
|
11
|
+
end
|
12
|
+
end
|
13
|
+
data
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -1,3 +1,6 @@
|
|
1
|
+
require 'test_diff/coverage_data'
|
2
|
+
require 'test_diff/execution_times'
|
3
|
+
|
1
4
|
module TestDiff
|
2
5
|
# runs each spec and saves it to storage
|
3
6
|
class CoverageRunner
|
@@ -10,11 +13,12 @@ module TestDiff
|
|
10
13
|
@batch_queue = batch_queue
|
11
14
|
@storage = Storage.new
|
12
15
|
@continue = continue
|
16
|
+
@execution_times = ExecutionTimes.new
|
17
|
+
@execution_times.clear
|
13
18
|
end
|
14
19
|
|
15
20
|
def run
|
16
21
|
require 'coverage.so'
|
17
|
-
Coverage.start
|
18
22
|
|
19
23
|
ENV['TEST_DIFF_COVERAGE'] = 'yes'
|
20
24
|
|
@@ -40,6 +44,7 @@ module TestDiff
|
|
40
44
|
|
41
45
|
def require_pre_load
|
42
46
|
return unless @pre_load
|
47
|
+
::Coverage.start
|
43
48
|
puts "pre_loading #{@pre_load}"
|
44
49
|
$LOAD_PATH << "#{Dir.getwd}/spec"
|
45
50
|
require File.expand_path(@pre_load)
|
@@ -66,7 +71,6 @@ module TestDiff
|
|
66
71
|
_pid, status = Process.waitpid2(pid)
|
67
72
|
raise 'Test Failed' unless status.success?
|
68
73
|
end
|
69
|
-
Coverage.result # disable coverage
|
70
74
|
end
|
71
75
|
|
72
76
|
def start_process_fork(main_spec_file)
|
@@ -74,6 +78,7 @@ module TestDiff
|
|
74
78
|
puts "running #{main_spec_file}"
|
75
79
|
ActiveRecord::Base.connection.reconnect! if defined?(ActiveRecord::Base)
|
76
80
|
Time.zone_default = (Time.zone = 'UTC') if Time.respond_to?(:zone_default) && Time.zone_default.nil?
|
81
|
+
::Coverage.start
|
77
82
|
run_test(main_spec_file)
|
78
83
|
end
|
79
84
|
end
|
@@ -82,7 +87,8 @@ module TestDiff
|
|
82
87
|
s = Time.now
|
83
88
|
result = run_tests(main_spec_file)
|
84
89
|
if result
|
85
|
-
|
90
|
+
save_execution_time(main_spec_file, Time.now - s)
|
91
|
+
save_coverage_data(main_spec_file)
|
86
92
|
else
|
87
93
|
$stderr.puts(@last_output.string)
|
88
94
|
Coverage.result # disable coverage
|
@@ -95,16 +101,13 @@ module TestDiff
|
|
95
101
|
::RSpec::Core::Runner.run([main_spec_file], @last_output, @last_output).zero?
|
96
102
|
end
|
97
103
|
|
98
|
-
def save_coverage_data(main_spec_file
|
99
|
-
|
100
|
-
Coverage.result.each do |file_name, stats|
|
101
|
-
relative_file_name = file_name.gsub("#{FileUtils.pwd}/", '')
|
102
|
-
if file_name.start_with?(FileUtils.pwd)
|
103
|
-
data[relative_file_name] = stats.join(',')
|
104
|
-
end
|
105
|
-
end
|
106
|
-
@storage.set(main_spec_file, data)
|
104
|
+
def save_coverage_data(main_spec_file)
|
105
|
+
@storage.set(main_spec_file, CoverageData.get)
|
107
106
|
@storage.flush if @storage.respond_to?(:flush)
|
108
107
|
end
|
108
|
+
|
109
|
+
def save_execution_time(main_spec_file, execution_time)
|
110
|
+
@execution_times.add(main_spec_file, execution_time)
|
111
|
+
end
|
109
112
|
end
|
110
113
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'test_diff/logging'
|
2
|
+
|
3
|
+
module TestDiff
|
4
|
+
# runs each spec and saves it to storage
|
5
|
+
class ExecutionTimes
|
6
|
+
include Logging
|
7
|
+
|
8
|
+
def initialize(directory = 'test_diff_coverage', filename = 'execution_times.txt')
|
9
|
+
@file_name = "#{directory}/#{filename}"
|
10
|
+
end
|
11
|
+
|
12
|
+
def clear
|
13
|
+
return unless file_exist?
|
14
|
+
log_debug "Deleting #{@file_name}"
|
15
|
+
File.delete(@file_name)
|
16
|
+
reset_times
|
17
|
+
end
|
18
|
+
|
19
|
+
def add(main_spec_file, execution_time)
|
20
|
+
File.open(@file_name, 'a+') do |file|
|
21
|
+
file.write "#{main_spec_file}:#{execution_time}\n"
|
22
|
+
end
|
23
|
+
reset_times
|
24
|
+
end
|
25
|
+
|
26
|
+
def get(file)
|
27
|
+
time = times[file]
|
28
|
+
return nil if time.nil?
|
29
|
+
time.to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
alias [] :get
|
33
|
+
|
34
|
+
private
|
35
|
+
|
36
|
+
def times
|
37
|
+
return {} unless file_exist?
|
38
|
+
@times ||= Hash[File.readlines(@file_name).map(&:chomp).map { |line| line.split(':') }]
|
39
|
+
end
|
40
|
+
|
41
|
+
def reset_times
|
42
|
+
@times = nil
|
43
|
+
end
|
44
|
+
|
45
|
+
def file_exist?
|
46
|
+
File.exist?(@file_name)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
data/lib/test_diff/storage.rb
CHANGED
@@ -5,8 +5,23 @@ module TestDiff
|
|
5
5
|
class Storage
|
6
6
|
attr_reader :folder
|
7
7
|
|
8
|
-
def initialize(folder = 'test_diff_coverage'
|
8
|
+
def initialize(folder = 'test_diff_coverage',
|
9
|
+
execution_times = ExecutionTimes.new('test_diff_coverage'))
|
9
10
|
@folder = folder
|
11
|
+
@execution_times = execution_times
|
12
|
+
@preload_name = '_preload_'
|
13
|
+
end
|
14
|
+
|
15
|
+
def preload=(coverage_data)
|
16
|
+
raise 'Data must be a Hash' unless coverage_data.is_a?(Hash)
|
17
|
+
get_store(@preload_name).transaction do |store|
|
18
|
+
store.roots.each do |key|
|
19
|
+
store.delete(key)
|
20
|
+
end
|
21
|
+
coverage_data.keys.sort.each do |key|
|
22
|
+
store[key] = coverage_data[key]
|
23
|
+
end
|
24
|
+
end
|
10
25
|
end
|
11
26
|
|
12
27
|
def set(file, coverage_data)
|
@@ -33,9 +48,7 @@ module TestDiff
|
|
33
48
|
|
34
49
|
def find_for(files, sub_folder = nil)
|
35
50
|
results = []
|
36
|
-
|
37
|
-
root_folder += "/#{sub_folder}" if sub_folder
|
38
|
-
Dir["#{root_folder}/**/*.yml"].each do |storage_file|
|
51
|
+
each_file(sub_folder) do |storage_file|
|
39
52
|
find_for_storage_file(results, storage_file, files)
|
40
53
|
end
|
41
54
|
results
|
@@ -43,23 +56,18 @@ module TestDiff
|
|
43
56
|
|
44
57
|
def select_tests_for(files, sub_folder = nil)
|
45
58
|
results = []
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
59
|
+
preload_files = preload_found_files(files)
|
60
|
+
each_file(sub_folder) do |storage_file|
|
61
|
+
next if storage_file.include?(@preload_name)
|
62
|
+
if preload_files.any? || found_files(storage_file, files).any?
|
63
|
+
results << TestInfo.new(storage_file, @execution_times[storage_file])
|
64
|
+
end
|
50
65
|
end
|
51
66
|
results
|
52
67
|
end
|
53
68
|
|
54
69
|
def test_info_for(file)
|
55
|
-
|
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
|
70
|
+
TestInfo.new(file, @execution_times[file])
|
63
71
|
end
|
64
72
|
|
65
73
|
def clear
|
@@ -70,32 +78,25 @@ module TestDiff
|
|
70
78
|
|
71
79
|
private
|
72
80
|
|
73
|
-
def
|
74
|
-
|
75
|
-
|
76
|
-
found_files.each do |file|
|
77
|
-
if _active_file?(store[file])
|
78
|
-
results << storage_file.gsub('.yml', '').gsub("#{@folder}/", '')
|
79
|
-
end
|
80
|
-
end
|
81
|
+
def found_files(storage_file, files)
|
82
|
+
get_store(storage_file).transaction(true) do |store|
|
83
|
+
files & store.roots
|
81
84
|
end
|
82
85
|
end
|
83
86
|
|
84
|
-
def
|
85
|
-
|
86
|
-
|
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
|
87
|
+
def preload_found_files(files)
|
88
|
+
get_store(@preload_name).transaction(true) do |store|
|
89
|
+
files & store.roots
|
94
90
|
end
|
95
91
|
end
|
96
92
|
|
97
|
-
def
|
98
|
-
|
93
|
+
def find_for_storage_file(results, storage_file, files)
|
94
|
+
get_store(storage_file).transaction(true) do |store|
|
95
|
+
found_files = files & store.roots
|
96
|
+
found_files.each do |_file|
|
97
|
+
results << storage_file.gsub('.yml', '').gsub("#{@folder}/", '')
|
98
|
+
end
|
99
|
+
end
|
99
100
|
end
|
100
101
|
|
101
102
|
def get_store(file)
|
@@ -104,5 +105,13 @@ module TestDiff
|
|
104
105
|
FileUtils.mkdir_p(dir)
|
105
106
|
YAML::Store.new "#{dir}/#{filename}"
|
106
107
|
end
|
108
|
+
|
109
|
+
def each_file(sub_folder = nil)
|
110
|
+
root_folder = @folder
|
111
|
+
root_folder += "/#{sub_folder}" if sub_folder
|
112
|
+
Dir["#{root_folder}/**/*.yml"].sort.each do |full_storage_file|
|
113
|
+
yield full_storage_file.gsub("#{@folder}/", '').gsub('.yml', '')
|
114
|
+
end
|
115
|
+
end
|
107
116
|
end
|
108
117
|
end
|
data/lib/test_diff/version.rb
CHANGED
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.6.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:
|
11
|
+
date: 2019-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- ".rspec"
|
94
94
|
- ".rubocop.yml"
|
95
95
|
- ".travis.yml"
|
96
|
+
- CHANGELOG.md
|
96
97
|
- CODE_OF_CONDUCT.md
|
97
98
|
- Gemfile
|
98
99
|
- LICENSE.txt
|
@@ -105,7 +106,9 @@ files:
|
|
105
106
|
- lib/test_diff/build_coverage.rb
|
106
107
|
- lib/test_diff/build_coverage_diff.rb
|
107
108
|
- lib/test_diff/config.rb
|
109
|
+
- lib/test_diff/coverage_data.rb
|
108
110
|
- lib/test_diff/coverage_runner.rb
|
111
|
+
- lib/test_diff/execution_times.rb
|
109
112
|
- lib/test_diff/logging.rb
|
110
113
|
- lib/test_diff/run_diff.rb
|
111
114
|
- lib/test_diff/runable_tests.rb
|
@@ -138,7 +141,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
138
141
|
version: '0'
|
139
142
|
requirements: []
|
140
143
|
rubyforge_project:
|
141
|
-
rubygems_version: 2.7.
|
144
|
+
rubygems_version: 2.7.6
|
142
145
|
signing_key:
|
143
146
|
specification_version: 4
|
144
147
|
summary: Gem that attempts to find the tests that are required to run for the changes
|