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 +5 -5
- data/.aspell.pws +28 -15
- data/Changelog +29 -4
- data/LICENSE +1 -1
- data/README.md +85 -4
- data/Rakefile +6 -1
- data/lib/regtest.rb +86 -57
- data/lib/regtest/colorize.rb +3 -42
- data/lib/regtest/colors.rb +63 -0
- data/lib/regtest/task.rb +0 -4
- data/lib/regtest/version.rb +1 -1
- data/regtest.gemspec +13 -20
- data/regtest/{example.rb → examples.rb} +3 -0
- data/regtest/{example.yml → examples.yml} +3 -0
- data/regtest/log.log +3 -0
- data/regtest/log.rb +18 -0
- data/regtest/log.yml +6 -0
- data/regtest/log_append.log +4 -0
- data/regtest/log_append.rb +32 -0
- data/regtest/log_append.yml +18 -0
- data/regtest/log_rewrite.log +1 -0
- data/regtest/log_rewrite.rb +32 -0
- data/regtest/log_rewrite.yml +12 -0
- data/regtest/metatest.rb +5 -2
- data/regtest/metatest.yml +11 -3
- data/regtest/metatest_git.rb +10 -6
- data/regtest/metatest_git.yml +95 -27
- data/regtest/no_samples.rb +1 -1
- data/regtest/toplevel.log +1 -0
- data/regtest/toplevel.rb +30 -0
- data/regtest/toplevel.yml +28 -0
- metadata +27 -29
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b91c5f1f5b30d309f77eaf7c3c218529bd82321a7af578b37c52a4bed09d53e4
|
4
|
+
data.tar.gz: f66632f3eb0f2844ab43068f83c30e62aca2805dad460543436b9df0620c3598
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38257004b8aab5bbad388e430b85362e80b5759be4ca1729756ce0e2704a6cc85f12e3899c17b28df32afc1380251228321f750fb7f8bc4bd951a56e1ca27690
|
7
|
+
data.tar.gz: 2a2f5f808848caccb56db4a4d90a9e34babf70a79d30bf49182317c77081985bcae89289c77acab5ba4a029483330ba3533a37d91be6fbdfc7b63b3cfd397948
|
data/.aspell.pws
CHANGED
@@ -1,25 +1,38 @@
|
|
1
|
-
personal_ws-1.1 en
|
2
|
-
NOREGTESTRC
|
3
|
-
dir
|
1
|
+
personal_ws-1.1 en 26
|
4
2
|
Bugfix
|
5
|
-
ostruct
|
6
3
|
ENV
|
7
|
-
|
4
|
+
Friedrich
|
8
5
|
Gemfile
|
6
|
+
NOREGTESTRC
|
7
|
+
README
|
8
|
+
Regtest
|
9
|
+
SCM
|
10
|
+
SemVer
|
11
|
+
SemVerTag
|
12
|
+
YAML
|
9
13
|
basename
|
10
|
-
|
14
|
+
bitbucket
|
15
|
+
dir
|
11
16
|
exiftool
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
17
|
+
gettime
|
18
|
+
github
|
19
|
+
md
|
20
|
+
metatest
|
16
21
|
metatests
|
17
|
-
catched
|
18
|
-
regtest
|
19
22
|
rb
|
20
23
|
rc
|
21
|
-
|
22
|
-
SCM
|
24
|
+
regtest
|
23
25
|
regtestrc
|
24
|
-
|
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.
|
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
|
21
|
-
|
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
|
-
|
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
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/
|
235
|
+
require 'regtest/colors'
|
163
236
|
# adapt some colorizing if wanted
|
164
|
-
Regtest::
|
165
|
-
Regtest::
|
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
|
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
|
-
|
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
|
-
|
17
|
+
extend self
|
18
|
+
|
19
|
+
@start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
17
20
|
@results = {}
|
18
|
-
@
|
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
|
-
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
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
|
-
|
81
|
-
|
82
|
-
|
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/
|
134
|
+
# by plugins e.g. regtest/colors.
|
106
135
|
def report *args, type: nil
|
107
136
|
puts *args
|
108
137
|
end
|
data/lib/regtest/colorize.rb
CHANGED
@@ -1,47 +1,8 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
|
5
|
-
module Regtest
|
4
|
+
require 'regtest/colors'
|
6
5
|
|
7
|
-
|
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
|
-
|
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.'
|