test_bench_legacy 1.3.5
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,63 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
class Error < StandardError
|
4
|
+
def self.example
|
5
|
+
new backtrace_locations
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.file
|
9
|
+
Path.example
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.line
|
13
|
+
1
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.message
|
17
|
+
'Some error'
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.method_name
|
21
|
+
'some_method'
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.backtrace_locations
|
25
|
+
[
|
26
|
+
BacktraceLocation.new(file, line, method_name),
|
27
|
+
BacktraceLocation.new(file, line + 1, method_name),
|
28
|
+
BacktraceLocation.new(file, line + 2, method_name),
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
class BacktraceLocation
|
33
|
+
attr_reader :label
|
34
|
+
attr_reader :lineno
|
35
|
+
attr_reader :path
|
36
|
+
|
37
|
+
def initialize path, lineno, label
|
38
|
+
@label = label
|
39
|
+
@lineno = lineno
|
40
|
+
@path = path
|
41
|
+
end
|
42
|
+
|
43
|
+
def to_s
|
44
|
+
"#{path}:#{lineno}:in `#{label}'"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_reader :backtrace_locations
|
49
|
+
|
50
|
+
def initialize backtrace_locations
|
51
|
+
@backtrace_locations = backtrace_locations
|
52
|
+
end
|
53
|
+
|
54
|
+
def backtrace
|
55
|
+
backtrace_locations.map(&:to_s)
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_s
|
59
|
+
self.class.message
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module Executor
|
4
|
+
class Substitute
|
5
|
+
attr_writer :telemetry
|
6
|
+
|
7
|
+
def call files
|
8
|
+
files.each do |file|
|
9
|
+
executed_files << file
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def executed_files
|
14
|
+
@executed_files ||= []
|
15
|
+
end
|
16
|
+
|
17
|
+
module Assertions
|
18
|
+
def executed? *files
|
19
|
+
files.all? do |file|
|
20
|
+
executed_files.include? file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module ExpandPath
|
4
|
+
def self.example
|
5
|
+
-> path do
|
6
|
+
if path == 'some/path'
|
7
|
+
%w(some/path/1.rb some/path/2.rb)
|
8
|
+
elsif path == 'other/path.rb'
|
9
|
+
%w(other/path.rb)
|
10
|
+
else
|
11
|
+
[]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module RootDirectory
|
17
|
+
def self.example
|
18
|
+
Pathname.new '/root'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module Fixture
|
4
|
+
class Example
|
5
|
+
include TestBench::Fixture
|
6
|
+
|
7
|
+
def example_context
|
8
|
+
context "Some context" do end
|
9
|
+
end
|
10
|
+
|
11
|
+
def example_test
|
12
|
+
test "Some test" do end
|
13
|
+
end
|
14
|
+
|
15
|
+
def example_assertions
|
16
|
+
assert true
|
17
|
+
refute false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.example
|
22
|
+
Example.new
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.pair
|
26
|
+
binding = Binding.example
|
27
|
+
telemetry = TestBench::Telemetry::Registry.get binding
|
28
|
+
|
29
|
+
fixture = example
|
30
|
+
fixture.structure = binding.receiver
|
31
|
+
|
32
|
+
return fixture, telemetry
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
class KernelSubstitute
|
4
|
+
def self.example file_map=nil
|
5
|
+
file_map ||= FileMap.example
|
6
|
+
|
7
|
+
instance = new file_map
|
8
|
+
instance
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader :file_map
|
12
|
+
|
13
|
+
def initialize file_map
|
14
|
+
@file_map = file_map
|
15
|
+
end
|
16
|
+
|
17
|
+
def load path
|
18
|
+
ruby_text = file_map[path]
|
19
|
+
|
20
|
+
TOPLEVEL_BINDING.eval ruby_text, path
|
21
|
+
end
|
22
|
+
|
23
|
+
module FileMap
|
24
|
+
def self.example
|
25
|
+
{
|
26
|
+
TestScript::Error.file => TestScript::Error.text,
|
27
|
+
TestScript::Failing.file => TestScript::Failing.text,
|
28
|
+
TestScript::Passing.file => TestScript::Passing.text,
|
29
|
+
}
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
module Files
|
34
|
+
def self.example
|
35
|
+
FileMap.example.keys
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
module TestScript
|
40
|
+
module Error
|
41
|
+
def self.text
|
42
|
+
Controls::TestScript::Error.example
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.file
|
46
|
+
'/error.rb'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
module Failing
|
51
|
+
def self.text
|
52
|
+
Controls::TestScript::Failing.example
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.file
|
56
|
+
'/failing.rb'
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
module Passing
|
61
|
+
def self.text
|
62
|
+
Controls::TestScript::Passing.example
|
63
|
+
end
|
64
|
+
|
65
|
+
def self.file
|
66
|
+
'/passing.rb'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module Output
|
4
|
+
def self.attach binding, level=nil
|
5
|
+
level ||= :verbose
|
6
|
+
|
7
|
+
output = TestBench::Output.build level
|
8
|
+
|
9
|
+
subscription = TestBench::Telemetry::Subscription.new output
|
10
|
+
|
11
|
+
telemetry = TestBench::Telemetry::Registry.get binding
|
12
|
+
telemetry.add_observer subscription
|
13
|
+
|
14
|
+
output
|
15
|
+
end
|
16
|
+
|
17
|
+
module Device
|
18
|
+
def self.tty
|
19
|
+
file = non_tty
|
20
|
+
|
21
|
+
def file.tty?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
|
25
|
+
def file.isatty
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
file
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.non_tty
|
33
|
+
Tempfile.new 'non-tty-control'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
module Error
|
38
|
+
def self.example reverse: nil
|
39
|
+
reverse ||= false
|
40
|
+
|
41
|
+
error = Controls::Error.example
|
42
|
+
|
43
|
+
file = Controls::Error.file
|
44
|
+
line = Controls::Error.line
|
45
|
+
method_name = Controls::Error.method_name
|
46
|
+
message = Controls::Error.message
|
47
|
+
|
48
|
+
lines = [
|
49
|
+
%{#{file}:#{line}:in `#{method_name}': #{message} (#{error.class})\n},
|
50
|
+
%{ from #{file}:#{line + 1}:in `#{method_name}'\n},
|
51
|
+
%{ from #{file}:#{line + 2}:in `#{method_name}'\n},
|
52
|
+
]
|
53
|
+
|
54
|
+
lines.reverse! if reverse
|
55
|
+
|
56
|
+
lines.join
|
57
|
+
end
|
58
|
+
|
59
|
+
module Reversed
|
60
|
+
def self.example
|
61
|
+
Error.example reverse: true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
module Summary
|
67
|
+
def self.example result=nil
|
68
|
+
result ||= Result.example
|
69
|
+
|
70
|
+
tests_per_second = Rational result.tests, result.elapsed_time
|
71
|
+
|
72
|
+
error_label = if result.errors == 1 then 'error' else 'errors' end
|
73
|
+
|
74
|
+
"Ran %d tests in 1m1.111s (%.3fs tests/second)\n1 passed, 1 skipped, %d failed, %d total %s" %
|
75
|
+
[result.tests, tests_per_second, result.failures, result.errors, error_label]
|
76
|
+
end
|
77
|
+
|
78
|
+
module Run
|
79
|
+
def self.example result=nil
|
80
|
+
result ||= Result.example
|
81
|
+
|
82
|
+
files = if result.files.size == 1 then 'file' else 'files' end
|
83
|
+
|
84
|
+
<<~TEXT
|
85
|
+
Finished running #{result.files.size} #{files}
|
86
|
+
#{Summary.example result}
|
87
|
+
TEXT
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
module File
|
92
|
+
def self.example result=nil
|
93
|
+
path = Path.example
|
94
|
+
result ||= Result.example
|
95
|
+
|
96
|
+
<<~TEXT
|
97
|
+
Finished running #{path}
|
98
|
+
#{Summary.example result}
|
99
|
+
|
100
|
+
TEXT
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module Result
|
4
|
+
def self.example file=nil, failures: nil, errors: nil
|
5
|
+
failures ||= 1
|
6
|
+
errors ||= 1
|
7
|
+
file ||= Path.example
|
8
|
+
|
9
|
+
TestBench::Result.new(
|
10
|
+
[file], # files
|
11
|
+
1, # passes
|
12
|
+
failures, # failures
|
13
|
+
1, # skips
|
14
|
+
11, # assertions
|
15
|
+
errors, # errors
|
16
|
+
t0, # start_time
|
17
|
+
t1, # stop_time
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.t0
|
22
|
+
Clock::Elapsed.t0
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.t1
|
26
|
+
Clock::Elapsed.t1
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.elapsed_time
|
30
|
+
"1m1.111s"
|
31
|
+
end
|
32
|
+
|
33
|
+
module Error
|
34
|
+
def self.example
|
35
|
+
Result.example file, :errors => 1, :failures => 0
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.file
|
39
|
+
'error.rb'
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
module Failed
|
44
|
+
def self.example
|
45
|
+
Result.example file, :errors => 0, :failures => 1
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.file
|
49
|
+
'fail.rb'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
module Passed
|
54
|
+
def self.example
|
55
|
+
Result.example file, :errors => 0, :failures => 0
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.file
|
59
|
+
'pass.rb'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module Telemetry
|
4
|
+
def self.example failed=nil
|
5
|
+
telemetry = TestBench::Telemetry.new
|
6
|
+
telemetry.failed = failed
|
7
|
+
telemetry
|
8
|
+
end
|
9
|
+
|
10
|
+
module Failed
|
11
|
+
def self.example
|
12
|
+
Telemetry.example true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Passed
|
17
|
+
def self.example
|
18
|
+
Telemetry.example false
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module TestBench
|
2
|
+
module Controls
|
3
|
+
module TestScript
|
4
|
+
module Failing
|
5
|
+
def self.example
|
6
|
+
'assert false'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
module Passing
|
11
|
+
def self.example
|
12
|
+
'assert true'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
module Error
|
17
|
+
def self.example
|
18
|
+
'fail'
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|