delta_test 1.0.0 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0ba461c2b9065403b53937eb258a5ea5849109c6
4
- data.tar.gz: db45db67cd4da906b56449943c1b2fc4cf4d485e
3
+ metadata.gz: 47f4e1eb57e82c65b8a07fa27ac74a5317abe77d
4
+ data.tar.gz: 3f4f42d81b721b034d38a205cb16b1c833d9c766
5
5
  SHA512:
6
- metadata.gz: b02c8a6c10ccc5306dff37b8033f6cf523a06eee8a83e34937da8e423c71ab3ff009157766a13d45e8aab5d9eb01cfe1f8f298d810702f9d26dd0424d53849ee
7
- data.tar.gz: 842057a457c81171430e51a5409fdbe8564b152c31ae2c746e82d500e7ea8b8610156f8352036170b811d48792ae9f442fbf354009432edca975339c1f767467
6
+ metadata.gz: 57d222b76717aa98fffb62a447a488af498b51e9dd678b8d2a48198e48e1f52c4f44ff0b83bd0846635ca96f20dd72f64e4543c4d43c86ea1bc69b8a0f3589af
7
+ data.tar.gz: 22cd884b4a5907bfe680a711568548c7011925b05a6433c5737aad31d3fdd159b17f17f74c80315502934671645ab3b459b7a8e37eb51bae49d4691b002091ef
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ master
7
7
  N/A
8
8
 
9
9
 
10
+ 1.0.1
11
+ -----
12
+
13
+ - [feature] #26 Subversioning to avoid conflicts
14
+
15
+
10
16
  1.0.0
11
17
  -----
12
18
 
data/README.md CHANGED
@@ -63,8 +63,7 @@ Usage
63
63
  ```bash
64
64
  $ git clone git@example.com:sample/sample_stats.git tmp/delta_test_stats
65
65
  $ delta_test stats:clean
66
- $ delta_test exec rspec spec/models
67
- $ delta_test exec rspec spec/controllers
66
+ $ delta_test exec rspec
68
67
  $ delta_test stats:save
69
68
  ```
70
69
 
@@ -81,9 +80,9 @@ options:
81
80
  --verbose Print more output.
82
81
 
83
82
  commands:
84
- exec [--force-run] <script> -- <files...>
83
+ exec [--force] <script> -- <files...>
85
84
  Execute test script using delta_test.
86
- --force-run to force DeltaTest to run full test cases.
85
+ --force to force DeltaTest to run full test in profile mode.
87
86
 
88
87
  specs List related spec files for changes.
89
88
 
data/lib/delta_test.rb CHANGED
@@ -51,7 +51,7 @@ module DeltaTest
51
51
  def tester_id
52
52
  return @tester_id if @tester_id
53
53
  t = Time.now
54
- @tester_id = 'p%dt%dn%d' % [$$, t.to_i, t.nsec]
54
+ @tester_id = '%d-%d-%d' % [t.to_i, t.nsec, $$]
55
55
  end
56
56
 
57
57
  end
@@ -8,9 +8,9 @@ module DeltaTest
8
8
  class CommandBase
9
9
 
10
10
  DEFAULT_OPTIONS = {
11
- 'verbose' => false,
12
- 'force-run' => false,
13
- 'no-sync' => false,
11
+ 'verbose' => false,
12
+ 'force' => false,
13
+ 'no-sync' => false,
14
14
  }.freeze
15
15
 
