regtest 2.2.1 → 2.4.0

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
  SHA256:
3
- metadata.gz: b91c5f1f5b30d309f77eaf7c3c218529bd82321a7af578b37c52a4bed09d53e4
4
- data.tar.gz: f66632f3eb0f2844ab43068f83c30e62aca2805dad460543436b9df0620c3598
3
+ metadata.gz: 7f62e6caefc8016f1155eb0ec2017653016d048b99c5df037e420f0e118263c0
4
+ data.tar.gz: 4829db0454d5897a91c0cfda0b8f47920973b3c3dd10221502262de6e480a7be
5
5
  SHA512:
6
- metadata.gz: 38257004b8aab5bbad388e430b85362e80b5759be4ca1729756ce0e2704a6cc85f12e3899c17b28df32afc1380251228321f750fb7f8bc4bd951a56e1ca27690
7
- data.tar.gz: 2a2f5f808848caccb56db4a4d90a9e34babf70a79d30bf49182317c77081985bcae89289c77acab5ba4a029483330ba3533a37d91be6fbdfc7b63b3cfd397948
6
+ metadata.gz: 404b61dad357ce2f41e922de4287afba65945652ad1b3dc6ca1feb58cadee1048f1fe27a4d2aed530770a573322ace55c57bd8f4e2eb394196702d4d4dd4e23e
7
+ data.tar.gz: fb0a2d617bc3744305126ccbc9d161119511f5dc76e4d73ccd9abba744e2bb240bbe55826bbdb93332243d3b4fbc5b815e7bf59cdf80dfecc692ca2c9112b5d5
data/.aspell.pws CHANGED
@@ -1,17 +1,26 @@
1
- personal_ws-1.1 en 26
1
+ personal_ws-1.1 en 37
2
2
  Bugfix
3
3
  ENV
4
4
  Friedrich
5
5
  Gemfile
6
+ Matz
6
7
  NOREGTESTRC
8
+ OpenStruct
7
9
  README
10
+ Rakefile
8
11
  Regtest
9
12
  SCM
13
+ STDERR
10
14
  SemVer
11
15
  SemVerTag
12
16
  YAML
17
+ arg
18
+ ary
19
+ backtrace
20
+ backtraces
13
21
  basename
14
22
  bitbucket
23
+ catched
15
24
  dir
16
25
  exiftool
17
26
  gettime
@@ -19,20 +28,11 @@ github
19
28
  md
20
29
  metatest
21
30
  metatests
31
+ ostruct
22
32
  rb
23
33
  rc
24
34
  regtest
25
35
  regtestrc
26
36
  scripref
27
- yml
28
- arg
29
- Matz
30
- ary
31
- Matz
32
- OpenStruct
33
- Rakefile
34
- arg
35
- ary
36
- catched
37
- ostruct
38
37
  yaml
38
+ yml
data/Changelog CHANGED
@@ -1,3 +1,14 @@
1
+ 2.4.0
2
+ Add parameter Regtest::Git.C.
3
+
4
+ 2.3.0
5
+ Remove regtest/colorize use regtest/colors instead.
6
+ Add Regtest::Git.work_tree and Regtest::Git.git_dir to be more flexible when
7
+ using different git repositories.
8
+ Add flag Regtest.show_exceptions for easier analysing problems when unexpected
9
+ exceptions occur.
10
+ Optimize some internals.
11
+
1
12
  2.2.1
2
13
  Adapt git output to work with different git versions.
3
14
  Simplify determination of filenames for outputs.
data/LICENSE CHANGED
@@ -1,3 +1,3 @@
1
- Copyright 2014, 2015, 2017-2019 by Jan Friedrich <janfri26@gmail.com>
1
+ Copyright 2014, 2015, 2017-2019, 2021, 2024 by Jan Friedrich <janfri26@gmail.com>
2
2
 
3
3
  Regtest is licensed under the same terms as Ruby itself.
data/README.md CHANGED
@@ -54,7 +54,7 @@ require 'regtest'
54
54
 
55
55
  Regtest.sample 'String result' do
56
56
  # Doing something to get the result of the sample
57
- # end make sure it is the result of the block
57
+ # and ensure it is the result of the block
58
58
  'some text'
59
59
  end
60
60
 
@@ -151,7 +151,7 @@ corresponding results files should be taken under version control.
151
151
  The key idea behind regtest is to produce values that are invariant and check
