Skip to content

Commit

Permalink
Support for TruffleRuby (#44)
Browse files Browse the repository at this point in the history
Initial support for TruffleRuby and JRuby.
  • Loading branch information
joeldrapper authored Oct 23, 2024
1 parent 49499ff commit 722c89c
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 150 deletions.
18 changes: 15 additions & 3 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,19 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
bundler-args: --without development
- name: Run Rubocop
run: bundle exec rubocop
- name: Quickdraw tests
run: bundle exec qt
run: bundle exec qt -t 1
rubocop:
runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['3.3']
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true
- name: Run RuboCop
run: bundle exec rubocop
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
.rubocop-*
.DS_Store
.covered.db
Gemfile.lock
15 changes: 9 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ source "https://rubygems.org"
# Specify your gem's dependencies in quickdraw.gemspec
gemspec

group :development do
gem "rubocop"
gem "rspec-expectations"
gem "minitest"
gem "sus"
gem "covered"
gem "rspec-expectations"

if RUBY_ENGINE == "ruby"
group :development do
gem "rubocop"
gem "minitest"
gem "sus"
gem "covered"
end
end
73 changes: 0 additions & 73 deletions Gemfile.lock

This file was deleted.

5 changes: 5 additions & 0 deletions lib/quickdraw.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# frozen_string_literal: true

require "concurrent/map"
require "concurrent/array"
require "concurrent/set"

module Quickdraw
autoload :ArgumentError, "quickdraw/errors/argument_error"
autoload :CLI, "quickdraw/cli"
Expand All @@ -26,6 +30,7 @@ module Quickdraw
Null = Object.new.freeze
Error = Module.new
Config = Configuration.new
MATCHERS = Concurrent::Map.new

def self.configure(&)
yield Config
Expand Down
20 changes: 0 additions & 20 deletions lib/quickdraw/concurrent_array.rb

This file was deleted.

14 changes: 9 additions & 5 deletions lib/quickdraw/context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def test(name = nil, skip: false, &block)
end

def use(*new_matchers)
matchers = self.matchers

i = 0
number_of_new_matchers = new_matchers.size

Expand All @@ -19,10 +21,12 @@ def use(*new_matchers)
end

def matchers
@matchers ||= if superclass < Quickdraw::Context
superclass.matchers.dup
else
Set[]
Quickdraw::MATCHERS.fetch_or_store(self) do
if superclass < Quickdraw::Context
superclass.matchers.dup
else
Concurrent::Set.new
end
end
end

Expand All @@ -39,7 +43,7 @@ def initialize(name, skip, runner, matchers)
@runner = runner
@matchers = matchers

@expectations = []
@expectations = Concurrent::Array.new
end

def expect(value = Quickdraw::Null, &block)
Expand Down
30 changes: 0 additions & 30 deletions lib/quickdraw/map.rb

This file was deleted.

18 changes: 11 additions & 7 deletions lib/quickdraw/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

class Quickdraw::Registry
def initialize
@registered_matchers = Quickdraw::Map.new
@type_matchers = Quickdraw::Map.new
@shapes = Quickdraw::Map.new
@registered_matchers = Concurrent::Map.new
@type_matchers = Concurrent::Map.new
@shapes = Concurrent::Map.new
end

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

# A "shape" is a specialised Expectation class that includes the given matchers. It's cached against the list of matchers.
def shape_for(matchers)
@shapes[matchers] ||= Class.new(Quickdraw::Expectation) do
matchers.each { |m| include m }
freeze
@shapes.fetch_or_store(matchers) do
Class.new(Quickdraw::Expectation) do
matchers.each { |m| include m }
freeze
end
end
end

# Given a value, find all the matchers that match it. This is cached against the class of the value.
def matchers_for(value)
@type_matchers[value.class] ||= slowly_find_matchers_for(value)
@type_matchers.fetch_or_store(value.class) do
slowly_find_matchers_for(value)
end
end

# If the above has a cache miss, we'll need to find the correct matchers slowly and then cache them.
Expand Down
4 changes: 2 additions & 2 deletions lib/quickdraw/run.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def load_tests
end

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

number_of_tests = @tests.size
i = 0
Expand Down Expand Up @@ -111,7 +111,7 @@ def fork_processes
end

def run_inline
queue = Quickdraw::Queue.new
queue = Concurrent::Array.new

i = 0
number_of_tests = @tests.size
Expand Down
13 changes: 9 additions & 4 deletions lib/quickdraw/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def initialize(queue:, threads:)
@queue = queue
@threads = threads

@failures = Quickdraw::ConcurrentArray.new
@successes = Quickdraw::ConcurrentArray.new
@failures = Concurrent::Array.new
@successes = Concurrent::Array.new
end

def call
Expand Down Expand Up @@ -47,8 +47,13 @@ def failure!
private

def drain_queue
@queue.drain { |(name, skip, test, context)|
queue = @queue
next_item = queue.shift

while next_item
name, skip, test, context = next_item
context.run_test(name, skip, self, &test)
}
next_item = queue.shift
end
end
end
2 changes: 2 additions & 0 deletions quickdraw.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]

spec.add_runtime_dependency "concurrent-ruby"

# For more information and examples about making a new gem, check out our
# guide at: https://bundler.io/guides/creating_gem.html
spec.metadata["rubygems_mfa_required"] = "true"
Expand Down

0 comments on commit 722c89c

Please sign in to comment.