turbo_test 0.1.1 → 0.1.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7f598fcd0bc09d2a885b3d0440eabbfa54c2718fae7f39d9f8b853fa37503474
4
- data.tar.gz: 348390cf74c0b7ba9c05d806eb2e84dd9571b3851cac2ae6dfd98898d2531a35
3
+ metadata.gz: dd92a8d1d67932dc52d0643b26380c7ccec43d8ad63fc52b398d1f5ff264b1b8
4
+ data.tar.gz: e886dba89a2425174af3d17b2786a4ce28bc75f8cd0fdfa3e59aef338f4d1e2f
5
5
  SHA512:
6
- metadata.gz: 2afcc1b037df3aa41ba017861939fbfff7fe7ff9e861026f56aa3771504344e6b2de58b4eecccfa963e1bca9688e789d931c7a51c2949353526a99e6847017ad
7
- data.tar.gz: 4b1270405702e4f9ccdd736c6bdbcfd75e61fa02bcc0080b1317cc1c21d42f2152cc8fc1cd8cee3e3013538f54dbf2f369f281239739788e7ee3bac88fac74ec
6
+ metadata.gz: 7b7e1cbcb8e14faf15cd70b9a6cf93a6ef0b6d8163c4d97afd23efebe5f5f3d5834c998346c3dcf6e3295d9bcbc47462b6ae7dccbb019c3a3dc51b1df3fc2b15
7
+ data.tar.gz: 7bf27ab042926db051945d7b1bc52dc6912a52e3f54a96f116827e33ab185244c64192043ad6b1947d26d209433571f7546dadfcd24de35a87d430285790968f
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'samovar'
24
+
25
+ require_relative '../server'
26
+ require_relative '../configuration'
27
+ require_relative '../rspec/job'
28
+
29
+ require 'bundler'
30
+
31
+ module TurboTest
32
+ module Command
33
+ class List < Samovar::Command
34
+ self.description = "List tests available to be run."
35
+
36
+ # The command line options.
37
+ # @attribute [Samovar::Options]
38
+ options do
39
+ option '-c/--configuration <path>', "The configuration path to use.", default: "turbo_test.rb"
40
+ end
41
+
42
+ # Prepare the environment and run the controller.
43
+ def call
44
+ path = @options[:configuration]
45
+ full_path = File.expand_path(path)
46
+
47
+ configuration = Configuration.new
48
+
49
+ if File.exist?(full_path)
50
+ configuration.load(full_path)
51
+ end
52
+
53
+ configuration.finalize!
54
+
55
+ configuration.jobs.each do |klass, path, **options|
56
+ if options&.any?
57
+ puts "#{klass}: #{path} #{options.inspect}"
58
+ else
59
+ puts "#{klass}: #{path}"
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
@@ -38,7 +38,7 @@ module TurboTest
38
38
  options do
39
39
  option '-n/--count <count>', "Number of instances to start.", default: Async::Container.processor_count, type: Integer
40
40
 
41
- option '-c/--configuration', "The configuration path to use.", default: "turbo_test.rb"
41
+ option '-c/--configuration <path>', "The configuration path to use.", default: "turbo_test.rb"
42
42
  end
43
43
 
44
44
  many :paths, "The test paths to execute."
@@ -52,10 +52,14 @@ module TurboTest
52
52
  path = @options[:configuration]
53
53
  full_path = File.expand_path(path)
54
54
 
55
+ configuration = Configuration.new
56
+
55
57
  if File.exist?(full_path)
56
- configuration = Configuration.load(full_path)
58
+ configuration.load(full_path)
57
59
  end
58
60
 
61
+ configuration.finalize!
62
+
59
63
  Bundler.require(:preload)
60
64
 
61
65
  if GC.respond_to?(:compact)
@@ -64,11 +68,17 @@ module TurboTest
64
68
 
65
69
  server = Server.new(configuration)
66
70
 
67
- queue = paths.map do |path|
68
- [RSpec::Job, path]
71
+ queue = configuration.queue(
72
+ paths&.map{|path| File.expand_path(path)}
73
+ )
74
+
75
+ results = server.run(queue)
76
+
77
+ if results[:failed].zero?
78
+ puts "All tests passed!"
69
79
  end
70
80
 
71
- return server.run(queue)
81
+ return results
72
82
  end
73
83
  end
