regtest 1.1.0 → 2.0.0.pre

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: 0e25e74bc6bf4d1abf0c84fe8f7602b0bc355385
4
- data.tar.gz: 80178a4963af2aebd6cb87d9c9e57fc7dc359dd8
3
+ metadata.gz: 9a917267b567e320d9f372ad942f4602282c42b4
4
+ data.tar.gz: d2e5e0da3b36b4190db29449c188b31ff6072f23
5
5
  SHA512:
6
- metadata.gz: 32e29f778fa7128b743fab14bd29834d9a52c2f226e13a46d473e538c64962965df1ef9b622bf35462a60c4e568cf6d88b6aa282c34302debc05b5af87058e87
7
- data.tar.gz: 1dfba5fe46becc517109a06670ccebcbabb930fc032570e67f34195649495a3d7b0f32f329887e8e7ed92dc4d492da507df275bcd4f13b8a4351f63b4dedb41e
6
+ metadata.gz: 2b439502a95aa227425959e0de2be46d09d71233a3fc70b62a01220650464584d5a8ff1498ffcd41b9197679ad1b69e441d477b91a648a0ccb1910ec28b9cd5c
7
+ data.tar.gz: 6e3b8462a54c051a5d1ae795572c6ba5871f07df53359c21c34c2eada095b23eab01fc0176e1afa9b17bc6efcdeca48fb9c8e2bddeca03b9911b91cc5b150528
@@ -0,0 +1,25 @@
1
+ personal_ws-1.1 en 24
2
+ NOREGTESTRC
3
+ dir
4
+ Bugfix
5
+ ostruct
6
+ ENV
7
+ filename
8
+ Gemfile
9
+ basename
10
+ Rakefile
11
+ exiftool
12
+ yml
13
+ yaml
14
+ workflow
15
+ refactoring
16
+ metatests
17
+ catched
18
+ regtest
19
+ rb
20
+ rc
21
+ Friedrich
22
+ SCM
23
+ regtestrc
24
+ metatest
25
+ OpenStruct
data/Changelog CHANGED
@@ -1,3 +1,29 @@
1
+ 2.0.0.pre Major Release
2
+
3
+ Incompatibilities to regtest 1.x
4
+ 1. The methods sample and combinations are not longer defined as instance
5
+ methods but as as module methods only. Therefore you can't use it as mixed in
6
+ methods via include.
7
+ 2. The exit code of regtest is now by default 1 if there are no plugins used which
8
+ check the results like regtest/git.
9
+ 3. Regtest needs Ruby version 2.1 or higher.
10
+
11
+ New Features
12
+ Regtest can now be customized with a .regtestrc file in the home directory
13
+ and/or actual directory. If ENV['NOREGTESTRC'] is set then .regtestrc files
14
+ will not be loaded.
15
+ A simple plugin mechanism is implemented and two plugins are part of regtest:
16
+ regtest/colorize and regtest/git. Plugins are usual activated by require in
17
+ one of the .regtestrc files.
18
+
19
+ 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.
22
+ Some metatests are added.
23
+ Version constant Regtest::VERSION is also added.
24
+ A lot of internal refactoring and improving documentation.
25
+
26
+
1
27
  1.1.0
2
28
  Remove output of statistics for writing files: It's not useful.
3
29
  Report filename of generated results not only the basename of it.
data/README.md CHANGED
@@ -1,13 +1,16 @@
1
- # Regtest - Simple Regression Testing For Ruby Projects
1
+ # Regtest - Simple Regression Testing With Ruby
2
2
 
3
3
  ## Description
4
4
 
5
- This library support a very simple way to do regression testing in Ruby
6
- projects. You write Ruby scripts with samples. Run these and get the sample
7
- results as YAML output besides your scripts. Check both the scripts and the YAML
8
- files with the results in you Source Code Control System. When you run the
9
- scrips on a later (or even previous) version of your code a simple diff show you
10
- if and how the changes in your code impact the results of your samples.
5
+ This library supports a very simple way to do regression testing with Ruby. It
6
+ is not limited to Ruby projects you can use it also in other contexts where you
7
+ can extract data with Ruby.
8
+
9
+ You write Ruby scripts with samples. Run these and get the sample results as
10
+ results files besides your scripts. Check both the scripts and the results
11
+ files in you Source Code Management System (SCM). When you run the scrips on a
12
+ later (or even previous) version of your code a simple diff show you if and how
13
+ the changes in your code or environment impact the results of your samples.
11
14
 
12
15
  This is not a replacement for unit testing but a complement: You can produce a
