test_bench-run 0 → 2.0.0.1

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: 6cc31ef71213961951028bc33a31f17ba40ba1401f18111ed20454be6236e3b4
4
- data.tar.gz: 98d146a75264aef9aa48e3e51366be7a7837830156908540b34df9723a36fdd0
3
+ metadata.gz: ee5f679212e446250cb75afbc800cba8625d1e0d22e99b3c0c58d5d7a77a3ca3
4
+ data.tar.gz: 4e11efce51b52e1b198f8d1b80e6ebcb1607dd0f2ff453f237183b581c0c21e9
5
5
  SHA512:
6
- metadata.gz: 01bf99f7760ff77df99bf40991e91753fe0cc1af6d9ecac45747a34687a193bdbd0d5d6f3a6ada6d2bea1ca04fe527f6fe10ffa3fe7b002b59449665b919b8b3
7
- data.tar.gz: 244160004df72f41db3b3304ad91a36319ccbdf6fefc7c4ee40e13749ce3f1876a2e8ed2884930a7c1178cd638d6ae6987a5ca45bed1b3df258a4e767d14ffb3
6
+ metadata.gz: 2ae36c9a3dec29d76b9c4b1f4bf2b920bb4cf1b66255e9a5e044da4b58131d8ead86b61d936483eb6e351038957c2d1bb95a45d560787637995b5265f207846f
7
+ data.tar.gz: 10c5f4612582c6d08412ae1eab65216feb35ebd0970e87bd0897d1794480a1f07b630dc93c194106e420040441763bdd9b0a6435247a968a95f2ff297d9cbda9
@@ -5,18 +5,23 @@ module TestBench
5
5
  module Finished
6
6
  extend EventData
7
7
 
8
- def self.example(result: nil, process_id: nil, time: nil)
8
+ def self.example(result: nil, random_seed: nil, process_id: nil, time: nil)
9
+ random_seed ||= self.random_seed
9
10
  result = self.result if result.nil?
10
11
  process_id ||= self.process_id
11
12
  time ||= self.time
12
13
 
13
- Run::Events::Finished.build(result, process_id:, time:)
14
+ Run::Events::Finished.build(random_seed, result, process_id:, time:)
14
15
  end
15
16
 
16
17
  def self.random
17
18
  Random.example
18
19
  end
19
20
 
21
+ def self.random_seed
22
+ Started.random_seed
23
+ end
24
+
20
25
  def self.result
21
26
  Result.example
22
27
  end
@@ -32,7 +37,8 @@ module TestBench
32
37
  module Random
33
38
  extend EventData
34
39
 
35
- def self.example(result: nil, process_id: nil, time: nil)
40
+ def self.example(result: nil, random_seed: nil, process_id: nil, time: nil)
41
+ random_seed ||= Controls::Random.integer
36
42
  process_id ||= ProcessID.random
37
43
  time ||= Time.random
38
44
 
@@ -40,7 +46,7 @@ module TestBench
40
46
  result = Result.random
41
47
  end
42
48
 
43
- Finished.example(result:, process_id:, time:)
49
+ Finished.example(result:, random_seed:, process_id:, time:)
44
50
  end
45
51
  end
46
52
  end
@@ -5,17 +5,22 @@ module TestBench
5
5
  module Started
6
6
  extend EventData
7
7
 
8
- def self.example(process_id: nil, time: nil)
8
+ def self.example(random_seed: nil, process_id: nil, time: nil)
9
+ random_seed ||= self.random_seed
9
10
  process_id ||= self.process_id
10
11
  time ||= self.time
11
12
 
12
- Run::Events::Started.build(process_id:, time:)
13
+ Run::Events::Started.build(random_seed, process_id:, time:)
13
14
  end
14
15
 
15
16
  def self.random
16
17
  Random.example
17
18
  end
18
19
 
20
+ def self.random_seed
21
+ 1
22
+ end
23
+
19
24
  def self.process_id
20
25
  ProcessID.example
21
26
  end
@@ -27,11 +32,12 @@ module TestBench
27
32
  module Random
28
33
  extend EventData
29
34
 
30
- def self.example(process_id: nil, time: nil)
35
+ def self.example(random_seed: nil, process_id: nil, time: nil)
36
+ random_seed ||= Controls::Random.integer
31
37
  process_id ||= ProcessID.random
32
38
  time ||= Time.random
33
39
 
34
- Started.example(process_id:, time:)
40
+ Started.example(random_seed:, process_id:, time:)
35
41
  end