16
16
  attr_reader(*%i[
@@ -87,6 +87,8 @@ module DeltaTest
87
87
  # @params {Integer|Nil} status
88
88
  ###
89
89
  def exec_with_data(args, ary, status = nil)
90
+ $stdout.sync = true
91
+
90
92
  Open3.popen3(args) do |i, o, e, w|
91
93
  i.write(ary.join("\n")) if ary
92
94
  i.close
@@ -10,53 +10,79 @@ module DeltaTest
10
10
  SPLITTER = '--'.freeze
11
11
 
12
12
  def invoke!
13
- if stats.base_commit
14
- puts 'Base commit: %s' % [stats.base_commit]
15
- puts
16
- end
13
+ retrive_spec_files
14
+ extract_arg_files
15
+ filter_spec_files
16
+ run_command
17
+ end
17
18
 
18
- spec_files = nil
19
- args = []
19
+ def stats
20
+ @stats ||= Stats.new
21
+ end
20
22
 
21
- begin
22
- unless profile_mode?
23
- list.load_table!(stats.table_file_path)
24
- list.retrive_changed_files!(stats.base_commit)
23
+ def list
24
+ @list ||= RelatedSpecList.new
25
+ end
25
26
 
26
- spec_files = list.related_spec_files.to_a
27
+ def profile_mode?
28
+ return @profile_mode if defined?(@profile_mode)
29
+ @profile_mode = !stats.base_commit || !!@options['force']
30
+ end
31
+
32
+ def retrive_spec_files
33
+ return if profile_mode?
34
+
35
+ puts 'Base commit: %s' % [stats.base_commit]
36
+ puts
37
+
38
+ list.load_table!(stats.table_file_path)
39
+ list.retrive_changed_files!(stats.base_commit)
27
40
 
28
- if spec_files.empty?
29
- exit_with_message(0, 'Nothing to test')
30
- end
31
- end
32
- rescue TableNotFoundError
33
- # force profile mode cuz we don't have a table
34
- @profile_mode = true
41
+ @spec_files = list.related_spec_files.to_a
42
+
43
+ if @spec_files.empty?
44
+ exit_with_message(0, 'Nothing to test')
35
45
  end
46
+ rescue TableNotFoundError
47
+ # force profile mode cuz we don't have a table
48
+ @profile_mode = true
49
+ end
36
50
 
51
+ def extract_arg_files
37
52
  @args.map! { |arg| Shellwords.escape(arg) }
38
53
 
39
- if (splitter = @args.index(SPLITTER))
40
- files = @args.drop(splitter + 1)
54
+ splitter = @args.index(SPLITTER)
55
+ return unless splitter
56
+
57
+ @arg_files = @args.drop(splitter + 1)
58
+ if @arg_files && @arg_files.any?
41
59
  @args = @args.take(splitter)
60
+ else
61
+ @arg_files = nil
62
+ end
63
+ end
64
+
65
+ def filter_spec_files
66
+ return unless @arg_files
42
67
 
43
- if files && files.any?
44
- if spec_files
45
- pattern = files.map { |file| Regexp.escape(file) }
46
- pattern = '^(%s)' % pattern.join('|')
47
- spec_files = spec_files.grep(pattern)
48
- else
49
- spec_files = files
50
- end
51
- end
68
+ if @spec_files
69
+ pattern = @arg_files.map { |file| Regexp.escape(file) }
70
+ pattern = '^(%s)' % pattern.join('|')
71
+ @spec_files = @spec_files.grep(pattern)
72
+ else
73
+ @spec_files = @arg_files
52
74
  end
75
+ end
76
+
77
+ def run_command
78
+ args = []
53
79
 
54
80
  if profile_mode?
55
81
  args << ('%s=%s' % [VERBOSE_FLAG, true]) if DeltaTest.verbose?
56
82
  args << ('%s=%s' % [ACTIVE_FLAG, true])
57
83
  end
58
84
 
59
- if spec_files
85
+ if @spec_files
60
86
  args.unshift('cat', '|')
61
87
  args << 'xargs'
62
88
  end
@@ -67,27 +93,7 @@ module DeltaTest
67
93
 
68
94
  args += @args
69
95
 
70
- $stdout.sync = true
71
-
72
- exec_with_data(args.join(' '), spec_files)
73
- end
74
-
75
- def stats
76
- @stats ||= Stats.new
77
- end
78
-
79
- def list
80
- @list ||= RelatedSpecList.new
81
- end
82
-
83
- ###
84
- # Whether run full test or not
85
- #
86
- # @return {Boolean}
87
- ###
88
- def profile_mode?
89
- return @profile_mode if defined?(@profile_mode)
90
- @profile_mode = !stats.base_commit && !@options['force-run']
96
+ exec_with_data(args.join(' '), @spec_files)
91
97
  end
92
98
 
93
99
  end
@@ -11,9 +11,9 @@ options:
11
11
  --verbose Print more output.
12
12
 
13
13
  commands:
14
- exec [--force-run] <script> -- <files...>
14
+ exec [--force] <script> -- <files...>
15
15
  Execute test script using delta_test.
16
- --force-run to force DeltaTest to run full test cases.
16
+ --force to force DeltaTest to run full test in profile mode.
17
17
 
18
18
  specs List related spec files for changes.
19
19
 
@@ -44,17 +44,15 @@ module DeltaTest
44
44
  CONFIG_FILES = [
45
45
  'delta_test.yml',
46
46
  'delta_test.yaml',
47
- ].freeze
48
-
49
- PART_FILE_EXT = '.part-%s'
47
+ ].map(&:freeze).freeze
50
48
 
51
49
  attr_accessor(*%i[
52
50
  base_path
53
- files
54
-
55
51
  stats_path
56
52
  stats_life
57
53
 
54
+ files
55
+
58
56
  patterns
59
57
  exclude_patterns
60
58
  full_test_patterns
@@ -74,14 +72,6 @@ module DeltaTest
74
72
  Git.new(self.base_path).git_repo?
75
73
  end
76
74
 
77
- validate :files, 'need to be an array' do
78
- self.files.is_a?(Array)
79
- end
80
-
81
- validate :patterns, 'need to be an array' do
82
- self.patterns.is_a?(Array)
83
- end
84
-
85
75
  validate :stats_path, 'need to be an absolute path' do
86
76
  self.stats_path.absolute? rescue false
87
77
  end
@@ -94,6 +84,14 @@ module DeltaTest
94
84
  self.stats_life.is_a?(Integer) && self.stats_life > 0
95
85
  end
96
86
 
87
+ validate :files, 'need to be an array' do
88
+ self.files.is_a?(Array)
89
+ end
90
+
91
+ validate :patterns, 'need to be an array' do
92
+ self.patterns.is_a?(Array)
93
+ end
94
+
97
95
  validate :exclude_patterns, 'need to be an array' do
98
96
  self.exclude_patterns.is_a?(Array)
99
97
  end
@@ -112,12 +110,12 @@ module DeltaTest
112
110
 
113
111
  def initialize
114
112
  update(validate: false) do |c|
115
- c.base_path = File.expand_path('.')
116
- c.files = []
117
-
113
+ c.base_path = File.expand_path('.')
118
114
  c.stats_path = File.expand_path('tmp/delta_test_stats')
119
115
  c.stats_life = 1000 # commits
120
116
 
117
+ c.files = []
118
+
121
119
  c.patterns = []
122
120
  c.exclude_patterns = []
123
121
  c.full_test_patterns = []
@@ -171,10 +169,7 @@ module DeltaTest
171
169
  filtered_files = self.files
172
170
  .map { |f| Utils.regulate_filepath(f, self.base_path) }
173
171
  .uniq
174
-
175
- filtered_files = Utils.files_grep(filtered_files, self.patterns, self.exclude_patterns)
176
-
177
- @filtered_files = Set.new(filtered_files)
172
+ @filtered_files = Utils.files_grep(filtered_files, self.patterns, self.exclude_patterns).to_set
178
173
 
179
174
  @stats_path = Pathname.new(File.absolute_path(self.stats_path, self.base_path))
180
175
  end
@@ -6,24 +6,31 @@ module DeltaTest
6
6
  attr_reader :base_git
7
7
  attr_reader :stats_git
8
8
 
9
- TABLE_FILENAME = 'table.marshal'
9
+ TABLE_FILENAME_TPL = '%s.table'.freeze
10
+ TABLE_FILENAME_PATTERN = '*.table'.freeze
10
11
 
11
12
  def initialize(head: false)
13
+ @head = !!head
14
+
12
15
  @base_git = Git.new(DeltaTest.config.base_path)
13
16
  @stats_git = Git.new(DeltaTest.config.stats_path)
14
-
15
- @base_commit = @base_git.rev_parse('HEAD') if head
16
17
  end
17
18
 
18
19
  def base_commit
19
20
  return @base_commit if defined?(@base_commit)
20
21
 
21
- indexes = @stats_git.ls_files
22
- .map { |f| f.split('/').take(2).join('') }
23
- .to_set
22
+ if @head
23
+ @base_commit = @base_git.rev_parse('HEAD')
24
+ else
25
+ indexes = @stats_git.ls_files
26
+ .map { |f| f.split('/').take(2).join('') }
27
+ .to_set
28
+
29
+ @base_commit = @base_git.ls_hashes(DeltaTest.config.stats_life)
30
+ .find { |h| indexes.include?(h) }
31
+ end
24
32
 
25
- @base_commit = @base_git.ls_hashes(DeltaTest.config.stats_life)
26
- .find { |h| indexes.include?(h) }
33
+ @base_commit
27
34
  end
28
35
 
29
36
  def commit_dir
@@ -34,7 +41,20 @@ module DeltaTest
34
41
  end
35
42
 
36
43
  def table_file_path
37
- commit_dir && commit_dir.join(TABLE_FILENAME)
44
+ return unless commit_dir
45
+ return @table_file_path if defined?(@table_file_path)
46
+
47
+ if @head
48
+ @table_file_path = commit_dir.join(TABLE_FILENAME_TPL % [DeltaTest.tester_id])
49
+ else
50
+ file = Dir.glob(commit_dir.join(TABLE_FILENAME_PATTERN)).max do |f|
51
+ File.basename(f).split('-').take(2).join('.').to_f
52
+ end
53
+ @table_file_path = file
54
+ @table_file_path = Pathname.new(file) if file
55
+ end
56
+
57
+ @table_file_path
38
58
  end
39
59
 
40
60
  end
@@ -2,7 +2,7 @@ module DeltaTest
2
2
 
3
3
  MAJOR = 1
4
4
  MINOR = 0
5
- REVISION = 0
5
+ REVISION = 1
6
6
 
7
7
  VERSION = [MAJOR, MINOR, REVISION].compact.join('.')
8
8
 
@@ -100,17 +100,17 @@ describe DeltaTest::CLI::CommandBase do
100
100
 
101
101
  expect(options).to be_a(Hash)
102
102
 
103
- expect(options['force-run']).to eq(false)
103
+ expect(options['force']).to eq(false)
104
104
  expect(options['verbose']).to eq(false)
105
105
  end
106
106
 
107
107
  it 'should be able to overwrite default options' do
108
- args = ['--force-run', '--verbose']
108
+ args = ['--force', '--verbose']
109
109
  options = command_base.parse_options!(args)
110
110
 
111
111
  expect(options).to be_a(Hash)
112
112
 
113
- expect(options['force-run']).to eq(true)
113
+ expect(options['force']).to eq(true)
114
114
  expect(options['verbose']).to eq(true)
115
115
  end
116
116
 
@@ -26,6 +26,7 @@ describe DeltaTest::CLI::ExecCommand do
26
26
  allow(command.list).to receive(:related_spec_files).and_return(related_spec_files)
27
27
 
28
28
  allow(command.stats).to receive(:base_commit).and_return(base_commit)
29
+ allow(command.stats).to receive(:table_file_path).and_return(nil)
29
30
  end
30
31
 
31
32
  describe '#profile_mode?' do
@@ -45,13 +46,13 @@ describe DeltaTest::CLI::ExecCommand do
45
46
  expect(command.profile_mode?).to be(true)
46
47
  end
47
48
 
48
- context 'with --force-run' do
49
+ context 'with --force' do
49
50
 
50
- let(:args) { ['--force-run', 'bundle', 'exec', 'rspec'] }
51
+ let(:args) { ['--force', 'bundle', 'exec', 'rspec'] }
51
52
 
52
- it 'should always return false' do
53
+ it 'should always return true' do
53
54
  allow(command.stats).to receive(:base_commit).and_return(nil)
54
- expect(command.profile_mode?).to be(false)
55
+ expect(command.profile_mode?).to be(true)
55
56
  end
56
57
 
57
58
  end
@@ -18,6 +18,7 @@ describe DeltaTest::CLI::SpecsCommand do
18
18
  allow(command.list).to receive(:related_spec_files).and_return(related_spec_files)
19
19
 
20
20
  allow(command.stats).to receive(:base_commit).and_return(base_commit)
21
+ allow(command.stats).to receive(:table_file_path).and_return(nil)
21
22
  end
22
23
 
23
24
  describe '#invoke!' do
@@ -30,9 +30,10 @@ describe DeltaTest::Stats do
30
30
  let(:files) do
31
31
  [
32
32
  '11/11111111111111111111111111111111111111/foo.txt',
33
- '11/11111111111111111111111111111111111111/table.marshal',
33
+ '11/11111111111111111111111111111111111111/1000000000-1000000-100.table',
34
34
  '33/33333333333333333333333333333333333333/bar.txt',
35
- '33/33333333333333333333333333333333333333/table.marshal',
35
+ '33/33333333333333333333333333333333333333/2000000000-1000000-100.table',
36
+ '33/33333333333333333333333333333333333333/1000000000-1000000-100.table',
36
37
  ]
37
38
  end
38
39
 
@@ -41,6 +42,11 @@ describe DeltaTest::Stats do
41
42
  .with(DeltaTest.config.stats_life)
42
43
  .and_return(commit_hashes)
43
44
  allow_any_instance_of(DeltaTest::Git).to receive(:ls_files).and_return([])
45
+
46
+ files.each do |file|
47
+ file = DeltaTest.config.stats_path.join(file)
48
+ FakeFS::FileSystem.add(file, FakeFS::FakeFile.new)
49
+ end
44
50
  end
45
51
 
46
52
  describe '#base_commit' do
@@ -73,9 +79,9 @@ describe DeltaTest::Stats do
73
79
 
74
80
  describe '#table_file_path' do
75
81
 
76
- let(:table_file_path) { DeltaTest.config.stats_path.join('33/33333333333333333333333333333333333333/table.marshal') }
82
+ let(:table_file_path) { DeltaTest.config.stats_path.join('33/33333333333333333333333333333333333333/2000000000-1000000-100.table') }
77
83
 
78
- it 'should return a path of table file' do
84
+ it 'should return a path of the newest table file' do
79
85
  allow_any_instance_of(DeltaTest::Git).to receive(:ls_files).and_return(files)
80
86
  expect(stats.table_file_path).to eq(table_file_path)
81
87
  end
@@ -86,4 +92,36 @@ describe DeltaTest::Stats do
86
92
 
87
93
  end
88
94
 
95
+ context 'head: true' do
96
+
97
+ let(:stats) { DeltaTest::Stats.new(head: true) }
98
+
99
+ let(:head_commit) { '4444444444444444444444444444444444444444' }
100
+
101
+ before do
102
+ allow_any_instance_of(DeltaTest::Git).to receive(:rev_parse)
103
+ .with('HEAD')
104
+ .and_return(head_commit)
105
+ end
106
+
107
+ describe '#base_commit' do
108
+
109
+ it 'should return a commit hash of HEAD' do
110
+ expect(stats.base_commit).to eq(head_commit)
111
+ end
112
+
113
+ end
114
+
115
+ describe '#table_file_path' do
116
+
117
+ let(:table_file_path) { DeltaTest.config.stats_path.join('44/44444444444444444444444444444444444444/%s.table' % [DeltaTest.tester_id]) }
118
+
119
+ it 'should return a path of the current tester_id' do
120
+ expect(stats.table_file_path).to eq(table_file_path)
121
+ end
122
+
123
+ end
124
+
125
+ end
126
+
89
127
  end
@@ -120,7 +120,7 @@ describe DeltaTest do
120
120
 
121
121
  it 'should return an unique id for process' do
122
122
  expect(DeltaTest.tester_id).to be_a(String)
123
- expect(DeltaTest.tester_id).to match(/\Ap\d+t\d+n\d+\z/)
123
+ expect(DeltaTest.tester_id).to match(/\A\d+-\d+-\d+\z/)
124
124
  end
125
125
 
126
126
  end
@@ -11,7 +11,7 @@ GIT
11
11
  PATH
12
12
  remote: ../..
13
13
  specs:
14
- delta_test (1.0.0)
14
+ delta_test (1.0.1)
15
15
 
16
16
  GEM
17
17
  remote: https://rubygems.org/
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: delta_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuki Iwanaga
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-29 00:00:00.000000000 Z
11
+ date: 2015-11-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler