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.
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ module Regtest
5
+
6
+ module Colors
7
+
8
+ # Redefine Regtest.report
9
+ def report *args, type: nil
10
+ color = Colors.mapping[type]
11
+ if color && $stdout.tty?
12
+ args = args.map {|a| Colors.apply(a.to_s, color)}
13
+ end
14
+ puts *args
15
+ end
16
+
17
+ class << self
18
+ # Color mapping
19
+ # Examples:
20
+ # Regtest::Colors.mapping[:filename] = :lightblue
21
+ # Regtest::Colors.mapping[:fail] = :@red # '@' prefix means background color
22
+ # Regtest::Colors.mapping[:statistics] = %i(cyan italic) # more than one color code is possible
23
+ attr_accessor :mapping
24
+
25
+ # Apply color codes to a string
26
+ def apply str, *codes
27
+ codes.flatten.each do |c|
28
+ num = @codes[c.to_sym]
29
+ fail format('Code %s not supported.', c) unless num
30
+ str = format("\e[%dm%s", num, str)
31
+ end
32
+ format("%s\e[0m", str)
33
+ end
34
+
35
+ # Get available color codes
36
+ def codes
37
+ @codes.keys
38
+ end
39
+ end
40
+
41
+ private
42
+
43
+ @mapping = (%i(success fail unknown_result filename).zip %i(green red yellow blue)).to_h
44
+ @codes = {}
45
+
46
+ %i(bold faint italic underline).each_with_index do |mode, i|
47
+ @codes[mode] = 1 + i
48
+ end
49
+
50
+ %i(black red green yellow blue magenta cyan white).each_with_index do |color, i|
51
+ @codes[color] = 30 + i
52
+ @codes[format('@%s', color).to_sym] = 40 + i
53
+ @codes[format('light%s', color).to_sym] = 90 + i
54
+ @codes[format('@light%s', color).to_sym] = 100 + i
55
+ end
56
+
57
+ end
58
+
59
+ class << self
60
+ prepend Colors
61
+ end
62
+
63
+ end
data/lib/regtest/task.rb CHANGED
@@ -1,9 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # frozen_string_literal: true
3
- #
4
- # Copyright 2014, 2016, 2017 by Jan Friedrich <janfri26@gmail.com>
5
- # License: Regtest is licensed under the same terms as Ruby itself.
6
- #
7
3
 
8
4
  # Regtest sample files (= Ruby files)
9
5
  REGTEST_FILES_RB = FileList.new('regtest/**/*.rb')
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Regtest
5
- VERSION = '2.0.0.pre'
5
+ VERSION = '2.2.1'
6
6
  end
data/regtest.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: regtest 2.0.0.pre ruby lib
2
+ # stub: regtest 2.2.1 ruby lib
3
3
  #
4
4
  # This file is automatically generated by rim.
5
5
  # PLEASE DO NOT EDIT IT DIRECTLY!
@@ -7,39 +7,32 @@
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "regtest"
10
- s.version = "2.0.0.pre"
10
+ s.version = "2.2.1"
11
11
 
12
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
12
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
13
13
  s.require_paths = ["lib"]
14
14
  s.authors = ["Jan Friedrich"]
15
- s.date = "2017-09-12"
15
+ s.date = "2021-02-24"
16
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 = ["./.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"]
18
+ s.files = ["./.aspell.pws", "Changelog", "Gemfile", "LICENSE", "README.md", "Rakefile", "lib/regtest", "lib/regtest.rb", "lib/regtest/colorize.rb", "lib/regtest/colors.rb", "lib/regtest/git.rb", "lib/regtest/task.rb", "lib/regtest/version.rb", "regtest.gemspec", "regtest/combinations.rb", "regtest/combinations.yml", "regtest/examples.rb", "regtest/examples.yml", "regtest/filename with spaces.rb", "regtest/filename with spaces.yml", "regtest/log.log", "regtest/log.rb", "regtest/log.yml", "regtest/log_append.log", "regtest/log_append.rb", "regtest/log_append.yml", "regtest/log_rewrite.log", "regtest/log_rewrite.rb", "regtest/log_rewrite.yml", "regtest/metatest.rb", "regtest/metatest.yml", "regtest/metatest_git.rb", "regtest/metatest_git.yml", "regtest/no_samples.rb", "regtest/toplevel.log", "regtest/toplevel.rb", "regtest/toplevel.yml"]
19
19
  s.homepage = "https://github.com/janfri/regtest"
20
20
  s.licenses = ["Ruby"]
21
21
  s.required_ruby_version = Gem::Requirement.new(">= 2.1.0")
22
- s.rubygems_version = "2.6.13"
22
+ s.rubygems_version = "3.2.3"
23
23
  s.summary = "Simple regression testing with Ruby."
24
24
 
25
25
  if s.respond_to? :specification_version then
26
26
  s.specification_version = 4
27
+ end
27
28
 
28
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
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"])
32
- s.add_development_dependency(%q<regtest>, ["~> 1.0"])
33
- else
34
- s.add_dependency(%q<colorize>, ["~> 0.8"])
35
- s.add_dependency(%q<rake>, [">= 0"])
36
- s.add_dependency(%q<rim>, ["~> 2.15"])
37
- s.add_dependency(%q<regtest>, ["~> 1.0"])
38
- end
29
+ if s.respond_to? :add_runtime_dependency then
30
+ s.add_development_dependency(%q<rake>, [">= 0"])
31
+ s.add_development_dependency(%q<rim>, ["~> 2.17"])
32
+ s.add_development_dependency(%q<regtest>, ["~> 2"])
39
33
  else
40
- s.add_dependency(%q<colorize>, ["~> 0.8"])
41
34
  s.add_dependency(%q<rake>, [">= 0"])
42
- s.add_dependency(%q<rim>, ["~> 2.15"])
43
- s.add_dependency(%q<regtest>, ["~> 1.0"])
35
+ s.add_dependency(%q<rim>, ["~> 2.17"])
36
+ s.add_dependency(%q<regtest>, ["~> 2"])
44
37
  end
45
38
  end
@@ -15,3 +15,6 @@ Regtest.sample 'Division by zero' do
15
15
  # exception value for the sample.
16
16
  2 / 0
17
17
  end
18
+
19
+ # If no block is given => exception no block given (yield)
20
+ Regtest.sample 'no block'
@@ -4,3 +4,6 @@ result: some text
4
4
  ---
5
5
  sample: Division by zero
6
6
  exception: divided by 0
7
+ ---
8
+ sample: no block
9
+ exception: no block given (yield)
data/regtest/log.log ADDED
@@ -0,0 +1,3 @@
1
+ 2085.99375
2
+ 2085.994022
3
+ Logging from outside of a sample works.
data/regtest/log.rb ADDED
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'regtest'
5
+
6
+ Regtest.sample 'test' do
7
+ a = Process.clock_gettime(Process::CLOCK_MONOTONIC)
8
+ Regtest.log a
9
+ b = Process.clock_gettime(Process::CLOCK_MONOTONIC)
10
+ Regtest.log b
11
+ a < b
12
+ end
13
+
14
+ Regtest.sample 'invalid mode' do
15
+ Regtest.log 'foo', mode: 'x'
16
+ end
17
+
18
+ Regtest.log 'Logging from outside of a sample works.'
data/regtest/log.yml ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ sample: test
3
+ result: true
4
+ ---
5
+ sample: invalid mode
6
+ exception: Mode x is not allowed.
@@ -0,0 +1,4 @@
1
+ initial line
2
+ first log entry
3
+ second log entry
4
+ first log entry
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'regtest'
5
+ require 'fileutils'
6
+
7
+
8
+ $log_filename = __FILE__.sub(/\.rb$/, '.log')
9
+
10
+ # set the initial content of the log file
11
+ File.open($log_filename, 'w') do |f|
12
+ f.puts 'initial line'
13
+ end
14
+
15
+ def lines_of_log_file
16
+ File.readlines($log_filename).map(&:chomp) # keyword chomp is not supported by Ruby versions < 2.4
17
+ end
18
+
19
+ Regtest.sample 'first log entry appends to file' do
20
+ Regtest.log 'first log entry', mode: 'a'
21
+ lines_of_log_file
22
+ end
23
+
24
+ Regtest.sample 'second log entry appends to file' do
25
+ Regtest.log 'second log entry'
26
+ lines_of_log_file
27
+ end
28
+
29
+ Regtest.sample 'third log entry appends to file' do
30
+ Regtest.log 'first log entry', mode: 'a'
31
+ lines_of_log_file
32
+ end
@@ -0,0 +1,18 @@
1
+ ---
2
+ sample: first log entry appends to file
3
+ result:
4
+ - initial line
5
+ - first log entry
6
+ ---
7
+ sample: second log entry appends to file
8
+ result:
9
+ - initial line
10
+ - first log entry
11
+ - second log entry
12
+ ---
13
+ sample: third log entry appends to file
14
+ result:
15
+ - initial line
16
+ - first log entry
17
+ - second log entry
18
+ - first log entry
@@ -0,0 +1 @@
1
+ third log entry
@@ -0,0 +1,32 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+
4
+ require 'regtest'
5
+ require 'fileutils'
6
+
7
+
8
+ $log_filename = __FILE__.sub(/\.rb$/, '.log')
9
+
10
+ # set the initial content of the log file
11
+ File.open($log_filename, 'w') do |f|
12
+ f.puts 'initial line'
13
+ end
14
+
15
+ def lines_of_log_file
16
+ File.readlines($log_filename).map(&:chomp) # keyword chomp is not supported by Ruby versions < 2.4
17
+ end
18
+
19
+ Regtest.sample 'first log entry rewrites log file' do
20
+ Regtest.log 'first log entry'
21
+ lines_of_log_file
22
+ end
23
+
24
+ Regtest.sample 'second log entry rewrites log file' do
25
+ Regtest.log 'second log entry', mode: 'w'
26
+ lines_of_log_file
27
+ end
28
+
29
+ Regtest.sample 'third log entry rewrites log file' do
30
+ Regtest.log 'third log entry', mode: 'w'
31
+ lines_of_log_file
32
+ end
@@ -0,0 +1,12 @@
1
+ ---
2
+ sample: first log entry rewrites log file
3
+ result:
4
+ - first log entry
5
+ ---
6
+ sample: second log entry rewrites log file
7
+ result:
8
+ - second log entry
9
+ ---
10
+ sample: third log entry rewrites log file
11
+ result:
12
+ - third log entry
data/regtest/metatest.rb CHANGED
@@ -6,8 +6,10 @@ require 'open3'
6
6
  require 'regtest'
7
7
  require 'tmpdir'
8
8
 
9
+ $my_dir = File.expand_path(__dir__)
10
+
9
11
  Dir.mktmpdir('regtest') do |tmpdir|
10
- Dir.chdir __dir__ do
12
+ Dir.chdir $my_dir do
11
13
  Dir['*.rb'].each do |filename|
12
14
  # Beware of endless recursion.
13
15
  next if filename =~ /metatest/
@@ -15,12 +17,13 @@ Dir.mktmpdir('regtest') do |tmpdir|
15
17
  end
16
18
  end
17
19
  Dir.chdir tmpdir do
18
- lib_dir = File.join(__dir__, '../lib')
20
+ lib_dir = File.join($my_dir, '../lib')
19
21
  o, e, ps = Open3.capture3(*[{'NOREGTESTRC' => 'true'}, 'ruby', '-I', lib_dir], *Dir['*.rb'].sort)
20
22
  Regtest.sample 'metatest' do
21
23
  res = {'stdout' => o, 'stderr' => e}
22
24
  # Levelling out runtime specific differences.
23
25
  res['stdout'].gsub!(/\d+\.\d+/, 'x.xx')
26
+ res['stdout'].gsub!(%r(\d+ samples/s), 'x samples/s')
24
27
  res['exitstatus'] = ps.exitstatus
25
28
  res
26
29
  end
data/regtest/metatest.yml CHANGED
@@ -4,12 +4,20 @@ result:
4
4
  stdout: |
5
5
  combinations.yml
6
6
  ......
7
- example.yml
8
- ..
7
+ examples.yml
8
+ ...
9
9
  filename with spaces.yml
10
10
  .
11
+ log.yml
12
+ ..
13
+ log_append.yml
14
+ ...
15
+ log_rewrite.yml
16
+ ...
17
+ toplevel.yml
18
+ .....
11
19
 
12
- 9 samples executed in x.xx s (x.xx samples/s)
20
+ 23 samples executed in x.xx s (x samples/s)
13
21
 
