Skip to content

Commit ccec8d8

Browse files
committed
Test Native and GSL Implementations
classifier-reborn is designed to work with or without [GSL](https://www.gnu.org/software/gsl/) support. https://github.com/jekyll/classifier-reborn/blob/99d13af5adf040ba40a6fe77dbe0b28756562fcc/docs/index.md?plain=1#L68 If GSL is installed, classifier-reborn will detect it and use it. If GSL is not installed, classifier-reborn will fall back to a pure-ruby implementation. The mechanism for doing so is in `lsi.rb`: https://github.com/jekyll/classifier-reborn/blob/99d13af5adf040ba40a6fe77dbe0b28756562fcc/lib/classifier-reborn/lsi.rb#L7-L17 I think it's important to test the classifier-reborn gem with GSL support in CI. One of my goals is to add similar support using Numo, and I'd like that to be tested in CI as well. Also, I want to make sure I don't do anything along the way that could break existing GSL support. As far as I can tell, GSL support was never tested in CI before now (though it was previously discussed [here](jekyll#46 (comment))). In this PR, I'm expanding our text matrix to test with and without GSL enabled. When the matrix has GSL enabled, we install the `gsl` gem (which is not included in our Gemfile since it's optional). Lucky for us, GitHub already [includes libgsl as pre-installed software](https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-Readme.md#installed-apt-packages), so we don't need to do anything special for the apt package. Our gem already has everything needed to build & install. When `matrix.gsl` is false, we won't install the gem and tests will run the native Ruby implementation. When `matrix.gsl` is true, we'll install the gem tests will run the GSL implementation. Currently, GSL only works with Ruby 2.7. (One of the main reasons I want to add support for Numo is because GSL is becoming difficult to support.) As such, I've excluded other versions of ruby in our test matrix for now. They'll still be tested with GSL disabled, but not with it enabled. While working on this, I noticed some tests in the LSI spec that return early when `$GSL` is not enabled. It would be better for those tests to report as skipped when GSL is not enabled (and this matches the pattern of the redis tests, that report as skipped if redis isn't available).
1 parent 99d13af commit ccec8d8

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,38 @@ on:
1414

1515
jobs:
1616
ci:
17-
name: "Run Tests (${{ matrix.label }})"
17+
name: "Run Tests (Ruby ${{ matrix.ruby_version }}, GSL: ${{ matrix.gsl }})"
1818
runs-on: "ubuntu-latest"
1919
env:
2020
# See https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby#matrix-of-gemfiles
2121
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
2222
strategy:
2323
fail-fast: false
2424
matrix:
25+
ruby_version: ["2.7", "3.0", "3.1", "jruby-9.3.4.0"]
26+
gsl: [true, false]
27+
# We use `include` to assign the correct Gemfile for each ruby_version
2528
include:
26-
- label: Ruby 2.7
27-
ruby_version: "2.7"
29+
- ruby_version: "2.7"
2830
gemfile: Gemfile
29-
- label: Ruby 3.0
30-
ruby_version: "3.0"
31+
- ruby_version: "3.0"
3132
gemfile: Gemfile
32-
- label: Ruby 3.1
33-
ruby_version: "3.1"
33+
- ruby_version: "3.1"
3434
gemfile: Gemfile
35-
- label: JRuby 9.3.4.0
36-
ruby_version: "jruby-9.3.4.0"
35+
- ruby_version: "jruby-9.3.4.0"
3736
gemfile: Gemfile-jruby
37+
exclude:
38+
# Ruby 3.0 does not work with the latest released gsl gem
39+
# https://github.com/SciRuby/rb-gsl/issues/67
40+
- ruby_version: "3.0"
41+
gsl: true
42+
# Ruby 3.1 does not work with the latest released gsl gem
43+
# https://github.com/SciRuby/rb-gsl/issues/67
44+
- ruby_version: "3.1"
45+
gsl: true
46+
# jruby-9.3.4.0 doesn't easily build the gsl gem on a GitHub worker. Skipping for now.
47+
- ruby_version: "jruby-9.3.4.0"
48+
gsl: true
3849
steps:
3950
- name: Checkout Repository
4051
uses: actions/checkout@v3
@@ -43,8 +54,12 @@ jobs:
4354
with:
4455
ruby-version: ${{ matrix.ruby_version }}
4556
bundler-cache: true
57+
- name: Install GSL Gem
58+
if: ${{ matrix.gsl }}
59+
run: gem install gsl
4660
- name: Run Minitest based tests
4761
run: script/test
62+
4863
services:
4964
redis:
5065
image: redis

test/lsi/lsi_test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ def test_cached_content_node_option
163163
end
164164

165165
def test_clears_cached_content_node_cache
166-
return unless $GSL
166+
skip "transposed_search_vector is only used by GSL implementation" unless $GSL
167167

168168
lsi = ClassifierReborn::LSI.new(cache_node_vectors: true)
169169
lsi.add_item @str1, 'Dog'
@@ -192,7 +192,7 @@ def test_keyword_search
192192
end
193193

194194
def test_invalid_searching_when_using_gsl
195-
return unless $GSL
195+
skip "Only GSL currently raises invalid search error" unless $GSL
196196

197197
lsi = ClassifierReborn::LSI.new
198198
lsi.add_item @str1, 'Dog'

0 commit comments

Comments
 (0)