13
16
  lot of samples with a small amount of Ruby code (e.g. a large number of
@@ -27,7 +30,7 @@ or add
27
30
  ```ruby
28
31
  gem 'regtest'
29
32
  ```
30
- to your Gemfile or put a copy of `regtest.rb` in your project.
33
+ to your Gemfile.
31
34
 
32
35
 
33
36
  ## Using
@@ -35,9 +38,11 @@ to your Gemfile or put a copy of `regtest.rb` in your project.
35
38
  The idea behind regtest is the following workflow:
36
39
  1. Writing samples
37
40
  2. Running samples
38
- 3. Checking results (differences between the actual results and the results of
39
- a previous run of your samples using the diff functionality of your Source
40
- Code Control System)
41
+ 3. Commit samples and result files to SCM.
42
+ 4. Change your code and / or external environment.
43
+ 5. Rerun your samples
44
+ 6. Check sample results for changes (this is normally automatically done with
45
+ a regtest plugin like regtest/git).
41
46
 
42
47
 
43
48
  ### Writing Samples
@@ -62,15 +67,13 @@ end
62
67
  ```
63
68
 
64
69
  The name of the sample (parameter of the `Regtest.sample` method) and the
65
- results of the samples (return value of the block) are stored in YAML format. So
66
- it should be a YAML friendly value as `String`, `Number`, `Boolean value`,
67
- `Symbol`. Results could also be an `Array` or `Hash` with such values.
68
-
69
-
70
- #### Helpers
70
+ results of the samples (return value of the block) are stored in YAML format.
71
+ So it should be a YAML-friendly value as `String`, `Number`, `Boolean value`,
72
+ `Symbol`. Results could also be an `Array` or `Hash` with such values.
71
73
 
72
- There is a method `Regtest.combinations` to generate a lot of combinations the
73
- easy way. An example:
74
+ In many cases you want to generate a lot of combinations of input data in your
75
+ sample code. For this there is a method `Regtest.combinations` to generate a
76
+ lot of combinations the easy way. An example:
74
77
 
75
78
  ```ruby
76
79
  require 'ostruct'
@@ -79,23 +82,14 @@ require 'regtest'
79
82
  o = OpenStruct.new
80
83
  o.a = [1,2,3]
81
84
  o.b = [:x, :y]
82
- Regtest.combinations(o).map(&:to_h)
83
- # => [{:a=>1, :b=>:x}, {:a=>1, :b=>:y}, {:a=>2, :b=>:x}, {:a=>2, :b=>:y}, {:a=>3, :b=>:x}, {:a=>3, :b=>:y}]
85
+ Regtest.combinations(o)
86
+ # => [#<OpenStruct a=1, b=:x>, #<OpenStruct a=1, b=:y>,
87
+ # #<OpenStruct a=2, b=:x>, #<OpenStruct a=2, b=:y>,
88
+ # #<OpenStruct a=3, b=:x>, #<OpenStruct a=3, b=:y>]
84
89
  ```
85
90
 
86
91
  See also the combinations example in the `regtest` folder.
87
92
 
88
- You can also include `Regtest` to have the `sample` and `combinations method at top level.
89
-
90
- ```ruby
91
- require 'regtest'
92
- include Regtest
93
-
94
- sample :x do
95
- :x
96
- end
97
- ```
98
-
99
93
  By convention sample files are stored in a directory `regtest` in your Ruby application.
100
94
 
101
95
 
@@ -119,7 +113,7 @@ to your `Rakefile` and you can run your samples with `rake regtest`.
119
113
  ### Checking Results
120
114
 
121
115
  The results of each samples file are stored as a collection of YAML documents in
122
- a corresponding results file (YAML) per samples file. For example for the
116
+ a corresponding results file per samples file. For example for the
123
117
  samples files
124
118
 
125
119
  ```sh
@@ -145,14 +139,69 @@ sample: Division by zero
145
139
  exception: divided by 0
146
140
  ```
147
141
 
148
- Note: Each sample is represented by a YAML document in the corresponding YAML
149
- file.
150
-
151
- Each time you run one ore more samples file the corresponding results file will
142
+ Each time you run one ore more samples file the corresponding results files will
152
143
  be overwritten (or generated if not yet existent) with the actual result values
153
- of your samples. So Source Code Version Control program is the tool to
154
- determine changes between older runs of the samples. Therefore the samples file
155
- and their corresponding results files should be taken under version control.
144
+ of your samples. The determination of changes between the results of actual and
145
+ older runs of the samples is done by your SCM. So the sample files and their
146
+ corresponding results files should be taken under version control.
147
+
148
+
149
+ ## Configuration and Plugins
150
+
151
+ You can adapt the behaviour of regtest with plugins. To configure this and
152
+ maybe other things regtest support a simple rc file mechanism. While loading
153
+ regtest via `require 'regtest'` it looks for a file `.regtestrc` first in your
154
+ home directory and then in the local directory. So you can do global
155
+ configurations in the first one and project specific configurations in the
156
+ latter.
157
+
158
+ For example the following is a good default when you want colorized output and
159
+ use git as your SCM:
160
+
161
+ ```ruby
162
+ require 'regtest/colorize'
163
+ # adapt some colorizing if wanted
164
+ Regtest::Colorize.mapping[:filename] = :blue
165
+ Regtest::Colorize.mapping[:statistics] = {mode: :italic}
166
+
167
+ require 'regtest/git'
168
+ ```
169
+
170
+ Normally the check of changes in results is done automatically by a regtest
171
+ plugin like regtest/git (see example for `.regtestrc` above). In this case the
172
+ report will show you if there are changes or not and the exit code of the
173
+ script is accordingly set. The standard values are: 0 for success, 1 for an
174
+ unknown result (normally a new results file) and 2 for failure. If you use
175
+ plain regtest without a SCM plugin the exit code is 1 (= unknown result).
176
+
177
+ You can change the exit codes for the states with `Regtest.exit_codes` for example:
178
+
179
+ ```ruby
180
+ Regtest.exit_codes[:unknown_result] = 0
181
+ Regtest.exit_codes[:fail] = 0
182
+ ```
183
+
184
+ This also should be don in a `.regtest` file and not in the sample files.
185
+
186
+ Because in a `.regtestrc` file are individual configuration aspects of your
187
+ workflow and environment it should not be checked into your SCM.
188
+
189
+ ## Rake task
190
+
191
+ Regtest includes a Rake task `regtest`. Per default it runs any `.rb` files
192
+ under the `regtest` directory and includes all files under the `regtest`
193
+ directory to the files packaged with gem.
194
+ You can change these defaults like this
195
+
196
+ ```ruby
197
+ require 'regtest/task'
198
+
199
+ REGTEST_FILES_RB.clear << 'my_regtest_file.rb'
200
+ REGTEST_FILES.clear << 'my_regtest_file.rb' << 'my_regtest_file.yml' << 'other_file'
201
+ ```
202
+
203
+ It's a little bit old school like `CLEAN` and `CLOBBER` but I like the simple
204
+ approach to use constants.
156
205
 
157
206
 
158
207
  ## Further information
data/Rakefile CHANGED
@@ -1,35 +1,41 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
 
4
+ $:.unshift 'lib'
5
+
4
6
  require 'rim/tire'
5
7
  require 'rim/regtest'
6
8
  require 'rim/version'
7
9
 
8
- $:.unshift 'lib'
9
10
  require 'regtest/task'
11
+ require 'regtest/version'
10
12
 
11
13
  Rim.setup do |p|
12
14
  p.name = 'regtest'
13
- p.version = '1.1.0'
15
+ p.version = Regtest::VERSION
14
16
  p.authors = 'Jan Friedrich'
15
17
  p.email = 'janfri26@gmail.com'
16
- p.summary = 'Simple regression testing for Ruby projects.'
18
+ p.summary = 'Simple regression testing with Ruby.'
17
19
  p.license = 'Ruby'
18
20
  p.description = <<-END.gsub(/^ +/, '')
19
- This library support a very simple way to do regression testing in Ruby
20
- projects. You write Ruby scripts with samples. Run these and get the sample
21
- results as YAML output besides your scripts. Check both the scripts and the YAML
22
- files with the results in you Source Code Control System. When you run the
23
- scrips on a later (or even previous) version of your code a simple diff show you
24
- if and how the changes in your code impact the results of your samples.
21
+ This library supports a very simple way to do regression testing with Ruby. It
22
+ is not limited to Ruby projects you can use it also in other contexts where you
23
+ can extract data with Ruby.
24
+
25
+ You write Ruby scripts with samples. Run these and get the sample results as
26
+ results files besides your scripts. Check both the scripts and the results
27
+ files in you Source Code Management System (SCM). When you run the scrips on a
28
+ later (or even previous) version of your code a simple diff show you if and how
29
+ the changes in your code or environment impact the results of your samples.
25
30
 
26
31
  This is not a replacement for unit testing but a complement: You can produce a
27
32
  lot of samples with a small amount of Ruby code (e.g. a large number of
28
33
  combinations of data).
29
34
  END
30
35
  p.homepage = 'https://github.com/janfri/regtest'
36
+ p.ruby_version = '>=2.1.0'
37
+ p.dependencies << %w(colorize ~>0.8)
31
38
  end
32
39
 
33
- task :test do
34
- # nothing
35
- end
40
+ task :test => :regtest
41
+ task :default => :test
@@ -1,73 +1,88 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
  #
4
- # Regtest - Simple Regression Testing For Ruby Projects
4
+ # Regtest - Simple Regression Testing With Ruby
5
5
  #
6
6
  # Copyright 2014, 2015, 2017 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
+ require 'regtest/version'
11
12
  require 'yaml'
12
13
 
13
14
  module Regtest
14
15
 
15
- @count = 0
16
- @results = {}
17
16
  @start = Time.now
17
+ @results = {}
18
+ @statistics = []
19
+ @exit_codes = Hash.new(1)
20
+ @exit_codes.merge!({success: 0, unknown_result: 1, fail: 2})
18
21
 
19
- def sample name
20
- h = {}
21
- name = name.to_s if name.kind_of?(Symbol)
22
- h['sample'] = name
23
- begin
24
- h['result'] = yield
25
- rescue Exception => e
26
- h['exception'] = e.message
27
- end
28
- output_filename = caller.first.split(/:/).first.sub(/\.rb/, '') << '.yml'
29
- unless Regtest.results[output_filename]
30
- puts unless Regtest.results.empty?
31
- puts output_filename
32
- Regtest.results[output_filename] = []
33
- end
34
- Regtest.results[output_filename] << h
35
- Regtest.count += 1
36
- print '.'; $stdout.flush
37
- end
22
+ class << self
23
+
24
+ attr_reader :exit_codes, :results, :statistics, :start
38
25
 
39
- # Build all combinations of a Hash-like object with arrays as values.
40
- # Return value is an array of OpenStruct instances.
41
- #
42
- # Example:
43
- # require 'ostruct'
44
- # o = OpenStruct.new
45
- # o.a = [1,2,3]
46
- # o.b = [:x, :y]
47
- # Regtest.combinations(o).map(&:to_h) # => [{:a=>1, :b=>:x}, {:a=>1, :b=>:y}, {:a=>2, :b=>:x}, {:a=>2, :b=>:y}, {:a=>3, :b=>:x}, {:a=>3, :b=>:y}]
48
- #
49
- def combinations hashy
50
- h = hashy.to_h
51
- a = h.values[0].product(*h.values[1..-1])
52
- res = []
53
- a.each do |e|
54
- o = OpenStruct.new
55
- h.keys.zip(e) do |k, v|
56
- o[k] = v
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
57
36
  end
58
- res << o
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] = []
42
+ 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
59
48
  end