152
152
  if this assumption is true at another (mostly later) state of code. But often
153
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
154
+ run of regtest. This could be for example an id of a created record or the
155
155
  version of a used external service or some time-relevant values. Sometimes it
156
156
  is useful, to know the actual value of one of these.
157
157
 
@@ -219,6 +219,22 @@ Because the log files contains only temporary stuff they should normally not
219
219
  checked in the SCM.
220
220
 
221
221
 
222
+ ## Exceptions an backtraces
223
+
224
+ If there is an exception raised inside a regtest sample its message is a part
225
+ of the result of the sample. This is intentional because exceptions are
226
+ possible results you want to check.
227
+
228
+ But sometimes an exception occur inside of a sample that was not the intention
229
+ of the sample code. In such situation it would be helpful to have the full
230
+ exception message with the backtrace, to find the code location where the error
231
+ occurred.
232
+
233
+ You can do this with setting `Regtest.show_exceptions = true` (normally in a
234
+ local `.regtestrc` file, see below) temporarily. Then the exception and
235
+ backtrace is written to STDERR.
236
+
237
+
222
238
  ## Configuration and Plugins
223
239
 
224
240
  You can adapt the behaviour of regtest with plugins. To configure this and
@@ -255,11 +271,29 @@ Regtest.exit_codes[:unknown_result] = 0
255
271
  Regtest.exit_codes[:fail] = 0
