Skip to content

Commit 722c89c

Browse files
authored
Support for TruffleRuby (#44)
Initial support for TruffleRuby and JRuby.
1 parent 49499ff commit 722c89c

File tree

12 files changed

+63
-150
lines changed

12 files changed

+63
-150
lines changed

.github/workflows/ruby.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,19 @@ jobs:
3232
ruby-version: ${{ matrix.ruby-version }}
3333
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
3434
bundler-args: --without development
35-
- name: Run Rubocop
36-
run: bundle exec rubocop
3735
- name: Quickdraw tests
38-
run: bundle exec qt
36+
run: bundle exec qt -t 1
37+
rubocop:
38+
runs-on: ubuntu-latest
39+
strategy:
40+
matrix:
41+
ruby-version: ['3.3']
42+
steps:
43+
- uses: actions/checkout@v3
44+
- name: Set up Ruby
45+
uses: ruby/setup-ruby@v1
46+
with:
47+
ruby-version: ${{ matrix.ruby-version }}
48+
bundler-cache: true
49+
- name: Run RuboCop
50+
run: bundle exec rubocop

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
.rubocop-*
1010
.DS_Store
1111
.covered.db
12+
Gemfile.lock

Gemfile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ source "https://rubygems.org"
55
# Specify your gem's dependencies in quickdraw.gemspec
66
gemspec
77

8-
group :development do
9-
gem "rubocop"
10-
gem "rspec-expectations"
11-
gem "minitest"
12-
gem "sus"
13-
gem "covered"
8+
gem "rspec-expectations"
9+
10+
if RUBY_ENGINE == "ruby"
11+
group :development do
12+
gem "rubocop"
13+
gem "minitest"
14+
gem "sus"
15+
gem "covered"
16+
end
1417
end

Gemfile.lock

Lines changed: 0 additions & 73 deletions
This file was deleted.

lib/quickdraw.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# frozen_string_literal: true
22

3+
require "concurrent/map"
4+
require "concurrent/array"
5+
require "concurrent/set"
6+
37
module Quickdraw
48
autoload :ArgumentError, "quickdraw/errors/argument_error"
59
autoload :CLI, "quickdraw/cli"
@@ -26,6 +30,7 @@ module Quickdraw
2630
Null = Object.new.freeze
2731
Error = Module.new
2832
Config = Configuration.new
33+
MATCHERS = Concurrent::Map.new
2934

3035
def self.configure(&)
3136
yield Config

lib/quickdraw/concurrent_array.rb

Lines changed: 0 additions & 20 deletions
This file was deleted.

lib/quickdraw/context.rb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ def test(name = nil, skip: false, &block)
99
end
1010

1111
def use(*new_matchers)
12+
matchers = self.matchers
13+
1214
i = 0
1315
number_of_new_matchers = new_matchers.size
1416

@@ -19,10 +21,12 @@ def use(*new_matchers)
1921
end
2022

2123
def matchers
22-
@matchers ||= if superclass < Quickdraw::Context
23-
superclass.matchers.dup
24-
else
25-
Set[]
24+
Quickdraw::MATCHERS.fetch_or_store(self) do
25+
if superclass < Quickdraw::Context
26+
superclass.matchers.dup
27+
else
28+
Concurrent::Set.new
29+
end
2630
end
2731
end
2832

@@ -39,7 +43,7 @@ def initialize(name, skip, runner, matchers)
3943
@runner = runner
4044
@matchers = matchers
4145

42-
@expectations = []
46+
@expectations = Concurrent::Array.new
4347
end
4448

4549
def expect(value = Quickdraw::Null, &block)

lib/quickdraw/map.rb

Lines changed: 0 additions & 30 deletions
This file was deleted.

lib/quickdraw/registry.rb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
class Quickdraw::Registry
44
def initialize
5-
@registered_matchers = Quickdraw::Map.new
6-
@type_matchers = Quickdraw::Map.new
7-
@shapes = Quickdraw::Map.new
5+
@registered_matchers = Concurrent::Map.new
6+
@type_matchers = Concurrent::Map.new
7+
@shapes = Concurrent::Map.new
88
end
99

1010
# Register a new matcher for the given types.
@@ -32,15 +32,19 @@ def expectation_for(value, matchers: nil)
3232

3333
# A "shape" is a specialised Expectation class that includes the given matchers. It's cached against the list of matchers.
3434
def shape_for(matchers)
35-
@shapes[matchers] ||= Class.new(Quickdraw::Expectation) do
36-
matchers.each { |m| include m }
37-
freeze
35+
@shapes.fetch_or_store(matchers) do
36+
Class.new(Quickdraw::Expectation) do
37+
matchers.each { |m| include m }
38+
freeze
39+
end
3840
end
3941
end
4042

4143
# Given a value, find all the matchers that match it. This is cached against the class of the value.
4244
def matchers_for(value)
43-
@type_matchers[value.class] ||= slowly_find_matchers_for(value)
45+
@type_matchers.fetch_or_store(value.class) do
46+
slowly_find_matchers_for(value)
47+
end
4448
end
4549

4650
# If the above has a cache miss, we'll need to find the correct matchers slowly and then cache them.

lib/quickdraw/run.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def load_tests
7272
end
7373

7474
def batch_tests
75-
batches = Array.new([@processes, @tests.size].min) { Quickdraw::Queue.new }
75+
batches = Array.new([@processes, @tests.size].min) { Concurrent::Array.new }
7676

7777
number_of_tests = @tests.size
7878
i = 0
@@ -111,7 +111,7 @@ def fork_processes
111111
end
112112

113113
def run_inline
114-
queue = Quickdraw::Queue.new
114+
queue = Concurrent::Array.new
115115

116116
i = 0
117117
number_of_tests = @tests.size

lib/quickdraw/runner.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ def initialize(queue:, threads:)
77
@queue = queue
88
@threads = threads
99

10-
@failures = Quickdraw::ConcurrentArray.new
11-
@successes = Quickdraw::ConcurrentArray.new
10+
@failures = Concurrent::Array.new
11+
@successes = Concurrent::Array.new
1212
end
1313

1414
def call
@@ -47,8 +47,13 @@ def failure!
4747
private
4848

4949
def drain_queue
50-
@queue.drain { |(name, skip, test, context)|
50+
queue = @queue
51+
next_item = queue.shift
52+
53+
while next_item
54+
name, skip, test, context = next_item
5155
context.run_test(name, skip, self, &test)
52-
}
56+
next_item = queue.shift
57+
end
5358
end
5459
end

quickdraw.gemspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
3030
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
3131
spec.require_paths = ["lib"]
3232

33+
spec.add_runtime_dependency "concurrent-ruby"
34+
3335
# For more information and examples about making a new gem, check out our
3436
# guide at: https://bundler.io/guides/creating_gem.html
3537
spec.metadata["rubygems_mfa_required"] = "true"

0 commit comments

Comments
 (0)