60
- res
61
- end
62
49
 
63
- class << self
64
- attr_accessor :count, :results, :start
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
76
+ end
65
77
 
66
- def report
78
+ # Report some statistics, could be overwritten by plugins.
79
+ def report_statistics
67
80
  time = Time.now - start
68
- puts format("\n\n%d samples executed in %.2f s (%.2f samples/s)", count, time, count / time)
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
69
83
  end
70
84
 
85
+ # Save all results to the corresponding files.
71
86
  def save
72
87
  results.each_pair do |filename, arr|
73
88
  File.open(filename, 'w') do |f|
@@ -77,14 +92,34 @@ module Regtest
77
92
  end
78
93
  end
79
94
  end
95
+
96
+ # Checking results, should be overwritten by SCM plugins
97
+ # e.g. regtest/git
98
+ # @return Symbol with check result (one of :success, :unknown_result or :fail)
99
+ def check_results
100
+ report "\nPlease check result files manually. Regtest isn't able to do that.", type: :unknown_result
101
+ :unknown_result
102
+ end
103
+
104
+ # Report text to output with possible type, could be overwritten
105
+ # by plugins e.g. regtest/colorize.
106
+ def report *args, type: nil
107
+ puts *args
108
+ end
80
109
  end
81
110
 
82
- module_function :sample, :combinations
111
+ end
83
112
 
