regtest 2.0.0.pre → 2.2.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
- SHA1:
3
- metadata.gz: 9a917267b567e320d9f372ad942f4602282c42b4
4
- data.tar.gz: d2e5e0da3b36b4190db29449c188b31ff6072f23
2
+ SHA256:
3
+ metadata.gz: b91c5f1f5b30d309f77eaf7c3c218529bd82321a7af578b37c52a4bed09d53e4
4
+ data.tar.gz: f66632f3eb0f2844ab43068f83c30e62aca2805dad460543436b9df0620c3598
5
5
  SHA512:
6
- metadata.gz: 2b439502a95aa227425959e0de2be46d09d71233a3fc70b62a01220650464584d5a8ff1498ffcd41b9197679ad1b69e441d477b91a648a0ccb1910ec28b9cd5c
7
- data.tar.gz: 6e3b8462a54c051a5d1ae795572c6ba5871f07df53359c21c34c2eada095b23eab01fc0176e1afa9b17bc6efcdeca48fb9c8e2bddeca03b9911b91cc5b150528
6
+ metadata.gz: 38257004b8aab5bbad388e430b85362e80b5759be4ca1729756ce0e2704a6cc85f12e3899c17b28df32afc1380251228321f750fb7f8bc4bd951a56e1ca27690
7
+ data.tar.gz: 2a2f5f808848caccb56db4a4d90a9e34babf70a79d30bf49182317c77081985bcae89289c77acab5ba4a029483330ba3533a37d91be6fbdfc7b63b3cfd397948
data/.aspell.pws CHANGED
@@ -1,25 +1,38 @@
1
- personal_ws-1.1 en 24
2
- NOREGTESTRC
3
- dir
1
+ personal_ws-1.1 en 26
4
2
  Bugfix
5
- ostruct
6
3
  ENV
7
- filename
4
+ Friedrich
8
5
  Gemfile
6
+ NOREGTESTRC
7
+ README
8
+ Regtest
9
+ SCM
10
+ SemVer
11
+ SemVerTag
12
+ YAML
9
13
  basename
10
- Rakefile
14
+ bitbucket
15
+ dir
11
16
  exiftool
12
- yml
13
- yaml
14
- workflow
15
- refactoring
17
+ gettime
18
+ github
19
+ md
20
+ metatest
16
21
  metatests
17
- catched
18
- regtest
19
22
  rb
20
23
  rc
21
- Friedrich
22
- SCM
24
+ regtest
23
25
  regtestrc
24
- metatest
26
+ scripref
27
+ yml
28
+ arg
29
+ Matz
30
+ ary
31
+ Matz
25
32
  OpenStruct
33
+ Rakefile
34
+ arg
35
+ ary
36
+ catched
37
+ ostruct
38
+ yaml
data/Changelog CHANGED
@@ -1,4 +1,24 @@
1
- 2.0.0.pre Major Release
1
+ 2.2.1
2
+ Adapt git output to work with different git versions.
3
+ Simplify determination of filenames for outputs.
4
+ Add a test and Fix documentation.
5
+
6
+ 2.2.0
7
+ Add a new method Regtest.log to allow the logging of temporary values which
8
+ could be of interest for different reasons (i. e. debugging).
9
+ With this version you can use `extend Regtest` to have the methods sample, log
10
+ and combinations as top level methods. This is experimental and therefore not
11
+ yet mentioned at README.
12
+
13
+ 2.1.1
14
+ Adapt remaining examples of regtest/colorize to regtest/colors.
15
+
16
+ 2.1.0
17
+ Use Process.clock_gettime for time measurements.
18
+ Eliminate dependency to colorize gem. So Regtest has no longer any
19
+ dependency.
20
+
21
+ 2.0.0 Major Release
2
22
 
3
23
  Incompatibilities to regtest 1.x
4
24
  1. The methods sample and combinations are not longer defined as instance
@@ -15,13 +35,18 @@ will not be loaded.
15
35
  A simple plugin mechanism is implemented and two plugins are part of regtest:
16
36
  regtest/colorize and regtest/git. Plugins are usual activated by require in
17
37
  one of the .regtestrc files.
38
+ It is possible to change the exit codes for different return states of
39
+ Regtest.check_results. This is done with changing Regtest.exit_codes see
40
+ README.md for an example.
18
41
 
19
42
  Further Changes
20
- Reporting of statistics for writing files is removed because it's not useful.
21
- Now the full filename for results files are reported when running regtest.
43
+ Reporting of statistics was reduced and the full filename for results files
44
+ are now reported when running regtest.
22
45
  Some metatests are added.
23
46
  Version constant Regtest::VERSION is also added.
24
- A lot of internal refactoring and improving documentation.
47
+ Regtest.sample returns now the hash with result information. This could be
48
+ useful for plugins which overload this method.
49
+ A lot of internal refactoring and improving documentation was done.
25
50
 
26
51
 
27
52
  1.1.0
data/LICENSE CHANGED
@@ -1,3 +1,3 @@
1
- Copyright 2014-2017 by Jan Friedrich <janfri26@gmail.com>
1
+ Copyright 2014, 2015, 2017-2019 by Jan Friedrich <janfri26@gmail.com>
2
2
 
3
3
  Regtest is licensed under the same terms as Ruby itself.
data/README.md CHANGED
@@ -146,6 +146,79 @@ older runs of the samples is done by your SCM. So the sample files and their
146
146
  corresponding results files should be taken under version control.
147
147
 
148
148
 
149
+ ## Logging
150
+
151
+ The key idea behind regtest is to produce values that are invariant and check
152
+ if this assumption is true at another (mostly later) state of code. But often
153
+ there are temporary or specific values which changes or could change at each
154
+ run of regtest. This could be for example an id for a created record or the
155
+ version of a used external service or some time-relevant values. Sometimes it
156
+ is useful, to know the actual value of one of these.
157
+
158
+ In such cases the method ```Regtest.log``` could be handy. It writes a line of
159
+ the given object to a log file which is named with the same name as the calling
160
+ Ruby script but has as extension ```.log```. It could be called inside as well
161
+ as outside of a regtest sample. Per default this file is overwritten by the
162
+ first call of ```Regtest.log``` of each run of regtest and per file. And each
163
+ further call of ```Regtest.log``` appends then to the file. So you get a
164
+ complete log for each run. But this behaviour could be changed with the
165
+ ```mode``` keyword arg of the method. Let's see an example:
166
+
167
+ ```ruby
168
+ Regtest.log RUBY_VERSION
169
+
170
+ def create_record **values
171
+ # do stuff to create the record and return the id of the generated record
172
+ end
173
+
174
+ def delete_record id
175
+ # delete an existing record or raise an exception if record with id doesn't
176
+ # exists
177
+ end
178
+
179
+ Regtest.sample 'create a record and delete it' do
180
+ id = create_record language: 'Ruby', creator: 'Matz'
181
+ Regtest.log "generated record with id #{id}"
182
+ delete_record id
183
+ # the generated id should not be part of the result, because it changes every
184
+ # time you create a new record
185
+ 'Record created and deleted'
186
+ end
187
+
188
+ Regtest.sample 'try to delete a non existing record' do
189
+ delete_record -1
190
+ end
191
+ ```
192
+
193
+ If you want to have a log that is not truncated at each run of regtest, you can
194
+ use ```mode: 'a'```at the first call of ```Regtest.log``` in the corresponding
195
+ ruby script.
196
+
197
+ ```ruby
198
+ # ...
199
+ # the first call of Regtest.log in this Ruby file
200
+ Regtest.log Time.now, mode: 'a'
201
+ ```
202
+
203
+ On the other hand, you can use ```mode: 'w'``` to truncate the log file even at
204
+ a later call of ```Regtest.log```.
205
+
206
+ ```ruby
207
+ max_time = 0
208
+ ary.each do |e|
209
+ t = get_time_to_do_some_stuff
210
+ if t > max_time
211
+ max_time = t
212
+ Regtest.log max_time, mode: 'w'
213
+ # the content of the corresponding log file is now one line with max_time
214
+ end
215
+ end
216
+ ```
217
+
218
+ Because the log files contains only temporary stuff they should normally not
219
+ checked in the SCM.
220
+
221
+
149
222
  ## Configuration and Plugins