36
42
  end
37
43
  end
@@ -5,8 +5,8 @@ module TestBench
5
5
  FileFinished = Telemetry::Event.define(:file, :result)
6
6
  FileCrashed = Telemetry::Event.define(:file, :error_message, :error_text)
7
7
 
8
- Started = Telemetry::Event.define
9
- Finished = Telemetry::Event.define(:result)
8
+ Started = Telemetry::Event.define(:random_seed)
9
+ Finished = Telemetry::Event.define(:random_seed, :result)
10
10
  end
11
11
  end
12
12
  end
@@ -70,12 +70,16 @@ module TestBench
70
70
 
71
71
  session = session_store.fetch
72
72
 
73
+ session_projection = Session::Projection.new(session)
74
+
73
75
  loop do
74
76
  event_text = telemetry_reader.gets
75
77
 
76
78
  event_data = Telemetry::EventData.load(event_text)
77
79
  session.telemetry.record(event_data)
78
80
 
81
+ session_projection.(event_data)
82
+
79
83
  if event_data.type == :FileCrashed
80
84
  session.record_failure
81
85
  dump_exception_text(event_data)
@@ -13,13 +13,21 @@ module TestBench
13
13
  end
14
14
  attr_writer :session
15
15
 
16
+ def random
17
+ @random ||= Random::Substitute.build
18
+ end
19
+ attr_writer :random
20
+
16
21
  def self.build(session: nil)
17
22
  instance = new
18
23
  Session.configure(instance, session:)
24
+ Random.configure(instance)
19
25
  instance
20
26
  end
21
27
 
22
28
  def call(file)
29
+ random.reset(file)
30
+
23
31
  begin
24
32
  source = ::File.read(file)
25
33
  rescue SystemCallError => error
@@ -21,7 +21,7 @@ module TestBench
21
21
  start_file(file)
22
22
  end
23
23
 
24
- handle Session::Events::Failed do |_failed|
24
+ handle Session::Events::Failed do
25
25
  current_file.record_failure
26
26
  end
27
27
 
@@ -57,19 +57,19 @@ module TestBench
57
57
  end
58
58
  end
59
59
 
60
- handle TestSkipped do |_test_skipped|
60
+ handle TestSkipped do
61
61
  self.tests_skipped += 1
62
62
  end
63
63
 
64
- handle ContextSkipped do |_test_skipped|
64
+ handle ContextSkipped do
65
65
  self.contexts_skipped += 1
66
66
  end
67
67
 
68
- handle FileFinished do |_file_finished|
68
+ handle FileFinished do
69
69
  self.files_finished += 1
70
70
  end
71
71
 
72
- handle FileCrashed do |_file_crashed|
72
+ handle FileCrashed do
73
73
  self.files_crashed += 1
74
74
  end
75
75
 
@@ -146,7 +146,10 @@ module TestBench
146
146
  writer.style(:reset_intensity)
147
147
  end
148
148
  else
149
- writer.print("0 passed")
149
+ writer
150
+ .style(:bold, :faint, :italic)
151
+ .print("0 passed")
152
+ .style(:reset_italic, :reset_intensity)
150
153
  end
151
154
  writer.print(", ")
152
155
 
@@ -1,6 +1,7 @@
1
1
  module TestBench
2
2
  class Run
3
- include Session::Handler
3
+ Error = Class.new(RuntimeError)
4
+
4
5
  include Events
5
6
 
6
7
  def telemetry
@@ -23,20 +24,25 @@ module TestBench
23
24
  end
24
25
  attr_writer :executor
25
26
 
27
+ def random
28
+ @random ||= Random::Substitute.build
29
+ end
30
+ attr_writer :random
31
+
26
32
  def path_sequence
27
33
  @path_sequence ||= 0
28
34
  end
29
35
  attr_writer :path_sequence
30
36
 
31
- def self.build(exclude_file_pattern: nil, session_store: nil)
32
- session_store ||= Session::Store.instance
33
-
37
+ def self.build(exclude_file_pattern: nil)
34
38
  instance = new
35
39
 
36
40
  GetFiles.configure(instance, exclude_file_pattern:)
37
41
 
38
42
  Executor::Serial.configure(instance)
39
43
 
44
+ Random.configure(instance)
45
+
40
46
  session = Session.build do |telemetry|
41
47
  Output::File.register(telemetry)
42
48
  Output::Summary::Error.register(telemetry)