113
+ # Load .regtestrc from home directory and actual directory if exists
114
+ # and ENV['NOREGTESTRC'] is not set.
115
+ unless ENV['NOREGTESTRC']
116
+ Dir[File.join(Dir.home, '.regtestrc'), '.regtestrc'].each {|fn| load fn}
84
117
  end
85
118
 
86
119
  at_exit do
87
120
  ARGV.each {|a| load a}
88
- Regtest.report
89
121
  Regtest.save
122
+ Regtest.report_statistics
123
+ check_state = Regtest.check_results
124
+ exit Regtest.exit_codes[check_state]
90
125
  end
@@ -0,0 +1,47 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ begin
5
+ module Regtest
6
+
7
+ # Regtest plugin to have colorized reports.
8
+ # It uses the great colorize gem
9
+ # (see https://rubygems.org/gems/colorize)
10
+ module Colorize
11
+
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
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'open3'
5
+
6
+ # Check if git is available and current directory is part of a git repository.
7
+ begin
8
+ _, ps = Open3.capture2e('git status --porcelain')
9
+ if ps.exitstatus == 0
10
+ module Regtest
11
+
12
+ # Regtest plugin for git (results are checked automatically when running
13
+ # regtest)
14
+ module Git
15
+
16
+ # Redefine Regtest.check_results.
17
+ def check_results
18
+ output_files = Regtest.results.keys
19
+ if output_files.empty?
20
+ report "\nNothing to do.", type: :success
21
+ return :success
22
+ end
23
+ git_stat, _, _ = Open3.capture3(*%w(git status --porcelain --), *output_files)
24
+ case git_stat
25
+ when /^.M/ # at least one modified file
26
+ report "\nThere are changes in your sample results!", type: :fail
27
+ system *%w(git status -s --), *output_files
28
+ return :fail
29
+ when /^.\?/ # at least one unknown file
30
+ report "\nThere is at least one new sample result file.", type: :unknown_result
31
+ system *%w(git status -s --), *output_files
32
+ return :unknown_result
33
+ when '', /^. / # no changes in (maybe staged) files
34
+ report "\nLooks good. :)", type: :success
35
+ system *%w(git status -s --), *output_files
36
+ return :success
37
+ else
38
+ report "\nYour sample results are in a bad condition!", type: :fail
39
+ system *%w(git status -s --), *output_files
40
+ return :fail
41
+ end
42
+ end
43
+
44
+ end
45
+
46
+ class << self
47
+ prepend Git
48
+ end
49
+
50
+ end
51
+ else
52
+ warn 'current directory is not part of a git repository:'
53
+ warn 'plugin regtest/git disabled'
54
+ end
55
+ rescue Errno::ENOENT
56
+ warn 'git command not found: plugin regtest/git disabled'
57
+ end
@@ -1,15 +1,17 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
3
  #