150
223
 
151
224
  You can adapt the behaviour of regtest with plugins. To configure this and
@@ -159,10 +232,10 @@ For example the following is a good default when you want colorized output and
159
232
  use git as your SCM:
160
233
 
161
234
  ```ruby
162
- require 'regtest/colorize'
235
+ require 'regtest/colors'
163
236
  # adapt some colorizing if wanted
164
- Regtest::Colorize.mapping[:filename] = :blue
165
- Regtest::Colorize.mapping[:statistics] = {mode: :italic}
237
+ Regtest::Colors.mapping[:filename] = :cyan
238
+ Regtest::Colors.mapping[:statistics] = %i(blue italic)
166
239
 
167
240
  require 'regtest/git'
168
241
  ```
@@ -174,7 +247,8 @@ script is accordingly set. The standard values are: 0 for success, 1 for an
174
247
  unknown result (normally a new results file) and 2 for failure. If you use
175
248
  plain regtest without a SCM plugin the exit code is 1 (= unknown result).
176
249
 
177
- You can change the exit codes for the states with `Regtest.exit_codes` for example:
250
+ You can change the exit codes for the states with `Regtest.exit_codes`. The
251
+ following example changes the behaviour to the same as in regtest version 1.x.
178
252
 
179
253
  ```ruby
180
254
  Regtest.exit_codes[:unknown_result] = 0
@@ -224,6 +298,13 @@ The code is hosted on [github](https://github.com/janfri/regtest) and
224
298
  [bitbucket](https://bitbucket.org/janfri/regtest) Change it to your needs.
225
299
  Release a fork. It is open source.
226
300
 
301
+
302
+ ## Versioning
303
+
304
+ Regtest follows [Semantic Versioning](https://semver.org/), both SemVer and
305
+ SemVerTag.
306
+
307
+
227
308
  ## Author
228
309
 
229
310
  Jan Friedrich <janfri26@gmail.com>
data/Rakefile CHANGED
@@ -34,7 +34,12 @@ Rim.setup do |p|
34
34
  END
35
35
  p.homepage = 'https://github.com/janfri/regtest'
36
36
  p.ruby_version = '>=2.1.0'
37
- p.dependencies << %w(colorize ~>0.8)
37
+ end
38
+
39
+ # JRuby does not support escaping of filenames with spaces in Open3.capture3
40
+ # therefore ignore metatest files when running on JRuby
41
+ if RUBY_ENGINE == 'jruby'
42
+ REGTEST_FILES_RB.reject! {|fn| fn =~ /metatest/}
38
43
  end
39
44
 
40
45
  task :test => :regtest
data/lib/regtest.rb CHANGED
@@ -3,83 +3,112 @@
3
3
  #
4
4
  # Regtest - Simple Regression Testing With Ruby
5
5
  #
6
- # Copyright 2014, 2015, 2017 by Jan Friedrich <janfri26@gmail.com>
6
+ # Copyright 2014, 2015, 2017-2019 by Jan Friedrich <janfri26@gmail.com>
7
7
  # License: Regtest is licensed under the same terms as Ruby itself.
8
8
  #
9
9
 
10
10
  require 'ostruct'
11
11
  require 'regtest/version'
12
+ require 'set'
12
13
  require 'yaml'
13
14
 
14
15
  module Regtest
15
16
 
16
- @start = Time.now
17
+ extend self
18
+
19
+ @start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
17
20
  @results = {}
18
- @statistics = []
21
+ @log_filenames = Set.new
19
22
  @exit_codes = Hash.new(1)
20
23
  @exit_codes.merge!({success: 0, unknown_result: 1, fail: 2})
21
24
 
22
- class << self
25
+ # Define a sample
26
+ def sample name
27
+ h = {}
28
+ name = name.to_s if name.kind_of?(Symbol)
29
+ h['sample'] = name
30
+ begin
31
+ h['result'] = yield
32
+ rescue Exception => e
33
+ h['exception'] = e.message
34
+ end
35
+ output_filename = Regtest.determine_filename_from_caller('.yml')
36
+ unless Regtest.results[output_filename]
37
+ Regtest.report "\n", type: :filename unless Regtest.results.empty?
38
+ Regtest.report output_filename, type: :filename
39
+ Regtest.results[output_filename] = []
40
+ end
41
+ Regtest.results[output_filename] << h
42
+ print '.'; $stdout.flush
43
+ h
44
+ end
23
45
 
24
- attr_reader :exit_codes, :results, :statistics, :start
25
-
26
- # Define a sample
27
- def sample name, &_
28
- start = Time.now
29
- h = {}
30
- name = name.to_s if name.kind_of?(Symbol)
31
- h['sample'] = name
32
- begin
33
- h['result'] = yield
34
- rescue Exception => e
35
- h['exception'] = e.message
36
- end
37
- output_filename = caller.first.split(/:\d+:/).first.sub(/\.rb/, '') << '.yml'
38
- unless Regtest.results[output_filename]
39
- Regtest.report "\n", type: :filename unless Regtest.results.empty?
40
- Regtest.report output_filename, type: :filename
41
- Regtest.results[output_filename] = []
46
+ # Build all combinations of a Hash-like object with arrays as values.
47
+ # Return value is an array of OpenStruct instances.
48
+ #
49
+ # Example:
50
+ # require 'ostruct'
51
+ # require 'regtest'
52
+ #
53
+ # o = OpenStruct.new
54
+ # o.a = [1,2,3]
55
+ # o.b = [:x, :y]
56
+ # Regtest.combinations(o)
57
+ # # => [#<OpenStruct a=1, b=:x>, #<OpenStruct a=1, b=:y>,
58
+ # # #<OpenStruct a=2, b=:x>, #<OpenStruct a=2, b=:y>,
59
+ # # #<OpenStruct a=3, b=:x>, #<OpenStruct a=3, b=:y>]
60
+ def combinations hashy
61
+ h = hashy.to_h
62
+ a = h.values[0].product(*h.values[1..-1])
63
+ res = []
64
+ a.each do |e|
65
+ o = OpenStruct.new
66
+ h.keys.zip(e) do |k, v|
67
+ o[k] = v
42
68
  end
43
- Regtest.results[output_filename] << h
44
- print '.'; $stdout.flush
45
- stop = Time.now
46
- Regtest.statistics << OpenStruct.new(filename: output_filename, sample: name, time: stop - start)
47
- name
69
+ res << o
48
70
  end
71
+ res
72
+ end
49
73
 
50
- # Build all combinations of a Hash-like object with arrays as values.
51
- # Return value is an array of OpenStruct instances.
52
- #
53
- # Example:
54
- # require 'ostruct'
55
- # require 'regtest'
56
- #
57
- # o = OpenStruct.new
58
- # o.a = [1,2,3]
59
- # o.b = [:x, :y]
60
- # Regtest.combinations(o)
61
- # # => [#<OpenStruct a=1, b=:x>, #<OpenStruct a=1, b=:y>,
62
- # # #<OpenStruct a=2, b=:x>, #<OpenStruct a=2, b=:y>,
63
- # # #<OpenStruct a=3, b=:x>, #<OpenStruct a=3, b=:y>]
64
- def combinations hashy
65
- h = hashy.to_h
66
- a = h.values[0].product(*h.values[1..-1])
67
- res = []
68
- a.each do |e|
69
- o = OpenStruct.new
70
- h.keys.zip(e) do |k, v|
71
- o[k] = v
72
- end
73
- res << o
74
- end
75
- res
74
+ # Write (temporary) informations to a log file
75
+ # By default the log file is truncated at the first call of Regtest.log for
76
+ # each run of regtest, and all following calls appends to the log file. So
77
+ # you have a log for one run of regtest. You can use mode ('a' or 'w') to
78
+ # change this behaviour for each call of Regtest.log.
79
+ def log s, mode: nil
80
+ log_filename = Regtest.determine_filename_from_caller('.log')
81
+ case mode
82
+ when nil
83
+ mode = Regtest.log_filenames.include?(log_filename) ? 'a' : 'w'
84
+ when 'a', 'w'
85
+ # ok
86
+ else
87
+ raise ArgumentError.new(format('Mode %s is not allowed.', mode))
88
+ end
89
+ Regtest.log_filenames << log_filename
90
+ File.open log_filename, mode do |f|
91
+ f.puts s
92
+ end
93
+ end
94
+
95
+ class << self
96
+
97
+ attr_reader :exit_codes, :log_filenames, :results, :start
98
+
99
+ # Determine a filename which is derived from the filename of the "real"
100
+ # caller of the calling method
101
+ # @param ext new extension (i.e. '.yml')
102
+ def determine_filename_from_caller ext
103
+ caller_locations(2, 1).first.path.sub(/\.rb$/, '') << ext.to_s
76
104
  end
77
105
 
78
106
  # Report some statistics, could be overwritten by plugins.
79
107
  def report_statistics
80
- time = Time.now - start
81
- sample_count = statistics.size
82
- report format("\n\n%d samples executed in %.2f s (%.2f samples/s)", sample_count, time, sample_count / time), type: :statistics
108
+ now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
109
+ time = now - start
110
+ sample_count = results.values.map(&:size).reduce(0, &:+)
111
+ report format("\n\n%d samples executed in %.2f s (%d samples/s)", sample_count, time, sample_count / time), type: :statistics
83
112
  end
84
113
 
85
114
  # Save all results to the corresponding files.
@@ -102,7 +131,7 @@ module Regtest
102
131
  end
103
132
 
104
133
  # Report text to output with possible type, could be overwritten
105
- # by plugins e.g. regtest/colorize.
134
+ # by plugins e.g. regtest/colors.
106
135
  def report *args, type: nil
107
136
  puts *args
108
137
  end
@@ -1,47 +1,8 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
- begin
5
- module Regtest
4
+ require 'regtest/colors'
6
5
 
7
- # Regtest plugin to have colorized reports.
8
- # It uses the great colorize gem
9
- # (see https://rubygems.org/gems/colorize)
10
- module Colorize
6
+ Regtest::Colorize = Regtest::Colors
11
7
 
12
- @mapping = (%i(success fail unknown_result filename statistics).zip %i(green red yellow cyan default)).to_h
13
-
14
- class << self
15
- # Color mapping (all parameters of ColorizedString.colorize are supported
16
- # (see https://github.com/fazibear/colorize#usage)
17
- # Examples:
18
- # Regtest::Colorize.mapping[:filename] = :light_blue
19
- # Regtest::Colorize.mapping[:statistics] = {color: :cyan, mode: :italic}
20
- attr_accessor :mapping
21
- end
22
-
23
- require 'colorized_string'
24
- # If loading of colorized_string (gem colorize) fails the accessor above is
25
- # available in .regtestrc files but method redefinition of Regtest.report and
26
- # prepending of Colorize is skipped.
27
-
28
- # Redefine Regtest.report.
29
- def report *args, type: nil
30
- color = Colorize.mapping[type]
31
- if color && $stdout.tty?
32
- args = args.map {|a| ColorizedString[a.to_s].colorize(color)}
33
- end
34
- puts *args
35
- end
36
-
37
- end
38
-
39
- class << self
40
- prepend Colorize
41
- end
42
-
43
- end
44
- rescue LoadError
45
- warn 'gem colorize not found'
46
- warn 'plugin regtest/colorize disabled'
47
- end
8
+ warn 'regtest/colorize is deprecated. use regtest/colors instead.'