test_bench 1.0.1.1 → 1.1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/test_bench.rb +9 -9
  3. data/lib/test_bench/cli.rb +2 -2
  4. data/lib/test_bench/cli/parse_arguments.rb +31 -18
  5. data/lib/test_bench/controls.rb +5 -1
  6. data/lib/test_bench/controls/output/batch_data.rb +52 -0
  7. data/lib/test_bench/controls/output/detail_setting.rb +29 -0
  8. data/lib/test_bench/controls/output/exercise.rb +7 -0
  9. data/lib/test_bench/controls/output/log_level.rb +7 -0
  10. data/lib/test_bench/controls/output/summary/error.rb +0 -16
  11. data/lib/test_bench/controls/output/summary/session.rb +20 -0
  12. data/lib/test_bench/controls/pattern.rb +6 -2
  13. data/lib/test_bench/controls/time.rb +18 -0
  14. data/lib/test_bench/fixture +1 -0
  15. data/lib/test_bench/fixture.rb +1 -0
  16. data/lib/test_bench/output.rb +14 -2
  17. data/lib/test_bench/output/batch_data.rb +17 -0
  18. data/lib/test_bench/output/buffer.rb +112 -0
  19. data/lib/test_bench/output/log.rb +27 -0
  20. data/lib/test_bench/output/raw.rb +353 -0
  21. data/lib/test_bench/output/summary.rb +146 -0
  22. data/lib/test_bench/output/summary/session.rb +94 -0
  23. data/lib/test_bench/output/writer.rb +2 -2
  24. data/lib/test_bench/run.rb +7 -7
  25. metadata +15 -12
  26. data/lib/test_bench/controls/output/summary/run.rb +0 -59
  27. data/lib/test_bench/output/build.rb +0 -51
  28. data/lib/test_bench/output/levels/debug.rb +0 -229
  29. data/lib/test_bench/output/levels/failure.rb +0 -31
  30. data/lib/test_bench/output/levels/none.rb +0 -13
  31. data/lib/test_bench/output/levels/pass.rb +0 -286
  32. data/lib/test_bench/output/levels/summary.rb +0 -21
  33. data/lib/test_bench/output/summary/error.rb +0 -77
  34. data/lib/test_bench/output/summary/run.rb +0 -102
  35. data/lib/test_bench/output/summary/run/print.rb +0 -98
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e5dc802eff42633ec71536849758c5116bfa837cfd63f422c372488e1b28ab8
4
- data.tar.gz: 2c84f96196e8a20dafb78836415f9a9d042afb0e023a8b0477a98713e2694647
3
+ metadata.gz: 9d18b019b73d853e50b78abd989c8d8969c65eb7c5beedc0f3eeadb415f652aa
4
+ data.tar.gz: e8a421026be5f2cf1c5f2af81ddd6a763ab0095669bbda97998fee4ca6fafb83
5
5
  SHA512:
6
- metadata.gz: 6836f23d39dace2d2eedc88cddbcf6928fbcfd4624e7485748706e7774fa540399b5cf5141ca60f4ac32b1fdb13aa9f7f187541d86ff2e6c020a2ca32881f5ef
7
- data.tar.gz: fd7a547ec5c1d9eeb3da5da4802a2e37f4f8ab4e1f0e7dc550746efdf6aa81cf3b628eb056273a20659e0639d4ef6dbcb4e3fa04aa320f1917491757964ea663
6
+ metadata.gz: bc855a5819e98378bae988487b7d8e55c5143ca157f6f116c1411e2bbf087771a6bf992650049d07cb3b1a8a0666ad56ef4ef05686a88536264884700851de77
7
+ data.tar.gz: 15a6baea7cbbf7f8cfcccaa17c3bb128fe396be9ffb227087335f4edc5a569d95cdbe066359f9af80907f3fa298e8299af8be0d402fb6e08c3c125222fe69a23
@@ -14,17 +14,17 @@ require 'test_bench/output/timer/substitute'
14
14
 
15
15
  require 'test_bench/output/print_error'
16
16
 
17
- require 'test_bench/output/summary/run/print'
18
- require 'test_bench/output/summary/run'
19
- require 'test_bench/output/summary/error'
17
+ require 'test_bench/output/summary'
18
+ require 'test_bench/output/summary/session'
20
19
 
21
- require 'test_bench/output/levels/none'
22
- require 'test_bench/output/levels/summary'
23
- require 'test_bench/output/levels/failure'
24
- require 'test_bench/output/levels/debug'
25
- require 'test_bench/output/levels/pass'
20
+ require 'test_bench/output/batch_data'
21
+
22
+ require 'test_bench/output/raw'
23
+
24
+ require 'test_bench/output/buffer'
25
+
26
+ require 'test_bench/output/log'
26
27
 
27
- require 'test_bench/output/build'
28
28
  require 'test_bench/output'
29
29
 
30
30
  require 'test_bench/test_bench'
@@ -1,6 +1,6 @@
1
1
  module TestBench
2
2
  module CLI
3
- def self.call(tests_directory=nil, **runner_args)
3
+ def self.call(tests_directory=nil, exclude_file_pattern: nil)
4
4
  tests_directory ||= Defaults.tests_directory
5
5
 
6
6
  path_arguments = ParseArguments.()
@@ -11,7 +11,7 @@ module TestBench
11
11
  warn "$stdin is a pipe, but no data was written to it; no test files will be run"
12
12
  end
13
13
 
14
- Run.(**runner_args) do |run|
14
+ Run.(exclude: exclude_file_pattern) do |run|
15
15
  if read_stdin
16
16
  until $stdin.eof?
17
17
  path = $stdin.gets.chomp
@@ -66,7 +66,19 @@ module TestBench
66
66
  env['TEST_BENCH_ABORT_ON_ERROR'] = abort_on_error ? 'on' : 'off'
67
67
  end
68
68
 