4
- # Copyright 2014, 2016 by Jan Friedrich <janfri26@gmail.com>
4
+ # Copyright 2014, 2016, 2017 by Jan Friedrich <janfri26@gmail.com>
5
5
  # License: Regtest is licensed under the same terms as Ruby itself.
6
6
  #
7
7
 
8
+ # Regtest sample files (= Ruby files)
8
9
  REGTEST_FILES_RB = FileList.new('regtest/**/*.rb')
9
- REGTEST_FILES_YML = FileList.new('regtest/**/*.yml')
10
- REGTEST_FILES = REGTEST_FILES_RB + REGTEST_FILES_YML
10
+
11
+ # ALL Regtest files (sample files, results files and maybe other files)
12
+ REGTEST_FILES = FileList.new('regtest/**/*').select {|fn| File.file?(fn)}
11
13
 
12
14
  desc 'Run regression tests'
13
15
  task :regtest do
14
- sh "ruby -I lib:regtest #{REGTEST_FILES_RB}"
16
+ sh *%w(ruby -I lib:regtest), *REGTEST_FILES_RB
15
17
  end
@@ -0,0 +1,6 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Regtest
5
+ VERSION = '2.0.0.pre'
6
+ end
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: regtest 1.1.0 ruby lib
2
+ # stub: regtest 2.0.0.pre ruby lib
3
3
  #
4
4
  # This file is automatically generated by rim.
5
5
  # PLEASE DO NOT EDIT IT DIRECTLY!
@@ -7,35 +7,39 @@
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "regtest"
10
- s.version = "1.1.0"
10
+ s.version = "2.0.0.pre"
11
11
 
12
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
+ s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["Jan Friedrich"]
15
- s.date = "2017-08-29"
16
- s.description = "This library support a very simple way to do regression testing in Ruby\nprojects. You write Ruby scripts with samples. Run these and get the sample\nresults as YAML output besides your scripts. Check both the scripts and the YAML\nfiles with the results in you Source Code Control System. When you run the\nscrips on a later (or even previous) version of your code a simple diff show you\nif and how the changes in your code impact the results of your samples.\n\nThis is not a replacement for unit testing but a complement: You can produce a\nlot of samples with a small amount of Ruby code (e.g. a large number of\ncombinations of data).\n"
15
+ s.date = "2017-09-12"
16
+ s.description = "This library supports a very simple way to do regression testing with Ruby. It\nis not limited to Ruby projects you can use it also in other contexts where you\ncan extract data with Ruby.\n\nYou write Ruby scripts with samples. Run these and get the sample results as\nresults files besides your scripts. Check both the scripts and the results\nfiles in you Source Code Management System (SCM). When you run the scrips on a\nlater (or even previous) version of your code a simple diff show you if and how\nthe changes in your code or environment impact the results of your samples.\n\nThis is not a replacement for unit testing but a complement: You can produce a\nlot of samples with a small amount of Ruby code (e.g. a large number of\ncombinations of data).\n"
17
17
  s.email = "janfri26@gmail.com"
18
- s.files = ["Changelog", "Gemfile", "LICENSE", "README.md", "Rakefile", "lib/regtest", "lib/regtest.rb", "lib/regtest/task.rb", "regtest.gemspec", "regtest/combinations.rb", "regtest/combinations.yml", "regtest/example.rb", "regtest/example.yml", "regtest/metatest.rb", "regtest/metatest.yml", "regtest/no_samples.rb"]
18
+ s.files = ["./.aspell.pws", "Changelog", "Gemfile", "LICENSE", "README.md", "Rakefile", "lib/regtest", "lib/regtest.rb", "lib/regtest/colorize.rb", "lib/regtest/git.rb", "lib/regtest/task.rb", "lib/regtest/version.rb", "regtest.gemspec", "regtest/combinations.rb", "regtest/combinations.yml", "regtest/example.rb", "regtest/example.yml", "regtest/filename with spaces.rb", "regtest/filename with spaces.yml", "regtest/metatest.rb", "regtest/metatest.yml", "regtest/metatest_git.rb", "regtest/metatest_git.yml", "regtest/no_samples.rb"]
19
19
  s.homepage = "https://github.com/janfri/regtest"
