test_bench_legacy 1.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/bin/bench +10 -0
- data/lib/test_bench.rb +37 -0
- data/lib/test_bench/activate.rb +3 -0
- data/lib/test_bench/assert.rb +58 -0
- data/lib/test_bench/assert/failed.rb +25 -0
- data/lib/test_bench/assert/proc.rb +24 -0
- data/lib/test_bench/assert/refute.rb +9 -0
- data/lib/test_bench/cli.rb +4 -0
- data/lib/test_bench/cli/cli.rb +108 -0
- data/lib/test_bench/controls.rb +16 -0
- data/lib/test_bench/controls/binding.rb +17 -0
- data/lib/test_bench/controls/clock/elapsed.rb +41 -0
- data/lib/test_bench/controls/clock/reference.rb +15 -0
- data/lib/test_bench/controls/dir_substitute.rb +58 -0
- data/lib/test_bench/controls/error.rb +63 -0
- data/lib/test_bench/controls/executor/substitute.rb +27 -0
- data/lib/test_bench/controls/expand_path.rb +23 -0
- data/lib/test_bench/controls/fixture.rb +36 -0
- data/lib/test_bench/controls/kernel_substitute.rb +72 -0
- data/lib/test_bench/controls/output.rb +106 -0
- data/lib/test_bench/controls/path.rb +11 -0
- data/lib/test_bench/controls/result.rb +64 -0
- data/lib/test_bench/controls/telemetry.rb +23 -0
- data/lib/test_bench/controls/test_script.rb +23 -0
- data/lib/test_bench/executor.rb +45 -0
- data/lib/test_bench/expand_path.rb +44 -0
- data/lib/test_bench/fixture.rb +17 -0
- data/lib/test_bench/output.rb +169 -0
- data/lib/test_bench/output/assertions.rb +43 -0
- data/lib/test_bench/output/palette.rb +59 -0
- data/lib/test_bench/output/writer.rb +94 -0
- data/lib/test_bench/output/writer/assertions.rb +29 -0
- data/lib/test_bench/output/writer/assertions/line.rb +76 -0
- data/lib/test_bench/registry.rb +32 -0
- data/lib/test_bench/result.rb +71 -0
- data/lib/test_bench/result/assertions.rb +11 -0
- data/lib/test_bench/result/null.rb +12 -0
- data/lib/test_bench/runner.rb +59 -0
- data/lib/test_bench/settings.rb +62 -0
- data/lib/test_bench/settings/defaults.rb +29 -0
- data/lib/test_bench/settings/environment.rb +124 -0
- data/lib/test_bench/settings/registry.rb +17 -0
- data/lib/test_bench/structure.rb +89 -0
- data/lib/test_bench/telemetry.rb +130 -0
- data/lib/test_bench/telemetry/assertions.rb +85 -0
- data/lib/test_bench/telemetry/registry.rb +17 -0
- data/lib/test_bench/telemetry/subscription.rb +23 -0
- data/lib/test_bench/test_bench.rb +33 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f8a3bbbea3b17a0bfef403315e96bc36ec72f85cc5f51f7168698626ef009976
|
4
|
+
data.tar.gz: 4bd2579635c5df18083d50861dcae2f7f186be176ec99adc4d55de2f735c0a96
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 57515c64e1cb86885ede6dbcb18ecb3d284dda0549d5e35a11e7ca91c966042ec5cf950aa01a2479f0570101ce6ae1f40756ccdf13546d530e00c307489a9ffc
|
7
|
+
data.tar.gz: 9954bc2f45222fb7526aa3d3cf59843ce7371b37995c488010a6fec0275cf4feb10eaa749778a89e798ff3b642998fbea2dd61e4f99dd0a779488e7834d4fa69
|
data/bin/bench
ADDED
data/lib/test_bench.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'English'
|
2
|
+
require 'forwardable'
|
3
|
+
require 'observer'
|
4
|
+
require 'pathname'
|
5
|
+
require 'stringio'
|
6
|
+
require 'time'
|
7
|
+
|
8
|
+
require 'test_bench/telemetry'
|
9
|
+
require 'test_bench/telemetry/assertions'
|
10
|
+
require 'test_bench/telemetry/registry'
|
11
|
+
require 'test_bench/telemetry/subscription'
|
12
|
+
|
13
|
+
require 'test_bench/assert'
|
14
|
+
require 'test_bench/assert/failed'
|
15
|
+
require 'test_bench/assert/proc'
|
16
|
+
require 'test_bench/assert/refute'
|
17
|
+
require 'test_bench/executor'
|
18
|
+
require 'test_bench/expand_path'
|
19
|
+
require 'test_bench/fixture'
|
20
|
+
require 'test_bench/output'
|
21
|
+
require 'test_bench/output/assertions'
|
22
|
+
require 'test_bench/output/palette'
|
23
|
+
require 'test_bench/output/writer'
|
24
|
+
require 'test_bench/output/writer/assertions'
|
25
|
+
require 'test_bench/output/writer/assertions/line'
|
26
|
+
require 'test_bench/registry'
|
27
|
+
require 'test_bench/result'
|
28
|
+
require 'test_bench/result/assertions'
|
29
|
+
require 'test_bench/result/null'
|
30
|
+
require 'test_bench/runner'
|
31
|
+
require 'test_bench/settings'
|
32
|
+
require 'test_bench/settings/defaults'
|
33
|
+
require 'test_bench/settings/environment'
|
34
|
+
require 'test_bench/settings/registry'
|
35
|
+
require 'test_bench/structure'
|
36
|
+
|
37
|
+
require 'test_bench/test_bench'
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Assert
|
3
|
+
attr_reader :block
|
4
|
+
attr_reader :mod
|
5
|
+
attr_reader :subject
|
6
|
+
|
7
|
+
def initialize subject, mod, block
|
8
|
+
@subject = subject
|
9
|
+
@mod = mod
|
10
|
+
@block = block
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.call subject, mod=nil, &block
|
14
|
+
block ||= identity_block
|
15
|
+
|
16
|
+
instance = new subject, mod, block
|
17
|
+
instance.call
|
18
|
+
end
|
19
|
+
|
20
|
+
def assertions_module
|
21
|
+
return mod if mod
|
22
|
+
|
23
|
+
if subject_namespace.const_defined? :Assertions
|
24
|
+
subject_namespace.const_get :Assertions
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def call
|
29
|
+
extend_subject assertions_module if assertions_module
|
30
|
+
|
31
|
+
result = subject.instance_exec subject, &block
|
32
|
+
|
33
|
+
interpret_result result
|
34
|
+
end
|
35
|
+
|
36
|
+
def extend_subject mod
|
37
|
+
raise TypeError if subject.frozen?
|
38
|
+
subject.extend mod
|
39
|
+
rescue TypeError
|
40
|
+
end
|
41
|
+
|
42
|
+
def interpret_result result
|
43
|
+
if result then true else false end
|
44
|
+
end
|
45
|
+
|
46
|
+
def subject_namespace
|
47
|
+
if subject.is_a? Module
|
48
|
+
subject
|
49
|
+
else
|
50
|
+
subject.class
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.identity_block
|
55
|
+
@identity_block ||= -> subject do subject end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Assert
|
3
|
+
class Failed < StandardError
|
4
|
+
attr_reader :backtrace_locations
|
5
|
+
|
6
|
+
def initialize backtrace_locations
|
7
|
+
@backtrace_locations = backtrace_locations
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.build backtrace_location=nil
|
11
|
+
backtrace_location ||= caller_locations[0]
|
12
|
+
|
13
|
+
new [backtrace_location]
|
14
|
+
end
|
15
|
+
|
16
|
+
def backtrace
|
17
|
+
backtrace_locations.map(&:to_s)
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"Assertion failed"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module TestBench
|
2
|
+
class Assert
|
3
|
+
module Proc
|
4
|
+
module Assertions
|
5
|
+
def raises_error? error_type=nil
|
6
|
+
rescue_error_type = error_type || StandardError
|
7
|
+
|
8
|
+
self.call
|
9
|
+
|
10
|
+
return false
|
11
|
+
|
12
|
+
rescue rescue_error_type => error
|
13
|
+
if error_type.nil? or error.instance_of? rescue_error_type
|
14
|
+
return true
|
15
|
+
end
|
16
|
+
|
17
|
+
raise error
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
::Proc.send :const_set, :Assertions, Assertions
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
module TestBench
|
2
|
+
class CLI
|
3
|
+
attr_reader :argv
|
4
|
+
attr_writer :settings
|
5
|
+
attr_writer :root_directory
|
6
|
+
|
7
|
+
def initialize argv
|
8
|
+
@argv = argv
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.call argv=nil, exclude_pattern: nil, tests_directory: nil
|
12
|
+
argv ||= ARGV
|
13
|
+
|
14
|
+
settings = Settings.toplevel
|
15
|
+
|
16
|
+
settings.exclude_pattern = exclude_pattern unless exclude_pattern.nil?
|
17
|
+
settings.tests_dir = tests_directory unless tests_directory.nil?
|
18
|
+
|
19
|
+
instance = new argv
|
20
|
+
|
21
|
+
instance.settings = settings
|
22
|
+
instance.()
|
23
|
+
end
|
24
|
+
|
25
|
+
def call
|
26
|
+
option_parser.parse! argv
|
27
|
+
|
28
|
+
paths = argv
|
29
|
+
paths << settings.tests_dir if paths.empty?
|
30
|
+
|
31
|
+
TestBench::Runner.(paths, root_directory) or exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
def help
|
35
|
+
puts option_parser.help
|
36
|
+
puts
|
37
|
+
puts <<-TEXT
|
38
|
+
If no paths are specified, #{program_name} runs all files in ./tests. The following environment variables can also control execution:
|
39
|
+
|
40
|
+
TEST_BENCH_ABORT_ON_ERROR Same as -a or --abort-on-error
|
41
|
+
TEST_BENCH_COLOR Set color on or off
|
42
|
+
TEST_BENCH_EXCLUDE_PATTERN Regular expression that matches paths to be excluded from execution
|
43
|
+
TEST_BENCH_RECORD_TELEMETRY Causes Test Bench to preserve telemetry events (needed for testing Test Bench itself)
|
44
|
+
TEST_BENCH_REVERSE_BACKTRACES Prints exceptions in reverse order
|
45
|
+
TEST_BENCH_QUIET Same as -q or --quiet
|
46
|
+
TEST_BENCH_TESTS_DIR Specifies the default directory where Test Bench searches for tests
|
47
|
+
TEST_BENCH_VERBOSE Same as -v or --verbose
|
48
|
+
|
49
|
+
TEXT
|
50
|
+
end
|
51
|
+
|
52
|
+
def option_parser
|
53
|
+
@option_parser ||= OptionParser.new do |parser|
|
54
|
+
parser.on '-a', '--abort-on-error', "Exit immediately after any test script fails" do
|
55
|
+
settings.abort_on_error = true
|
56
|
+
end
|
57
|
+
|
58
|
+
parser.on '-h', '--help', "Print this help message and exit successfully" do
|
59
|
+
help
|
60
|
+
exit 0
|
61
|
+
end
|
62
|
+
|
63
|
+
parser.on '-q', '--quiet', "Lower verbosity level" do
|
64
|
+
settings.lower_verbosity
|
65
|
+
end
|
66
|
+
|
67
|
+
parser.on '-r', '--reverse-backtraces', "Reverse error backtraces" do
|
68
|
+
settings.reverse_backtraces = true
|
69
|
+
end
|
70
|
+
|
71
|
+
parser.on '-v', '--verbose', "Raise verbosity level" do
|
72
|
+
settings.raise_verbosity
|
73
|
+
end
|
74
|
+
|
75
|
+
parser.on '-V', '--version', "Print version and exit successfully" do
|
76
|
+
puts "test-bench (#{parser.program_name}) version #{version}"
|
77
|
+
exit 0
|
78
|
+
end
|
79
|
+
|
80
|
+
parser.on '-x', '--exclude PATTERN', %{Filter out files matching PATTERN (Default is "_init$")} do |pattern|
|
81
|
+
settings.exclude_pattern = pattern
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def program_name
|
87
|
+
File.basename $PROGRAM_NAME
|
88
|
+
end
|
89
|
+
|
90
|
+
def root_directory
|
91
|
+
@root_directory ||= File.expand_path Dir.pwd
|
92
|
+
end
|
93
|
+
|
94
|
+
def settings
|
95
|
+
@settings ||= Settings.new
|
96
|
+
end
|
97
|
+
|
98
|
+
def version
|
99
|
+
spec = Gem.loaded_specs['test_bench']
|
100
|
+
|
101
|
+
if spec
|
102
|
+
spec.version
|
103
|
+
else
|
104
|
+
'(local)'.freeze
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'ostruct'
|
2
|
+
|
3
|
+
require 'test_bench/controls/binding'
|
4
|
+
require 'test_bench/controls/clock/elapsed'
|
5
|
+
require 'test_bench/controls/clock/reference'
|
6
|
+
require 'test_bench/controls/dir_substitute'
|
7
|
+
require 'test_bench/controls/executor/substitute'
|
8
|
+
require 'test_bench/controls/expand_path'
|
9
|
+
require 'test_bench/controls/error'
|
10
|
+
require 'test_bench/controls/fixture'
|
11
|
+
require 'test_bench/controls/kernel_substitute'
|
12
|
+
require 'test_bench/controls/output'
|
13
|
+
require 'test_bench/controls/path'
|
14
|
+
require 'test_bench/controls/result'
|
15
|
+
require 'test_bench/controls/telemetry'
|
16
|
+
require 'test_bench/controls/test_script'
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module Clock
|
4
|
+
class Elapsed
|
5
|
+
def self.example
|
6
|
+
new t0, t1
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.seconds
|
10
|
+
61.11111
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.t0
|
14
|
+
time = Time.new 2000, 1, 1, 1, 1, 1.11111, 0
|
15
|
+
time.round 5
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.t1
|
19
|
+
time = Time.new 2000, 1, 1, 1, 2, 2.22222, 0
|
20
|
+
time.round 5
|
21
|
+
end
|
22
|
+
|
23
|
+
attr_reader :t0
|
24
|
+
attr_reader :t1
|
25
|
+
|
26
|
+
def initialize t0, t1
|
27
|
+
@t0 = t0
|
28
|
+
@t1 = t1
|
29
|
+
end
|
30
|
+
|
31
|
+
def now
|
32
|
+
enumerator.next
|
33
|
+
end
|
34
|
+
|
35
|
+
def enumerator
|
36
|
+
@enumerator ||= [t0, t1].lazy
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
class DirSubstitute
|
4
|
+
def self.example
|
5
|
+
files = %w(
|
6
|
+
/root/some/path/1.rb
|
7
|
+
/root/some/path/2.rb
|
8
|
+
/root/other/path.rb
|
9
|
+
)
|
10
|
+
|
11
|
+
new files
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_reader :files
|
15
|
+
|
16
|
+
def initialize files
|
17
|
+
@files = files
|
18
|
+
end
|
19
|
+
|
20
|
+
def [] pattern
|
21
|
+
if match_data = %r{\A(?<base>.*)/\*\*/\*\.rb\z}.match(pattern)
|
22
|
+
# some/path/**/*.rb
|
23
|
+
files.select do |file|
|
24
|
+
file.start_with? match_data['base']
|
25
|
+
end
|
26
|
+
elsif match_data = %r{\A(?<base>.*)/\*\.rb\z}.match(pattern)
|
27
|
+
# some/path/*.rb
|
28
|
+
files.select do |file|
|
29
|
+
dirname = File.dirname file
|
30
|
+
dirname == match_data['base']
|
31
|
+
end
|
32
|
+
else
|
33
|
+
# some/path.rb
|
34
|
+
files.select do |file|
|
35
|
+
file == pattern
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def directories
|
41
|
+
files.flat_map do |file|
|
42
|
+
dirs = []
|
43
|
+
|
44
|
+
until file == '/'
|
45
|
+
file = File.dirname file
|
46
|
+
dirs << file
|
47
|
+
end
|
48
|
+
|
49
|
+
dirs
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def exist? directory
|
54
|
+
directories.include? directory.to_s
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|