256
272
  ```
257
273
 
258
- This also should be don in a `.regtest` file and not in the sample files.
274
+ This also should be done in a `.regtest` file and not in the sample files.
259
275
 
260
276
  Because in a `.regtestrc` file are individual configuration aspects of your
261
277
  workflow and environment it should not be checked into your SCM.
262
278
 
279
+
280
+ ## Plugin regtest/git
281
+
282
+ If you use the git plugin (`require 'regtest/git'`) there will be two options
283
+ you can set:
284
+
285
+ * `Regtest::Git.C`
286
+ * `Regtest::Git.git_dir`
287
+ * `Regtest::Git.work_tree`
288
+
289
+ which corresponds to the git parameters `-C`, `--git-dir` and `--work-tree`.
290
+ Which could be helpful if you run `regtest` from inside some other git
291
+ repository than your regtest files. Have a look at the git documentation for
292
+ more details.
293
+
294
+ As said above: this should also be done in a local `.regtestrc` file.
295
+
296
+
263
297
  ## Rake task
264
298
 
265
299
  Regtest includes a Rake task `regtest`. Per default it runs any `.rb` files
data/Rakefile CHANGED
@@ -4,7 +4,6 @@
4
4
  $:.unshift 'lib'
5
5
 
6
6
  require 'rim/tire'
7
- require 'rim/regtest'
8
7
  require 'rim/version'
9
8
 
10
9
  require 'regtest/task'
@@ -42,5 +41,13 @@ if RUBY_ENGINE == 'jruby'
42
41
  REGTEST_FILES_RB.reject! {|fn| fn =~ /metatest/}
43
42
  end
44
43
 
44
+ task :before_regtest do
45
+ verbose false do
46
+ rm_rf 'regtest/*.log'
47
+ rm_rf 'regtest/*.yml'
48
+ end
49
+ end
50
+
51
+ task :regtest => :before_regtest
45
52
  task :test => :regtest
46
53
  task :default => :test
data/lib/regtest/git.rb CHANGED
@@ -3,54 +3,82 @@
3
3
 
4
4
  require 'open3'
5
5
 
6
- # Check if git is available and current directory is part of a git repository.
6
+ # Check if git is available
7
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
8
+ Open3.capture2e('git --version')
9
+ module Regtest
10
+
11
+ # Regtest plugin for git (results are checked automatically when running
12
+ # regtest)
13
+ module Git
43
14
 
15
+ # Redefine Regtest.check_results.
16
+ def check_results
17
+ output_files = Regtest.results.keys
18
+ if output_files.empty?
19
+ report "\nNothing to do.", type: :success
20
+ return :success
21
+ end
22
+ git_status = ['git', git_global_args, %w(status -s --)].flatten
23
+ git_results, stderr, _ = Open3.capture3(*git_status, *output_files)
24
+ unless stderr.empty?
25
+ report "\ngit command coud not be executed!", type: :fail
26
+ return :fail
27
+ end
28
+ case git_results
29
+ when /^.M/ # at least one modified file
30
+ report "\nThere are changes in your sample results!", type: :fail
31
+ system *git_status, *output_files
32
+ return :fail
33
+ when /^.\?/ # at least one unknown file
34
+ report "\nThere is at least one new sample result file.", type: :unknown_result
35
+ system *git_status, *output_files
36
+ return :unknown_result
37
+ when '', /^. / # no changes in (maybe staged) files
38
+ report "\nLooks good. :)", type: :success
39
+ system *git_status, *output_files
40
+ return :success
41
+ else
42
+ report "\nYour sample results are in a bad condition!", type: :fail
43
+ system *git_status, *output_files
44
+ return :fail
45
+ end
44
46
  end
45
47
 
46
48
  class << self
47
- prepend Git
49
+ # git parameter +-C+
50
+ attr_accessor :C
51
+
52
+ # git parameter +--work-tree+
53
+ attr_accessor :work_tree
54
+
55
+ # git parameter +--git-dir+
56
+ attr_accessor :git_dir
57
+ end
58
+
59
+ private
60
+
61
+ def git_global_args
62
+ args = []
63
+ if c = Regtest::Git.C
64
+ args << '-C'
65
+ args << c
66
+ end
67
+ if wt = Regtest::Git.work_tree
68
+ args << format('--work-tree=%s', wt)
69
+ end
70
+ if gd = Regtest::Git.git_dir
71
+ args << format('--git-dir=%s', gd)
72
+ end
73
+ args
48
74
  end
49
75
 
50
76
  end
51
- else
52
- warn 'current directory is not part of a git repository:'
53
- warn 'plugin regtest/git disabled'
77
+
78
+ class << self
79
+ prepend Git
80
+ end
81
+
54
82
  end
55
83
  rescue Errno::ENOENT
56
84
  warn 'git command not found: plugin regtest/git disabled'
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Regtest
5
- VERSION = '2.2.1'
5
+ VERSION = '2.4.0'
6
6
  end
data/lib/regtest.rb CHANGED
@@ -3,7 +3,8 @@
3
3
  #
4
4
  # Regtest - Simple Regression Testing With Ruby
5
5
  #
6
- # Copyright 2014, 2015, 2017-2019 by Jan Friedrich <janfri26@gmail.com>
6
+ # Copyright 2014, 2015, 2017-2019, 2021, 2024 by Jan Friedrich
7
+ # <janfri26@gmail.com>
7
8
  # License: Regtest is licensed under the same terms as Ruby itself.
8
9
  #
9
10
 
@@ -21,6 +22,7 @@ module Regtest
21
22
  @log_filenames = Set.new
22
23
  @exit_codes = Hash.new(1)
23
24
  @exit_codes.merge!({success: 0, unknown_result: 1, fail: 2})
25
+ @show_exceptions = false
24
26
 
25
27
  # Define a sample
26
28
  def sample name
@@ -31,6 +33,9 @@ module Regtest
31
33
  h['result'] = yield
32
34
  rescue Exception => e
33
35
  h['exception'] = e.message
36
+ if show_exceptions
37
+ $stderr.puts nil, e.full_message
38
+ end
34
39
  end
35
40
  output_filename = Regtest.determine_filename_from_caller('.yml')
36
41
  unless Regtest.results[output_filename]
@@ -96,6 +101,9 @@ module Regtest
96
101
 
97
102
  attr_reader :exit_codes, :log_filenames, :results, :start
98
103
 
104
+ # Flag to show exceptions on STDERR
105
+ attr_accessor :show_exceptions
106
+
99
107
  # Determine a filename which is derived from the filename of the "real"
100
108
  # caller of the calling method
101
109
  # @param ext new extension (i.e. '.yml')
data/regtest.gemspec CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- # stub: regtest 2.2.1 ruby lib
2
+ # stub: regtest 2.4.0 ruby lib
3
3
  #
4
4
  # This file is automatically generated by rim.
5
5
  # PLEASE DO NOT EDIT IT DIRECTLY!
@@ -7,32 +7,23 @@
7
7
 
8
8
  Gem::Specification.new do |s|
9
9
  s.name = "regtest"
10
- s.version = "2.2.1"
10
+ s.version = "2.4.0"
11
11
 
12
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 = "2021-02-24"
15
+ s.date = "2024-09-13"
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/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"]
18
+ s.files = ["./.aspell.pws", "Changelog", "Gemfile", "LICENSE", "README.md", "Rakefile", "lib/regtest", "lib/regtest.rb", "lib/regtest/colors.rb", "lib/regtest/git.rb", "lib/regtest/task.rb", "lib/regtest/version.rb", "regtest.gemspec"]
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 = "3.2.3"
22
+ s.rubygems_version = "3.6.0.dev"
23
23
  s.summary = "Simple regression testing with Ruby."
24
24
 
25
- if s.respond_to? :specification_version then
26
- s.specification_version = 4
27
- end
25
+ s.specification_version = 4
28
26
 
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"])
33
- else
34
- s.add_dependency(%q<rake>, [">= 0"])
35
- s.add_dependency(%q<rim>, ["~> 2.17"])
36
- s.add_dependency(%q<regtest>, ["~> 2"])
37
- end
27
+ s.add_development_dependency(%q<rake>, [">= 0"])
28
+ s.add_development_dependency(%q<rim>, ["~> 2.17"])
38
29
  end
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regtest
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.1
4
+ version: 2.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Friedrich
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2021-02-24 00:00:00.000000000 Z
10
+ date: 2024-09-13 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: rake
@@ -38,20 +37,6 @@ dependencies:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
39
  version: '2.17'
41
- - !ruby/object:Gem::Dependency
42
- name: regtest
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '2'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '2'
55
40
  description: |
56
41
  This library supports a very simple way to do regression testing with Ruby. It
57
42
  is not limited to Ruby projects you can use it also in other contexts where you
@@ -78,40 +63,15 @@ files:
78
63
  - README.md
79
64
  - Rakefile
80
65
  - lib/regtest.rb
81
- - lib/regtest/colorize.rb
82
66
  - lib/regtest/colors.rb
83
67
  - lib/regtest/git.rb
84
68
  - lib/regtest/task.rb
85
69
  - lib/regtest/version.rb
86
70
  - regtest.gemspec
87
- - regtest/combinations.rb
88
- - regtest/combinations.yml
89
- - regtest/examples.rb
90
- - regtest/examples.yml
91
- - regtest/filename with spaces.rb
92
- - regtest/filename with spaces.yml
93
- - regtest/log.log
94
- - regtest/log.rb
95
- - regtest/log.yml
96
- - regtest/log_append.log
97
- - regtest/log_append.rb
98
- - regtest/log_append.yml
99
- - regtest/log_rewrite.log
100
- - regtest/log_rewrite.rb
101
- - regtest/log_rewrite.yml
102
- - regtest/metatest.rb
103
- - regtest/metatest.yml
104
- - regtest/metatest_git.rb
105
- - regtest/metatest_git.yml
106
- - regtest/no_samples.rb
107
- - regtest/toplevel.log
108
- - regtest/toplevel.rb
109
- - regtest/toplevel.yml
110
71
  homepage: https://github.com/janfri/regtest
111
72
  licenses:
112
73
  - Ruby
113
74
  metadata: {}
114
- post_install_message:
115
75
  rdoc_options: []
116
76
  require_paths:
117
77
  - lib
@@ -126,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
86
  - !ruby/object:Gem::Version
127
87
  version: '0'
128
88
  requirements: []
129
- rubygems_version: 3.2.3
130
- signing_key:
89
+ rubygems_version: 3.6.0.dev
131
90
  specification_version: 4
132
91
  summary: Simple regression testing with Ruby.
133
92
  test_files: []
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'regtest/colors'
5
-
6
- Regtest::Colorize = Regtest::Colors
7
-
8
- warn 'regtest/colorize is deprecated. use regtest/colors instead.'
@@ -1,15 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'ostruct'
5
- require 'regtest'
6
-
7
- o = OpenStruct.new
8
- o.a = [1, 2, 3]
9
- o.b = [:x, :y]
10
-
11
- Regtest.combinations(o).each_with_index do |c, i|
12
- Regtest.sample "Combination #{i}" do
13
- c.to_h
14
- end
15
- end
@@ -1,30 +0,0 @@
1
- ---
2
- sample: Combination 0
3
- result:
4
- :a: 1
5
- :b: :x
6
- ---
7
- sample: Combination 1
8
- result:
9
- :a: 1
10
- :b: :y
11
- ---
12
- sample: Combination 2
13
- result:
14
- :a: 2
15
- :b: :x
16
- ---
17
- sample: Combination 3
18
- result:
19
- :a: 2
20
- :b: :y
21
- ---
22
- sample: Combination 4
23
- result:
24
- :a: 3
25
- :b: :x
26
- ---
27
- sample: Combination 5
28
- result:
29
- :a: 3
30
- :b: :y
data/regtest/examples.rb DELETED
@@ -1,20 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'regtest'
5
-
6
- Regtest.sample 'String result' do
7
- # Doing something to get the result of the sample
8
- # and make sure it is the result of the block.
9
- 'some text'
10
- end
11
-
12
- Regtest.sample 'Division by zero' do
13
- # If an exception occurs while execution of the
14
- # block it is catched and its message is used as
15
- # exception value for the sample.
16
- 2 / 0
17
- end
18
-
19
- # If no block is given => exception no block given (yield)
20
- Regtest.sample 'no block'
data/regtest/examples.yml DELETED
@@ -1,9 +0,0 @@
1
- ---
2
- sample: String result
3
- result: some text
4
- ---
5
- sample: Division by zero
6
- exception: divided by 0
7
- ---
8
- sample: no block
9
- exception: no block given (yield)
@@ -1,8 +0,0 @@
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
@@ -1,4 +0,0 @@
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. :)
data/regtest/log.log DELETED
@@ -1,3 +0,0 @@
1
- 2085.99375
2
- 2085.994022
3
- Logging from outside of a sample works.
data/regtest/log.rb DELETED
@@ -1,18 +0,0 @@
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 DELETED
@@ -1,6 +0,0 @@
1
- ---
2
- sample: test
3
- result: true
4
- ---
5
- sample: invalid mode
6
- exception: Mode x is not allowed.
@@ -1,4 +0,0 @@
1
- initial line
2
- first log entry
3
- second log entry
4
- first log entry
@@ -1,32 +0,0 @@
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
@@ -1,18 +0,0 @@
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
@@ -1 +0,0 @@
1
- third log entry
@@ -1,32 +0,0 @@
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
@@ -1,12 +0,0 @@
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 DELETED
@@ -1,31 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'fileutils'
5
- require 'open3'
6
- require 'regtest'
7
- require 'tmpdir'
8
-
9
- $my_dir = File.expand_path(__dir__)
10
-
11
- Dir.mktmpdir('regtest') do |tmpdir|
12
- Dir.chdir $my_dir do
13
- Dir['*.rb'].each do |filename|
14
- # Beware of endless recursion.
15
- next if filename =~ /metatest/
16
- FileUtils.cp filename, tmpdir
17
- end
18
- end
19
- Dir.chdir tmpdir do
20
- lib_dir = File.join($my_dir, '../lib')
21
- o, e, ps = Open3.capture3(*[{'NOREGTESTRC' => 'true'}, 'ruby', '-I', lib_dir], *Dir['*.rb'].sort)
22
- Regtest.sample 'metatest' do
23
- res = {'stdout' => o, 'stderr' => e}
24
- # Levelling out runtime specific differences.
25
- res['stdout'].gsub!(/\d+\.\d+/, 'x.xx')
26
- res['stdout'].gsub!(%r(\d+ samples/s), 'x samples/s')
27
- res['exitstatus'] = ps.exitstatus
28
- res
29
- end
30
- end
31
- end
data/regtest/metatest.yml DELETED
@@ -1,24 +0,0 @@
1
- ---
2
- sample: metatest
3
- result:
4
- stdout: |
5
- combinations.yml
6
- ......
7
- examples.yml
8
- ...
9
- filename with spaces.yml
10
- .
11
- log.yml
12
- ..
13
- log_append.yml
14
- ...
15
- log_rewrite.yml
16
- ...
17
- toplevel.yml
18
- .....
19
-
20
- 23 samples executed in x.xx s (x samples/s)
21
-
22
- Please check result files manually. Regtest isn't able to do that.
23
- stderr: ''
24
- exitstatus: 1
@@ -1,67 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- # If git isn't available skip this file
5
- begin
6
- require 'open3'
7
- Open3.capture2e('git --version')
8
-
9
- require 'fileutils'
10
- require 'regtest'
11
- require 'regtest/git'
12
- require 'tmpdir'
13
-
14
- $my_dir = File.expand_path(__dir__)
15
-
16
- def create_sample name
17
- lib_dir = File.join($my_dir, '../lib')
18
- o, e, ps = Open3.capture3(*[{'NOREGTESTRC' => 'true'}, 'ruby', '-I', lib_dir, '-r', 'regtest/git'], *Dir['*.rb'].sort)
19
- Regtest.sample name do
20
- res = {'stdout' => o, 'stderr' => e}
21
- # Levelling out runtime specific differences.
22
- res['stdout'].gsub!(/\d+\.\d+/, 'x.xx')
23
- res['stdout'].gsub!(%r(\d+ samples/s), 'x samples/s')
24
- res['stdout'].gsub!(/^\?\? filename with spaces.yml$/m, '?? "filename with spaces.yml"')
25
- res['exitstatus'] = ps.exitstatus
26
- res
27
- end
28
- end
29
-
30
- def execute cmd
31
- Open3.capture2e cmd
32
- end
33
-
34
- NEW_SAMPLE = <<-END
35
-
36
- Regtest.sample 'new sample' do
37
- 'new sample'
38
- end
39
- END
40
-
41
- Dir.mktmpdir('regtest') do |tmpdir|
42
- Dir.chdir $my_dir do
43
- Dir['*.rb'].each do |filename|
44
- # Beware of endless recursion.
45
- next if filename =~ /metatest/
46
- FileUtils.cp filename, tmpdir
47
- end
48
- end
49
- Dir.chdir tmpdir do
50
- execute 'git init'
51
- create_sample 'all new'
52
- execute 'git add *.rb examples.yml combinations.yml'
53
- create_sample 'only one new'
54
- example_rb = File.read('examples.rb')
55
- example_rb << NEW_SAMPLE
56
- File.write('examples.rb', example_rb)
57
- create_sample 'one new one modified to index'
58
- execute 'git commit -m "commit"'
59
- create_sample 'one new one modified'
60
- execute 'git add *.yml'
61
- create_sample 'all in index'
62
- execute 'git commit -m "commit"'
63
- create_sample 'all commited'
64
- end
65
- end
66
- rescue Errno::ENOENT
67
- end
@@ -1,177 +0,0 @@
1
- ---
2
- sample: all new
3
- result:
4
- stdout: |
5
- combinations.yml
6
- ......
7
- examples.yml
8
- ...
9
- filename with spaces.yml
10
- .
11
- log.yml
12
- ..
13
- log_append.yml
14
- ...
15
- log_rewrite.yml
16
- ...
17
- toplevel.yml
18
- .....
19
-
20
- 23 samples executed in x.xx s (x samples/s)
21
-
22
- There is at least one new sample result file.
23
- ?? combinations.yml
24
- ?? examples.yml
25
- ?? "filename with spaces.yml"
26
- ?? log.yml
27
- ?? log_append.yml
28
- ?? log_rewrite.yml
29
- ?? toplevel.yml
30
- stderr: ''
31
- exitstatus: 1
32
- ---
33
- sample: only one new
34
- result:
35
- stdout: |
36
- combinations.yml
37
- ......
38
- examples.yml
39
- ...
40
- filename with spaces.yml
41
- .
42
- log.yml
43
- ..
44
- log_append.yml
45
- ...
46
- log_rewrite.yml
47
- ...
48
- toplevel.yml
49
- .....
50
-
51
- 23 samples executed in x.xx s (x samples/s)
52
-
53
- There is at least one new sample result file.
54
- A combinations.yml
55
- A examples.yml
56
- ?? "filename with spaces.yml"
57
- ?? log.yml
58
- ?? log_append.yml
59
- ?? log_rewrite.yml
60
- ?? toplevel.yml
61
- stderr: ''
62
- exitstatus: 1
63
- ---
64
- sample: one new one modified to index
65
- result:
66
- stdout: |
67
- combinations.yml
68
- ......
69
- examples.yml
70
- ....
71
- filename with spaces.yml
72
- .
73
- log.yml
74
- ..
75
- log_append.yml
76
- ...
77
- log_rewrite.yml
78
- ...
79
- toplevel.yml
80
- .....
81
-
82
- 24 samples executed in x.xx s (x samples/s)
83
-
84
- There are changes in your sample results!
85
- A combinations.yml
86
- AM examples.yml
87
- ?? "filename with spaces.yml"
88
- ?? log.yml
89
- ?? log_append.yml
90
- ?? log_rewrite.yml
91
- ?? toplevel.yml
92
- stderr: ''
93
- exitstatus: 2
94
- ---
95
- sample: one new one modified
96
- result:
97
- stdout: |
98
- combinations.yml
99
- ......
100
- examples.yml
101
- ....
102
- filename with spaces.yml
103
- .
104
- log.yml
105
- ..
106
- log_append.yml
107
- ...
108
- log_rewrite.yml
109
- ...
110
- toplevel.yml
111
- .....
112
-
113
- 24 samples executed in x.xx s (x samples/s)
114
-
115
- There are changes in your sample results!
116
- M examples.yml
117
- ?? "filename with spaces.yml"
118
- ?? log.yml
119
- ?? log_append.yml
120
- ?? log_rewrite.yml
121
- ?? toplevel.yml
122
- stderr: ''
123
- exitstatus: 2
124
- ---
125
- sample: all in index
126
- result:
127
- stdout: |
128
- combinations.yml
129
- ......
130
- examples.yml
131
- ....
132
- filename with spaces.yml
133
- .
134
- log.yml
135
- ..
136
- log_append.yml
137
- ...
138
- log_rewrite.yml
139
- ...
140
- toplevel.yml
141
- .....
142
-
143
- 24 samples executed in x.xx s (x samples/s)
144
-
145
- Looks good. :)
146
- M examples.yml
147
- A "filename with spaces.yml"
148
- A log.yml
149
- A log_append.yml
150
- A log_rewrite.yml
151
- A toplevel.yml
152
- stderr: ''
153
- exitstatus: 0
154
- ---
155
- sample: all commited
156
- result:
157
- stdout: |
158
- combinations.yml
159
- ......
160
- examples.yml
161
- ....
162
- filename with spaces.yml
163
- .
164
- log.yml
165
- ..
166
- log_append.yml
167
- ...
168
- log_rewrite.yml
169
- ...
170
- toplevel.yml
171
- .....
172
-
173
- 24 samples executed in x.xx s (x samples/s)
174
-
175
- Looks good. :)
176
- stderr: ''
177
- exitstatus: 0
@@ -1,8 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'regtest'
5
-
6
- # If a Ruby file doesn't contain any sample regtest shouldn't
7
- # generate a corresponding YAML file.
8
- 2 + 2
data/regtest/toplevel.log DELETED
@@ -1 +0,0 @@
1
- 0.65204510187786
data/regtest/toplevel.rb DELETED
@@ -1,30 +0,0 @@
1
- # encoding: utf-8
2
- # frozen_string_literal: true
3
-
4
- require 'regtest'
5
-
6
- methods_before = methods
7
-
8
- extend Regtest
9
-
10
- methods_after = methods
11
-
12
- Regtest.sample "Toplevel methods defined by 'extend Regtest'" do
13
- (methods_after - methods_before).map(&:to_s).sort
14
- end
15
-
16
- Regtest.sample 'metatest' do
17
- sample 'sample works at toplevel' do
18
- true
19
- end
20
- end
21
-
22
- Regtest.sample 'combinations work at toplevel' do
23
- combinations(x: %w(a b), y: [1,2]).map(&:to_h)
24
- end
25
-
26
- Regtest.sample 'log works at toplevel' do
27
- f = rand.to_s
28
- log f
29
- File.read(__FILE__.sub(/\.rb$/, '.log')).chomp == f
30
- end
data/regtest/toplevel.yml DELETED
@@ -1,28 +0,0 @@
1
- ---
2
- sample: Toplevel methods defined by 'extend Regtest'
3
- result:
4
- - combinations
5
- - log
6
- - sample
7
- ---
8
- sample: sample works at toplevel
9
- result: true
10
- ---
11
- sample: metatest
12
- result:
13
- sample: sample works at toplevel
14
- result: true
15
- ---
16
- sample: combinations work at toplevel
17
- result:
18
- - :x: a
19
- :y: 1
20
- - :x: a
21
- :y: 2
22
- - :x: b
23
- :y: 1
24
- - :x: b
25
- :y: 2
26
- ---
27
- sample: log works at toplevel
28
- result: true