20
20
  s.licenses = ["Ruby"]
21
- s.rubygems_version = "2.6.12"
22
- s.summary = "Simple regression testing for Ruby projects."
21
+ s.required_ruby_version = Gem::Requirement.new(">= 2.1.0")
22
+ s.rubygems_version = "2.6.13"
23
+ s.summary = "Simple regression testing with Ruby."
23
24
 
24
25
  if s.respond_to? :specification_version then
25
26
  s.specification_version = 4
26
27
 
27
28
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
28
- s.add_development_dependency(%q<rake>, ["< 100", "> 0"])
29
- s.add_development_dependency(%q<rim>, ["~> 2.12"])
29
+ s.add_runtime_dependency(%q<colorize>, ["~> 0.8"])
30
+ s.add_development_dependency(%q<rake>, [">= 0"])
31
+ s.add_development_dependency(%q<rim>, ["~> 2.15"])
30
32
  s.add_development_dependency(%q<regtest>, ["~> 1.0"])
31
33
  else
32
- s.add_dependency(%q<rake>, ["< 100", "> 0"])
33
- s.add_dependency(%q<rim>, ["~> 2.12"])
34
+ s.add_dependency(%q<colorize>, ["~> 0.8"])
35
+ s.add_dependency(%q<rake>, [">= 0"])
36
+ s.add_dependency(%q<rim>, ["~> 2.15"])
34
37
  s.add_dependency(%q<regtest>, ["~> 1.0"])
35
38
  end
36
39
  else
37
- s.add_dependency(%q<rake>, ["< 100", "> 0"])
38
- s.add_dependency(%q<rim>, ["~> 2.12"])
40
+ s.add_dependency(%q<colorize>, ["~> 0.8"])
41
+ s.add_dependency(%q<rake>, [">= 0"])
42
+ s.add_dependency(%q<rim>, ["~> 2.15"])
39
43
  s.add_dependency(%q<regtest>, ["~> 1.0"])
40
44
  end
41
45
  end
@@ -5,13 +5,13 @@ require 'regtest'
5
5
 
6
6
  Regtest.sample 'String result' do
7
7
  # Doing something to get the result of the sample
8
- # and make sure it is the result of the block
8
+ # and make sure it is the result of the block.
9
9
  'some text'
10
10
  end
11
11
 
12
12
  Regtest.sample 'Division by zero' do
13
13
  # If an exception occurs while execution of the
14
14
  # block it is catched and its message is used as
15
- # exception value for the sample
15
+ # exception value for the sample.
16
16
  2 / 0
17
17
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'regtest'
5
+
6
+ Regtest.sample 'spaces in filenames' do
7
+ "If you can read this in the results file #{File.basename(__FILE__.sub(/\.rb/, '.yml')).inspect} than regtest can handle filenames with spaces. :)"
8
+ end
@@ -0,0 +1,4 @@
1
+ ---
2
+ sample: spaces in filenames
3
+ result: If you can read this in the results file "filename with spaces.yml" than regtest
4
+ can handle filenames with spaces. :)
@@ -9,17 +9,19 @@ require 'tmpdir'
9
9
  Dir.mktmpdir('regtest') do |tmpdir|
10
10
  Dir.chdir __dir__ do
11
11
  Dir['*.rb'].each do |filename|
12
- # beware of endless recursion
12
+ # Beware of endless recursion.
13
13
  next if filename =~ /metatest/
14
14
  FileUtils.cp filename, tmpdir
15
15
  end
16
16
  end
17
17
  Dir.chdir tmpdir do
18
- _, o, e = Open3.popen3("ruby -I #{File.join(__dir__, '../lib')} #{Dir['*.rb'].sort.join(' ')}")
18
+ lib_dir = File.join(__dir__, '../lib')
19
+ o, e, ps = Open3.capture3(*[{'NOREGTESTRC' => 'true'}, 'ruby', '-I', lib_dir], *Dir['*.rb'].sort)
19
20
  Regtest.sample 'metatest' do
20
- res = {'stdout' => o.read, 'stderr' => e.read}
21
- # levelling runtime specific values
21
+ res = {'stdout' => o, 'stderr' => e}
22
+ # Levelling out runtime specific differences.
22
23
  res['stdout'].gsub!(/\d+\.\d+/, 'x.xx')
24
+ res['exitstatus'] = ps.exitstatus
23
25
  res
24
26
  end
25
27
  end
@@ -6,6 +6,11 @@ result:
6
6
  ......
7
7
  example.yml
8
8
  ..
9
+ filename with spaces.yml
10
+ .
9
11
 
10
- 8 samples executed in x.xx s (x.xx samples/s)
12
+ 9 samples executed in x.xx s (x.xx samples/s)
13
+
14
+ Please check result files manually. Regtest isn't able to do that.
11
15
  stderr: ''