14
22
  Please check result files manually. Regtest isn't able to do that.
15
23
  stderr: ''
@@ -3,21 +3,25 @@
3
3
 
4
4
  # If git isn't available skip this file
5
5
  begin
6
+ require 'open3'
6
7
  Open3.capture2e('git --version')
7
8
 
8
9
  require 'fileutils'
9
- require 'open3'
10
+ require 'regtest'
10
11
  require 'regtest/git'
11
12
  require 'tmpdir'
12
13
 
14
+ $my_dir = File.expand_path(__dir__)
15
+
13
16
  def create_sample name
14
- lib_dir = File.join(__dir__, '../lib')
17
+ lib_dir = File.join($my_dir, '../lib')
15
18
  o, e, ps = Open3.capture3(*[{'NOREGTESTRC' => 'true'}, 'ruby', '-I', lib_dir, '-r', 'regtest/git'], *Dir['*.rb'].sort)
16
19
  Regtest.sample name do
17
20
  res = {'stdout' => o, 'stderr' => e}
18
21
  # Levelling out runtime specific differences.
19
22
  res['stdout'].gsub!(/\d+\.\d+/, 'x.xx')
20
23
  res['stdout'].gsub!(%r(\d+ samples/s), 'x samples/s')
24
+ res['stdout'].gsub!(/^\?\? filename with spaces.yml$/m, '?? "filename with spaces.yml"')
21
25
  res['exitstatus'] = ps.exitstatus
22
26
  res
23
27
  end
@@ -35,7 +39,7 @@ begin
35
39
  END
36
40
 
37
41
  Dir.mktmpdir('regtest') do |tmpdir|
38
- Dir.chdir __dir__ do
42
+ Dir.chdir $my_dir do
39
43
  Dir['*.rb'].each do |filename|
40
44
  # Beware of endless recursion.
41
45
  next if filename =~ /metatest/
@@ -45,11 +49,11 @@ begin
45
49
  Dir.chdir tmpdir do
46
50
  execute 'git init'
47
51
  create_sample 'all new'
48
- execute 'git add *.rb example.yml combinations.yml'
52
+ execute 'git add *.rb examples.yml combinations.yml'
49
53
  create_sample 'only one new'
50
- example_rb = File.read('example.rb')
54
+ example_rb = File.read('examples.rb')
51
55
  example_rb << NEW_SAMPLE
52
- File.write('example.rb', example_rb)
56
+ File.write('examples.rb', example_rb)
53
57
  create_sample 'one new one modified to index'
54
58
  execute 'git commit -m "commit"'
55
59
  create_sample 'one new one modified'
@@ -4,17 +4,29 @@ result:
4
4
  stdout: |
5
5
  combinations.yml
6
6
  ......
7
- example.yml
8
- ..
7
+ examples.yml
8
+ ...
9
9
  filename with spaces.yml
10
10
  .
11
+ log.yml
12
+ ..
13
+ log_append.yml
14
+ ...
15
+ log_rewrite.yml
16
+ ...
17
+ toplevel.yml
18
+ .....
11
19
 
12
- 9 samples executed in x.xx s (x.xx samples/s)
20
+ 23 samples executed in x.xx s (x samples/s)
13
21
 
14
22
  There is at least one new sample result file.
15
23
  ?? combinations.yml
16
- ?? example.yml
17
- ?? filename with spaces.yml
24
+ ?? examples.yml
25
+ ?? "filename with spaces.yml"
26
+ ?? log.yml
27
+ ?? log_append.yml
28
+ ?? log_rewrite.yml
29
+ ?? toplevel.yml
18
30
  stderr: ''
19
31
  exitstatus: 1
20
32
  ---
@@ -23,17 +35,29 @@ result:
23
35
  stdout: |
24
36
  combinations.yml
25
37
  ......
26
- example.yml
27
- ..
38
+ examples.yml
39
+ ...
28
40
  filename with spaces.yml
29
41
  .
42
+ log.yml
43
+ ..
44
+ log_append.yml
45
+ ...
46
+ log_rewrite.yml
47
+ ...
48
+ toplevel.yml
49
+ .....
30
50
 