69
- parser.on('-x', '--[no-]exclude PATTERN', %{Do not execute test files matching PATTERN (Default: #{Run::Defaults.exclude_file_pattern.inspect})}) do |pattern_text|
69
+ parser.on('-d', '--[no-]detail [DETAIL]', %{Always show (or hide) details (Default: #{Output::Raw::Defaults.detail})}) do |detail|
70
+ if detail.nil?
71
+ detail = 'on'
72
+ elsif detail == true
73
+ detail = 'on'
74
+ elsif detail == false
75
+ detail = 'off'
76
+ end
77
+
78
+ env['TEST_BENCH_DETAIL'] = detail
79
+ end
80
+
81
+ parser.on('-x', '--[no-]exclude PATTERN', %{Do not execute test files matching PATTERN (Default: #{Run::Defaults.exclude_pattern.inspect})}) do |pattern_text|
70
82
  if pattern_text == false
71
83
  pattern_text = self.none_pattern
72
84
  end
@@ -76,6 +88,14 @@ module TestBench
76
88
  env['TEST_BENCH_EXCLUDE_FILE_PATTERN'] = pattern_text
77
89
  end
78
90
 
91
+ parser.on('-l', '--log-level LEVEL', %{Set the internal logging level to LEVEL (Default: #{Output::Log::Defaults.level})}) do |level_text|
92
+ level = level_text.to_sym
93
+
94
+ Fixture::Output::Log.assure_level(level)
95
+
96
+ env['TEST_BENCH_LOG_LEVEL'] = level_text
97
+ end
98
+
79
99
  parser.on('-o', '--[no-]omit-backtrace PATTERN', %{Omit backtrace frames matching PATTERN (Default: #{Output::PrintError::Defaults.omit_backtrace_pattern.inspect})}) do |pattern_text|
80
100
  if pattern_text == false
81
101
  pattern_text = self.none_pattern
@@ -86,20 +106,12 @@ module TestBench
86
106
  env['TEST_BENCH_OMIT_BACKTRACE_PATTERN'] = pattern_text
87
107
  end
88
108
 
89
- parser.on('-l', '--output-level [none|summary|failure|pass|debug]', %{Sets output level (Default: #{Output::Build::Defaults.level})}) do |level_text|
90
- level = level_text.to_sym
91
-
92
- Output::Build.assure_level(level)
93
-
94
- env['TEST_BENCH_OUTPUT_LEVEL'] = level_text
95
- end
96
-
97
- parser.on('-s', '--output-styling [on|off|detect]', %{Render output coloring and font styling escape codes (Default: #{Output::Writer::Defaults.styling_setting})}) do |styling_text|
109
+ parser.on('-s', '--output-styling [on|off|detect]', %{Render output coloring and font styling escape codes (Default: #{Output::Writer::Defaults.styling})}) do |styling_text|
98
110
  styling_text ||= 'on'
99
111
 
100
- styling_setting = styling_text.to_sym
112
+ styling = styling_text.to_sym
101
113
 
102
- Output::Writer.assure_styling_setting(styling_setting)
114
+ Output::Writer.assure_styling_setting(styling)
103
115
 
104
116
  env['TEST_BENCH_OUTPUT_STYLING'] = styling_text
105
117
  end
@@ -112,6 +124,10 @@ module TestBench
112
124
  env['TEST_BENCH_REVERSE_BACKTRACES'] = reverse_backtraces ? 'on' : 'off'
113
125
  end
114
126
 
127
+ parser.on('-v', '--[no-]verbose', %{Increase output verbosity (Default: #{Output::Raw::Defaults.verbose ? 'on' : 'off'})}) do |verbose|
128
+ env['TEST_BENCH_VERBOSE'] = verbose ? 'on' : 'off'
129
+ end
130
+
115
131
  parser.separator(<<~TEXT)
116
132
 
117
133
  Paths to test files (and directories containing test files) can be given after any command line arguments or via STDIN (or both).
@@ -120,17 +136,14 @@ module TestBench
120
136
  The following environment variables can also control execution:
121
137
 
122
138
  #{parser.summary_indent}TEST_BENCH_ABORT_ON_ERROR Same as -a or --abort-on-error
139
+ #{parser.summary_indent}TEST_BENCH_DETAIL Same as -d or --detail
123
140
  #{parser.summary_indent}TEST_BENCH_EXCLUDE_FILE_PATTERN Same as -x or --exclude-file-pattern
141
+ #{parser.summary_indent}TEST_BENCH_LOG_LEVEL Same as -l or --log-level
124
142
  #{parser.summary_indent}TEST_BENCH_OMIT_BACKTRACE_PATTERN Same as -o or --omit-backtrace-pattern
125
- #{parser.summary_indent}TEST_BENCH_OUTPUT_LEVEL Same as -l or --output-level
126
143
  #{parser.summary_indent}TEST_BENCH_OUTPUT_STYLING Same as -s or --output-styling
127
144
  #{parser.summary_indent}TEST_BENCH_FAIL_DEACTIVATED_TESTS Opposite of -p or --permit-deactivated-tests
128
145
  #{parser.summary_indent}TEST_BENCH_REVERSE_BACKTRACES Same as -r or --reverse-backtraces
129
-
130
- TEXT
131
-
132
- parser.separator(<<~TEXT)
133
- Finally, the VERBOSE environment variable can set the output level to debug. If given, VERBOSE will take precedence over TEST_BENCH_OUTPUT_STYLING.
146
+ #{parser.summary_indent}TEST_BENCH_VERBOSE Same as -v or --reverse-backtraces
134
147
 
135
148
  TEXT
136
149
  end
@@ -18,5 +18,9 @@ require 'test_bench/controls/output/escape_code'
18
18
  require 'test_bench/controls/output/newline_character'
19
19
  require 'test_bench/controls/output/styling'
20
20
  require 'test_bench/controls/output/print_error'
21
- require 'test_bench/controls/output/summary/run'
21
+ require 'test_bench/controls/output/exercise'
22
+ require 'test_bench/controls/output/summary/session'
22
23
  require 'test_bench/controls/output/summary/error'
24
+ require 'test_bench/controls/output/batch_data'
25
+ require 'test_bench/controls/output/detail_setting'
26
+ require 'test_bench/controls/output/log_level'
@@ -0,0 +1,52 @@
1
+ module TestBench
2
+ module Controls
3
+ module Output
4
+ module BatchData
5
+ def self.example(result: nil, depth: nil)
6
+ result = self.result if result.nil?
7
+ depth ||= self.depth
8
+
9
+ TestBench::Output::BatchData.new(result, depth)
10
+ end
11
+
12
+ def self.result
13
+ Pass.result
14
+ end
15
+
16
+ def self.depth
17
+ 1
18
+ end
19
+
20
+ module Pass
21
+ def self.example(depth: nil)
22
+ BatchData.example(result: result, depth: depth)
23
+ end
24
+
25
+ def self.result
26
+ Result::Pass.example
27
+ end
28
+ end
29
+
30
+ module Failure
31
+ def self.example(depth: nil)
32
+ BatchData.example(result: result, depth: depth)
33
+ end
34
+
35
+ def self.result
36
+ Result::Failure.example
37
+ end
38
+ end
39
+
40
+ module Toplevel
41
+ def self.example(result: nil)
42
+ BatchData.example(depth: depth, result: result)
43
+ end
44
+
45
+ def self.depth
46
+ 0
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,29 @@
1
+ module TestBench
2
+ module Controls
3
+ module Output
4
+ module DetailSetting
5
+ def self.example
6
+ failure
7
+ end
8
+
9
+ def self.failure
10
+ :failure
11
+ end
12
+
13
+ def self.on
14
+ :on
15
+ end
16
+
17
+ def self.off
18
+ :off
19
+ end
20
+
21
+ module Invalid
22
+ def self.example
23
+ :not_a_detail_setting
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,7 @@
1
+ module TestBench
2
+ module Controls
3
+ module Output
4
+ Exercise = TestBench::Fixture::Controls::Output::Exercise
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module TestBench
2
+ module Controls
3
+ module Output
4
+ LogLevel = TestBench::Fixture::Controls::Output::Log::Level
5
+ end
6
+ end
7
+ end
@@ -3,22 +3,6 @@ module TestBench
3
3
  module Output
4
4
  module Summary
5
5
  module Error
6
- def self.example(writer: nil)
7
- error_summary = Example.new
8
- error_summary.writer = writer unless writer.nil?
9
- error_summary
10
- end
11
-
12
- class Example
13
- include TestBench::Fixture::Output
14
- include TestBench::Output::Summary::Error
15
-
16
- TestBench::Fixture::Output.instance_methods.each do |method|
17
- define_method(method) do |*|
18
- end
19
- end
20
- end
21
-
22
6
  module Text
23
7
  def self.example
24
8
  <<~TEXT
@@ -0,0 +1,20 @@
1
+ module TestBench
2
+ module Controls
3
+ module Output
4
+ module Summary
5
+ module Session
6
+ module Text
7
+ def self.example
8
+ <<~TEXT
9
+ Finished running 0 files
10
+ Ran 0 tests in 0.000s (0.0 tests/second)
11
+ 0 passed, 0 skipped, 0 failed, 0 total errors
12
+
13
+ TEXT
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -1,8 +1,12 @@
1
1
  module TestBench
2
2
  module Controls
3
3
  module Pattern
4
- def self.example
5
- /#{text}/
4
+ def self.example(text=nil)
5
+ text ||= self.text
6
+
7
+ escaped_text = Regexp.escape(text)
8
+
9
+ Regexp.new(escaped_text)
6
10
  end
7
11
 
8
12
  def self.text
@@ -55,6 +55,24 @@ module TestBench
55
55
  "1.111s"
56
56
  end
57
57
  end
58
+
59
+ module PerSecond
60
+ def self.example
61
+ elapsed_time = Elapsed.example
62
+
63
+ Rational(ocurrences, elapsed_time)
64
+ end
65
+
66
+ def self.ocurrences
67
+ 1
68
+ end
69
+
70
+ module Text
71
+ def self.example
72
+ "0.9"
73
+ end
74
+ end
75
+ end
58
76
  end
59
77
  end
60
78
  end
@@ -0,0 +1 @@
1
+ lib/test_bench/home/ntl/Projects/test-bench-fixture/lib/test_bench/fixture
@@ -0,0 +1 @@
1
+ lib/test_bench/home/ntl/Projects/test-bench-fixture/lib/test_bench/fixture.rb
@@ -1,7 +1,19 @@
1
1
  module TestBench
2
2
  module Output
3
- def self.build(**args)
4
- Build.(**args)
3
+ def self.build(log_level: nil, writer: nil, device: nil, styling: nil, **buffer_output_args)
4
+ summary = Summary.build(writer: writer, device: device, styling: styling)
5
+
6
+ log_output = Log.build(level: log_level)
7
+
8
+ writer = summary.writer
9
+
10
+ buffer_output = Buffer.build(writer: writer, **buffer_output_args)
11
+
12
+ Fixture::Output::Multiple.build(
13
+ log_output,
14
+ buffer_output,
15
+ summary
16
+ )
5
17
  end
6
18
 
7
19
  Substitute = Fixture::Output::Substitute
@@ -0,0 +1,17 @@
1
+ module TestBench
2
+ module Output
3
+ BatchData = Struct.new(:result, :depth) do
4
+ def passed?
5
+ result
6
+ end
7
+
8
+ def failed?
9
+ !result
10
+ end
11
+
12
+ def toplevel?
13
+ depth.zero?
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,112 @@
1
+ module TestBench
2
+ module Output
3
+ class Buffer < Fixture::Output::Capture
4
+ attr_accessor :writer
5
+
6
+ def raw_output
7
+ @raw_output ||= Raw.new
8
+ end
9
+ attr_writer :raw_output
10
+
11
+ def stack
12
+ @stack ||= []
13
+ end
14
+
15
+ def self.build(verbose: nil, detail: nil, omit_backtrace_pattern: nil, reverse_backtraces: nil, writer: nil, device: nil, styling: nil)
16
+ instance = new
17
+
18
+ raw_output = Raw.configure(instance, verbose: verbose, detail: detail, omit_backtrace_pattern: omit_backtrace_pattern, reverse_backtraces: reverse_backtraces, writer: writer, device: device, styling: styling)
19
+
20
+ instance.writer = raw_output.writer
21
+
22
+ instance
23
+ end
24
+
25
+ def exit_context(*)
26
+ super
27
+
28
+ flush unless buffering?
29
+ end
30
+
31
+ def finish_test(*)
32
+ super
33
+
34
+ flush unless buffering?
35
+ end
36
+
37
+ def finish_fixture(*)
38
+ super
39
+
40
+ flush unless buffering?
41
+ end
42
+
43
+ def new_record(signal, data)
44
+ record = Record.new(signal, data)
45
+
46
+ case signal
47
+ when :enter_context, :start_test, :start_fixture
48
+ start_batch(record)
49
+
50
+ when :exit_context, :finish_test, :finish_fixture
51
+ result = record.data.last
52
+
53
+ finish_batch(record, result)
54
+ end
55
+
56
+ record
57
+ end
58
+
59
+ def start_batch(record)
60
+ record.start_batch(stack_depth)
61
+
62
+ stack.push(record)
63
+ end
64
+
65
+ def finish_batch(final_record, result)
66
+ first_record = stack.pop
67
+
68
+ batch_data = first_record.batch_data
69
+ batch_data.result = result
70
+
71
+ final_record.batch_data = first_record.batch_data
72
+ end
73
+
74
+ def flush
75
+ records.each do |record|
76
+ record.forward(raw_output)
77
+ end
78
+
79
+ records.clear
80
+ end
81
+
82
+ def buffering?
83
+ stack_depth.nonzero?
84
+ end
85
+
86
+ def stack_depth
87
+ stack.length
88
+ end
89
+
90
+ class Record < Fixture::Output::Capture::Record
91
+ attr_accessor :batch_data
92
+
93
+ def forward(raw_output)
94
+ return super if batch_data.nil?
95
+
96
+ raw_output.public_send(signal, *data, batch_data: batch_data)
97
+ end
98
+
99
+ def start_batch(depth)
100
+ batch_data = Output::BatchData.new
101
+ batch_data.depth = depth
102
+
103
+ self.batch_data = batch_data
104
+ end
105
+
106
+ def finish_batch(result)
107
+ batch_data.result = result
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end