16
+ exitstatus: 1
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ # If git isn't available skip this file
5
+ begin
6
+ Open3.capture2e('git --version')
7
+
8
+ require 'fileutils'
9
+ require 'open3'
10
+ require 'regtest/git'
11
+ require 'tmpdir'
12
+
13
+ def create_sample name
14
+ lib_dir = File.join(__dir__, '../lib')
15
+ o, e, ps = Open3.capture3(*[{'NOREGTESTRC' => 'true'}, 'ruby', '-I', lib_dir, '-r', 'regtest/git'], *Dir['*.rb'].sort)
16
+ Regtest.sample name do
17
+ res = {'stdout' => o, 'stderr' => e}
18
+ # Levelling out runtime specific differences.
19
+ res['stdout'].gsub!(/\d+\.\d+/, 'x.xx')
20
+ res['stdout'].gsub!(%r(\d+ samples/s), 'x samples/s')
21
+ res['exitstatus'] = ps.exitstatus
22
+ res
23
+ end
24
+ end
25
+
26
+ def execute cmd
27
+ Open3.capture2e cmd
28
+ end
29
+
30
+ NEW_SAMPLE = <<-END
31
+
32
+ Regtest.sample 'new sample' do
33
+ 'new sample'
34
+ end
35
+ END
36
+
37
+ Dir.mktmpdir('regtest') do |tmpdir|
38
+ Dir.chdir __dir__ do
39
+ Dir['*.rb'].each do |filename|
40
+ # Beware of endless recursion.
41
+ next if filename =~ /metatest/
42
+ FileUtils.cp filename, tmpdir
43
+ end
44
+ end
45
+ Dir.chdir tmpdir do
46
+ execute 'git init'
47
+ create_sample 'all new'
48
+ execute 'git add *.rb example.yml combinations.yml'
49
+ create_sample 'only one new'
50
+ example_rb = File.read('example.rb')
51
+ example_rb << NEW_SAMPLE
52
+ File.write('example.rb', example_rb)
53
+ create_sample 'one new one modified to index'
54
+ execute 'git commit -m "commit"'
55
+ create_sample 'one new one modified'
56
+ execute 'git add *.yml'
57
+ create_sample 'all in index'
58
+ execute 'git commit -m "commit"'
59
+ create_sample 'all commited'
60
+ end
61
+ end
62
+ rescue Errno::ENOENT
63
+ end
@@ -0,0 +1,109 @@
1
+ ---
2
+ sample: all new
3
+ result:
4
+ stdout: |
5
+ combinations.yml
6
+ ......
7
+ example.yml
8
+ ..
9
+ filename with spaces.yml
10
+ .
11
+
12
+ 9 samples executed in x.xx s (x.xx samples/s)
13
+
14
+ There is at least one new sample result file.
15
+ ?? combinations.yml
16
+ ?? example.yml
17
+ ?? filename with spaces.yml
18
+ stderr: ''
19
+ exitstatus: 1
20
+ ---
21
+ sample: only one new
22
+ result:
23
+ stdout: |
24
+ combinations.yml
25
+ ......
26
+ example.yml
27
+ ..
28
+ filename with spaces.yml
29
+ .
30
+
31
+ 9 samples executed in x.xx s (x.xx samples/s)
32
+
33
+ There is at least one new sample result file.
34
+ A combinations.yml
35
+ A example.yml
36
+ ?? filename with spaces.yml
37
+ stderr: ''
38
+ exitstatus: 1
39
+ ---
40
+ sample: one new one modified to index
41
+ result:
42
+ stdout: |
43
+ combinations.yml
44
+ ......
45
+ example.yml
46
+ ...
47
+ filename with spaces.yml
48
+ .
49
+
50
+ 10 samples executed in x.xx s (x.xx samples/s)
51
+
52
+ There are changes in your sample results!
53
+ A combinations.yml
54
+ AM example.yml
55
+ ?? filename with spaces.yml
56
+ stderr: ''
57
+ exitstatus: 2
58
+ ---
59
+ sample: one new one modified
60
+ result:
61
+ stdout: |
62
+ combinations.yml
63
+ ......
64
+ example.yml
65
+ ...
66
+ filename with spaces.yml
67
+ .
68
+
69
+ 10 samples executed in x.xx s (x.xx samples/s)
70
+
71
+ There are changes in your sample results!
72
+ M example.yml
73
+ ?? filename with spaces.yml
74
+ stderr: ''
75
+ exitstatus: 2
76
+ ---
77
+ sample: all in index
78
+ result:
79
+ stdout: |
80
+ combinations.yml
81
+ ......
82
+ example.yml
83
+ ...
84
+ filename with spaces.yml
85
+ .
86
+
87
+ 10 samples executed in x.xx s (x.xx samples/s)
88
+
89
+ Looks good. :)
90
+ M example.yml
91
+ A "filename with spaces.yml"
92
+ stderr: ''
93
+ exitstatus: 0
94
+ ---
95
+ sample: all commited
96
+ result:
97
+ stdout: |
98
+ combinations.yml
99
+ ......
100
+ example.yml
101
+ ...
102
+ filename with spaces.yml
103
+ .
104
+
105
+ 10 samples executed in x.xx s (x.xx samples/s)
106
+
107
+ Looks good. :)
108
+ stderr: ''
109
+ exitstatus: 0
@@ -1,3 +1,8 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'regtest'
5
+
1
6
  # If a Ruby file doesn't contain any sample regtest shouldn't