@@ -46,16 +52,27 @@ module TestBench
46
52
  end
47
53
 
48
54
  Session.configure(instance, session:)
49
- session_store.put(session)
50
55
 
51
56
  instance
52
57
  end
53
58
 
54
- def self.call(path, exclude_file_pattern: nil)
59
+ def self.call(path, session_store: nil, exclude_file_pattern: nil)
60
+ session_store ||= Session::Store.instance
61
+
55
62
  instance = build(exclude_file_pattern:)
63
+
64
+ session_store.reset(instance.session)
65
+
56
66
  instance.(path)
57
67
  end
58
68
 
69
+ def self.configure(receiver, exclude_file_pattern: nil, attr_name: nil)
70
+ attr_name ||= :run
71
+
72
+ instance = build(exclude_file_pattern:)
73
+ receiver.public_send(:"#{attr_name}=", instance)
74
+ end
75
+
59
76
  def call(path)
60
77
  run do
61
78
  path(path)
@@ -63,12 +80,20 @@ module TestBench
63
80
  end
64
81
 
65
82
  def run(&block)
66
- telemetry.record(Started.build)
83
+ if ran?
84
+ raise Error, "Already ran"
85
+ end
86
+
87
+ telemetry.record(Started.build(random.seed))
67
88
 
68
89
  executor.start
69
90
 
70
91
  if not block.nil?
71
92
  block.(self)
93
+
94
+ if not ran?
95
+ raise Error, "No paths were supplied"
96
+ end
72
97
  end
73
98
 
74
99
  executor.finish
@@ -79,7 +104,7 @@ module TestBench
79
104
  result = false
80
105
  end
81
106
 
82
- telemetry.record(Finished.build(result))
107
+ telemetry.record(Finished.build(random.seed, result))
83
108
  result
84
109
  end
85
110
  alias :! :run
@@ -97,5 +122,33 @@ module TestBench
97
122
  session.record_failure
98
123
  end
99
124
  alias :<< :path
125
+
126
+ def ran?
127
+ path_sequence > 0
128
+ end
129
+
130
+ module Substitute
131
+ def self.build
132
+ Run.build
133
+ end
134
+
135
+ class Run < Run
136
+ def self.build
137
+ new
138
+ end
139
+
140
+ def path?(path)
141
+ get_files.path?(path)
142
+ end
143
+
144
+ def set_result(result)
145
+ if result
146
+ session.record_assertion
147
+ else
148
+ session.record_failure
149
+ end
150
+ end
151
+ end
152
+ end
100
153
  end
101
154
  end
@@ -6,7 +6,6 @@ require 'test_bench/run/get_files'
6
6
  require 'test_bench/run/get_files/substitute'
7
7
 
8
8
  require 'test_bench/run/file'
9
- require 'test_bench/run/file/substitute'
10
9
 
11
10
  require 'test_bench/run/output/file'
12
11
  require 'test_bench/run/output/summary/error'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: test_bench-run
3
3
  version: !ruby/object:Gem::Version
4
- version: '0'
4
+ version: 2.0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Ladd
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-16 00:00:00.000000000 Z
11
+ date: 2023-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: test_bench-fixture
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: test_bench-bootstrap
28
+ name: test_bench-isolated
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -70,7 +70,6 @@ files:
70
70
  - lib/test_bench/run/executor/serial.rb
71
71
  - lib/test_bench/run/executor/substitute.rb
72
72
  - lib/test_bench/run/file.rb
73
- - lib/test_bench/run/file/substitute.rb
74
73
  - lib/test_bench/run/get_files.rb
75
74
  - lib/test_bench/run/get_files/substitute.rb
76
75
  - lib/test_bench/run/output/file.rb
@@ -1,41 +0,0 @@
1
- module TestBench
2
- class Run
3
- class File
4
- module Substitute
5
- def self.build
6
- File.new
7
- end
8
-
9
- class File
10
- def result
11
- @result.nil? ? @result = true : @result
12
- end
13
- attr_writer :result
14
- alias :set_result :result=
15
-
16
- attr_accessor :exception
17
- alias :set_exception :exception=
18
- def exception? = !!exception
19
-
20
- def files
21
- @files ||= []
22
- end
23
-
24
- def call(file)
25
- files << file
26
-
27
- if exception?
28
- raise exception
29
- end
30
-
31
- result
32
- end
33
-
34
- def file?(file)
35
- files.include?(file)
36
- end
37
- end
38
- end
39
- end
40
- end
41
- end