31
- 9 samples executed in x.xx s (x.xx samples/s)
51
+ 23 samples executed in x.xx s (x samples/s)
32
52
 
33
53
  There is at least one new sample result file.
34
54
  A combinations.yml
35
- A example.yml
36
- ?? filename with spaces.yml
55
+ A examples.yml
56
+ ?? "filename with spaces.yml"
57
+ ?? log.yml
58
+ ?? log_append.yml
59
+ ?? log_rewrite.yml
60
+ ?? toplevel.yml
37
61
  stderr: ''
38
62
  exitstatus: 1
39
63
  ---
@@ -42,17 +66,29 @@ result:
42
66
  stdout: |
43
67
  combinations.yml
44
68
  ......
45
- example.yml
46
- ...
69
+ examples.yml
70
+ ....
47
71
  filename with spaces.yml
48
72
  .
73
+ log.yml
74
+ ..
75
+ log_append.yml
76
+ ...
77
+ log_rewrite.yml
78
+ ...
79
+ toplevel.yml
80
+ .....
49
81
 
50
- 10 samples executed in x.xx s (x.xx samples/s)
82
+ 24 samples executed in x.xx s (x samples/s)
51
83
 
52
84
  There are changes in your sample results!
53
85
  A combinations.yml
54
- AM example.yml
55
- ?? filename with spaces.yml
86
+ AM examples.yml
87
+ ?? "filename with spaces.yml"
88
+ ?? log.yml
89
+ ?? log_append.yml
90
+ ?? log_rewrite.yml
91
+ ?? toplevel.yml
56
92
  stderr: ''
57
93
  exitstatus: 2
58
94
  ---
@@ -61,16 +97,28 @@ result:
61
97
  stdout: |
62
98
  combinations.yml
63
99
  ......
64
- example.yml
65
- ...
100
+ examples.yml
101
+ ....
66
102
  filename with spaces.yml
67
103
  .
104
+ log.yml
105
+ ..
106
+ log_append.yml
107
+ ...
108
+ log_rewrite.yml
109
+ ...
110
+ toplevel.yml
111
+ .....
68
112
 
69
- 10 samples executed in x.xx s (x.xx samples/s)
113
+ 24 samples executed in x.xx s (x samples/s)
70
114
 
71
115
  There are changes in your sample results!
72
- M example.yml
73
- ?? filename with spaces.yml
116
+ M examples.yml
117
+ ?? "filename with spaces.yml"
118
+ ?? log.yml
119
+ ?? log_append.yml
120
+ ?? log_rewrite.yml
121
+ ?? toplevel.yml
74
122
  stderr: ''
75
123
  exitstatus: 2
76
124
  ---
@@ -79,16 +127,28 @@ result:
79
127
  stdout: |
80
128
  combinations.yml
81
129
  ......
82
- example.yml
83
- ...
130
+ examples.yml
131
+ ....
84
132
  filename with spaces.yml
85
133
  .
134
+ log.yml
135
+ ..
136
+ log_append.yml
137
+ ...
138
+ log_rewrite.yml
139
+ ...
140
+ toplevel.yml
141
+ .....
86
142
 
87
- 10 samples executed in x.xx s (x.xx samples/s)
143
+ 24 samples executed in x.xx s (x samples/s)
88
144
 
89
145
  Looks good. :)
90
- M example.yml
146
+ M examples.yml
91
147
  A "filename with spaces.yml"
148
+ A log.yml
149
+ A log_append.yml
150
+ A log_rewrite.yml
151
+ A toplevel.yml
92
152
  stderr: ''
93
153
  exitstatus: 0
94
154
  ---
@@ -97,12 +157,20 @@ result:
97
157
  stdout: |
98
158
  combinations.yml
99
159
  ......
100
- example.yml
101
- ...
160
+ examples.yml
161
+ ....
102
162
  filename with spaces.yml
103
163
  .
164
+ log.yml
165
+ ..
166
+ log_append.yml
167
+ ...
168
+ log_rewrite.yml
169
+ ...
170
+ toplevel.yml
171
+ .....
104
172
 
105
- 10 samples executed in x.xx s (x.xx samples/s)
173
+ 24 samples executed in x.xx s (x samples/s)
106
174
 
107
175
  Looks good. :)
108
176
  stderr: ''