2
7
  # generate a correspondig YAML file.
3
8
  2 + 2
metadata CHANGED
@@ -1,33 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regtest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 2.0.0.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-29 00:00:00.000000000 Z
11
+ date: 2017-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: colorize
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "<"
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
18
25
  - !ruby/object:Gem::Version
19
- version: '100'
20
- - - ">"
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
21
32
  - !ruby/object:Gem::Version
22
33
  version: '0'
23
34
  type: :development
24
35
  prerelease: false
25
36
  version_requirements: !ruby/object:Gem::Requirement
26
37
  requirements:
27
- - - "<"
28
- - !ruby/object:Gem::Version
29
- version: '100'
30
- - - ">"
38
+ - - ">="
31
39
  - !ruby/object:Gem::Version
32
40
  version: '0'
33
41
  - !ruby/object:Gem::Dependency
@@ -36,14 +44,14 @@ dependencies:
36
44
  requirements:
37
45
  - - "~>"
38
46
  - !ruby/object:Gem::Version
39
- version: '2.12'
47
+ version: '2.15'
40
48
  type: :development
41
49
  prerelease: false
42
50
  version_requirements: !ruby/object:Gem::Requirement
43
51
  requirements:
44
52
  - - "~>"
45
53
  - !ruby/object:Gem::Version
46
- version: '2.12'
54
+ version: '2.15'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: regtest
49
57
  requirement: !ruby/object:Gem::Requirement
@@ -59,12 +67,15 @@ dependencies:
59
67
  - !ruby/object:Gem::Version
60
68
  version: '1.0'
61
69
  description: |
62
- This library support a very simple way to do regression testing in Ruby
63
- projects. You write Ruby scripts with samples. Run these and get the sample
64
- results as YAML output besides your scripts. Check both the scripts and the YAML
65
- files with the results in you Source Code Control System. When you run the
66
- scrips on a later (or even previous) version of your code a simple diff show you
67
- if and how the changes in your code impact the results of your samples.
70
+ This library supports a very simple way to do regression testing with Ruby. It
71
+ is not limited to Ruby projects you can use it also in other contexts where you
72
+ can extract data with Ruby.
73
+
74
+ You write Ruby scripts with samples. Run these and get the sample results as
75
+ results files besides your scripts. Check both the scripts and the results
76
+ files in you Source Code Management System (SCM). When you run the scrips on a
77
+ later (or even previous) version of your code a simple diff show you if and how
78
+ the changes in your code or environment impact the results of your samples.
68
79
 
69
80
  This is not a replacement for unit testing but a complement: You can produce a
70
81
  lot of samples with a small amount of Ruby code (e.g. a large number of
@@ -74,20 +85,28 @@ executables: []
74
85
  extensions: []
75
86
  extra_rdoc_files: []
76
87
  files:
88
+ - "./.aspell.pws"
77
89
  - Changelog
78
90
  - Gemfile
79
91
  - LICENSE
80
92
  - README.md
81
93
  - Rakefile
82
94
  - lib/regtest.rb
95
+ - lib/regtest/colorize.rb
96
+ - lib/regtest/git.rb
83
97
  - lib/regtest/task.rb
98
+ - lib/regtest/version.rb
84
99
  - regtest.gemspec
85
100
  - regtest/combinations.rb
86
101
  - regtest/combinations.yml
87
102
  - regtest/example.rb
88
103
  - regtest/example.yml
104
+ - regtest/filename with spaces.rb
105
+ - regtest/filename with spaces.yml
89
106
  - regtest/metatest.rb
90
107
  - regtest/metatest.yml
108
+ - regtest/metatest_git.rb
109
+ - regtest/metatest_git.yml
91
110
  - regtest/no_samples.rb
92
111
  homepage: https://github.com/janfri/regtest
93
112
  licenses:
@@ -101,16 +120,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
101
120
  requirements:
102
121
  - - ">="
103
122
  - !ruby/object:Gem::Version
104
- version: '0'
123
+ version: 2.1.0
105
124
  required_rubygems_version: !ruby/object:Gem::Requirement
106
125
  requirements:
107
- - - ">="
126
+ - - ">"
108
127
  - !ruby/object:Gem::Version
109
- version: '0'
128
+ version: 1.3.1
110
129
  requirements: []
111
130
  rubyforge_project:
112
- rubygems_version: 2.6.12
131
+ rubygems_version: 2.6.13
113
132
  signing_key:
114
133
  specification_version: 4
115
- summary: Simple regression testing for Ruby projects.
134
+ summary: Simple regression testing with Ruby.
116
135
  test_files: []