74
84
  end
@@ -21,6 +21,7 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  require_relative 'run'
24
+ require_relative 'list'
24
25
  require_relative '../version'
25
26
 
26
27
  require 'samovar'
@@ -43,6 +44,7 @@ module TurboTest
43
44
  # @attribute [Command]
44
45
  nested :command, {
45
46
  'run' => Run,
47
+ 'list' => List,
46
48
  }, default: 'run'
47
49
 
48
50
  # Prepare the environment and invoke the sub-command.
@@ -20,31 +20,80 @@
20
20
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
21
  # THE SOFTWARE.
22
22
 
23
+ require_relative 'rspec/job'
24
+
23
25
  module TurboTest
24
26
  class Configuration
25
27
  def initialize
28
+ @loaded = false
26
29
  @worker = nil
30
+ @jobs = []
27
31
  end
28
32
 
33
+ attr_accessor :loaded
29
34
  attr_accessor :worker
35
+ attr_accessor :jobs
30
36
 
31
- def self.load(path)
32
- configuration = self.new
37
+ def load(path)
38
+ loader = Loader.new(self, File.dirname(path))
33
39
 
34
- loader = Loader.new(configuration)
35
40
  loader.instance_eval(File.read(path), path.to_s)
36
41
 
37
- return configuration
42
+ return loader
43
+ end
44
+
45
+ def finalize!
46
+ unless @loaded
47
+ self.defaults!
48
+ end
49
+ end
50
+
51
+ def queue(matching)
52
+ if matching.nil? or matching.empty?
53
+ # No filtering required, return all jobs:
54
+ return @jobs.dup
55
+ else
56
+ return @jobs.select{|klass, path| matching.include?(path)}
57
+ end
58
+ end
59
+
60
+ DEFAULT_JOB_CLASSES = [RSpec::Job]
61
+
62
+ def defaults!(pwd = Dir.pwd)
63
+ loader = Loader.new(self, pwd)
64
+
65
+ loader.defaults!
66
+
67
+ return loader
38
68
  end
39
69
 
40
70
  class Loader
41
- def initialize(configuration)
71
+ def initialize(configuration, base)
42
72
  @configuration = configuration
73
+ @base = base
43
74
  end
44
75
 
76
+ attr :path
77
+
45
78
  def worker(&block)
46
79
  @configuration.worker = block
47
80
  end
81
+
82
+ def add_jobs_matching(klass, pattern: klass::PATTERN, **options)
83
+ # This indicates that someone has added jobs:
84
+ @configuration.loaded = true
85
+
86
+ Dir.glob(pattern, base: @base) do |path|
87
+ path = File.expand_path(path, @base)
88
+ @configuration.jobs << [klass, path, **options]
89
+ end
90
+ end
91
+
92
+ def defaults!
93
+ DEFAULT_JOB_CLASSES.each do |klass|
94
+ add_jobs_matching(klass)
95
+ end
96
+ end
48
97
  end
49
98
  end
50
99
  end
@@ -45,7 +45,9 @@ module TurboTest
45
45
  end
46
46
 
47
47
  class Job
48
- def initialize(path)
48
+ PATTERN = "spec/**/*_spec.rb"
49
+
50
+ def initialize(path, **options)
49
51
  @path = path
50
52
  end
51
53
 
@@ -223,6 +223,10 @@ module TurboTest
223
223
 
224
224
  # Read the results from the host:
225
225
  return results.read
226
+ ensure
227
+ if path = @endpoint.path and File.exist?(path)
228
+ File.unlink(path)
229
+ end
226
230
  end
227
231
  end
228
232
  end
@@ -21,5 +21,5 @@
21
21
  # THE SOFTWARE.
22
22
 
23
23
  module TurboTest
24
- VERSION = "0.1.1"
24
+ VERSION = "0.1.2"
25
25
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turbo_test
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-01 00:00:00.000000000 Z
11
+ date: 2021-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: async-container
@@ -90,6 +90,7 @@ files:
90
90
  - bin/turbo_test
91
91
  - lib/turbo_test.rb
92
92
  - lib/turbo_test/command.rb
93
+ - lib/turbo_test/command/list.rb
93
94
  - lib/turbo_test/command/run.rb
94
95
  - lib/turbo_test/command/top.rb
95
96
  - lib/turbo_test/configuration.rb