Skip to content

Commit 3d11076

Browse files
authored
Fix GitHub Actions and add tests for mutable strings (#256)
* Fix GitHub Actions * Disable tests with `musl` for arm64 because there's no `libv8-node` gem for aarch64-linux-musl at the moment * Fix tests on older Ruby versions by running `gem update --system` * Removes macOS 10.15 (it will be unsupported by 2022-08-30 anyway) * Adds macOS 12 to the matrix * Run TruffleRuby job on macOS as well * Use `ruby/setup-ruby` action where possible and update `actions/checkout` to v3 * Run tests for pull requests * Raise sleep duration in tests to fix CI failures on macOS * Add tests for mutable string arguments and return values
1 parent e0f5a7a commit 3d11076

File tree

2 files changed

+100
-53
lines changed

2 files changed

+100
-53
lines changed

.github/workflows/ci.yml

Lines changed: 63 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,92 @@
1-
name: Test
1+
name: Tests
2+
23
on:
3-
- push
4+
pull_request:
5+
push:
6+
branches:
7+
- master
48

59
jobs:
610
test-truffleruby:
7-
name: Test TruffleRuby
8-
runs-on: ubuntu-20.04
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
os:
15+
- "macos-11"
16+
- "macos-12"
17+
- "ubuntu-20.04"
18+
ruby:
19+
- "truffleruby+graalvm-head"
20+
21+
name: ${{ matrix.os }} - ${{ matrix.ruby }}
22+
runs-on: ${{ matrix.os }}
23+
924
env:
1025
TRUFFLERUBYOPT: "--jvm --polyglot"
26+
1127
steps:
12-
- name: Checkout
13-
uses: actions/checkout@v2
14-
- name: Setup Ruby
15-
uses: ruby/setup-ruby@v1
28+
- uses: actions/checkout@v3
29+
- uses: ruby/setup-ruby@v1
1630
with:
17-
ruby-version: truffleruby+graalvm-head
18-
- name: Install GraalVM js component
19-
run: if ! gu list | grep '^js '; then gu install js; fi
20-
- name: Bundle
21-
run: bundle install
31+
ruby-version: ${{ matrix.ruby }}
32+
bundler-cache: true
33+
- name: Install GraalVM JS component
34+
run: gu install js
2235
- name: Compile
2336
run: bundle exec rake compile
2437
- name: Test
2538
run: bundle exec rake test
39+
2640
test-darwin:
2741
strategy:
2842
fail-fast: false
2943
matrix:
3044
os:
31-
- '10.15'
32-
- '11.0'
33-
platform:
34-
- x86_64
35-
# arm64
36-
name: Test (darwin)
37-
runs-on: macos-${{ matrix.os }}
45+
- "macos-11"
46+
- "macos-12"
47+
ruby:
48+
- "ruby-2.6"
49+
- "ruby-2.7"
50+
- "ruby-3.0"
51+
- "ruby-3.1"
52+
53+
name: ${{ matrix.os }} - ${{ matrix.ruby }}
54+
runs-on: ${{ matrix.os }}
55+
3856
steps:
39-
- name: Checkout
40-
uses: actions/checkout@v2
41-
- name: Bundle
42-
run: bundle install
57+
- uses: actions/checkout@v3
58+
- uses: ruby/setup-ruby@v1
59+
with:
60+
ruby-version: ${{ matrix.ruby }}
61+
bundler-cache: true
4362
- name: Compile
4463
run: bundle exec rake compile
4564
- name: Test
4665
run: bundle exec rake test
66+
4767
test-linux:
4868
strategy:
4969
fail-fast: false
5070
matrix:
5171
ruby:
52-
- '2.6'
53-
- '2.7'
54-
- '3.0'
55-
- '3.1'
72+
- "2.6"
73+
- "2.7"
74+
- "3.0"
75+
- "3.1"
5676
platform:
57-
- amd64
58-
- arm64
59-
# arm
60-
# ppc64le
61-
# s390x
77+
- "amd64"
78+
- "arm64"
6279
libc:
63-
- gnu
64-
- musl
65-
name: Test (linux)
80+
- "gnu"
81+
- "musl"
82+
exclude:
83+
# there's no libv8-node (v16) for aarch64-linux-musl at the moment
84+
- platform: "arm64"
85+
libc: "musl"
86+
87+
name: linux-${{ matrix.platform }} - ruby-${{ matrix.ruby }} - ${{ matrix.libc }}
6688
runs-on: ubuntu-20.04
89+
6790
steps:
6891
- name: Enable ${{ matrix.platform }} platform
6992
id: qemu
@@ -88,9 +111,11 @@ jobs:
88111
echo "::set-output name=id::$(cat container_id)"
89112
- name: Install Alpine system dependencies
90113
if: ${{ matrix.libc == 'musl' }}
91-
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base linux-headers bash python2 python3 git curl tar clang binutils-gold
114+
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} apk add --no-cache build-base bash git
92115
- name: Checkout
93-
uses: actions/checkout@v2
116+
uses: actions/checkout@v3
117+
- name: Update Rubygems
118+
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} gem update --system
94119
- name: Bundle
95120
run: docker exec -w "${PWD}" ${{ steps.container.outputs.id }} bundle install
96121
- name: Compile

test/mini_racer_test.rb

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ class MiniRacerTest < Minitest::Test
88
# see `test_platform_set_flags_works` below
99
MiniRacer::Platform.set_flags! :use_strict
1010

11-
1211
def test_locale
1312
skip "TruffleRuby does not have all js timezone by default" if RUBY_ENGINE == "truffleruby"
1413
val = MiniRacer::Context.new.eval("new Date('April 28 2021').toLocaleDateString('es-MX');")
@@ -439,7 +438,7 @@ def test_an_empty_snapshot_is_valid
439438
end
440439

441440
def test_snapshots_can_be_warmed_up_with_no_side_effects
442-
# shamelessly insipired by https://github.com/v8/v8/blob/5.3.254/test/cctest/test-serialize.cc#L792-L854
441+
# shamelessly inspired by https://github.com/v8/v8/blob/5.3.254/test/cctest/test-serialize.cc#L792-L854
443442
snapshot_source = <<-JS
444443
function f() { return Math.sin(1); }
445444
var a = 5;
@@ -649,7 +648,7 @@ def test_function_rval
649648

650649
def test_timeout_in_ruby_land
651650
context = MiniRacer::Context.new(timeout: 50)
652-
context.attach('sleep', proc{ sleep 0.1 })
651+
context.attach('sleep', proc{ sleep 0.5 })
653652
assert_raises(MiniRacer::ScriptTerminatedError) do
654653
context.eval('sleep(); "hi";')
655654
end
@@ -759,7 +758,7 @@ def test_ensure_gc
759758

760759
context.eval("'#{"x" * 10_000_000}'")
761760

762-
sleep 0.005
761+
sleep 0.01
763762

764763
end_heap = context.heap_stats[:used_heap_size]
765764

@@ -906,7 +905,7 @@ def test_infinite_object_js
906905
skip "TruffleRuby does not yet implement marshal_stack_depth" if RUBY_ENGINE == "truffleruby"
907906
context = MiniRacer::Context.new(marshal_stack_depth: 5)
908907
context.attach("a", proc{|a| a})
909-
908+
910909
js = <<~JS
911910
var d=0;
912911
function get(z) {
@@ -985,16 +984,16 @@ def test_webassembly
985984
context.attach("print", proc {|f| puts f})
986985

987986
context.eval <<~JS
988-
WebAssembly
989-
.instantiate(new Uint8Array(loadwasm()), {
990-
wasi_snapshot_preview1: {
991-
proc_exit: function() { print("exit"); },
992-
args_get: function() { return 0 },
993-
args_sizes_get: function() { return 0 }
994-
}
995-
})
996-
.then(i => { instance = i["instance"];})
997-
.catch(e => print(e.toString()));
987+
WebAssembly
988+
.instantiate(new Uint8Array(loadwasm()), {
989+
wasi_snapshot_preview1: {
990+
proc_exit: function() { print("exit"); },
991+
args_get: function() { return 0 },
992+
args_sizes_get: function() { return 0 }
993+
}
994+
})
995+
.then(i => { instance = i["instance"];})
996+
.catch(e => print(e.toString()));
998997
JS
999998

1000999
while !context.eval("instance") do
@@ -1034,4 +1033,27 @@ def test_timeout
10341033
JS
10351034
end
10361035
end
1036+
1037+
def test_eval_returns_unfrozen_string
1038+
context = MiniRacer::Context.new
1039+
result = context.eval("'Hello George!'")
1040+
assert_equal("Hello George!", result)
1041+
assert_equal(false, result.frozen?)
1042+
end
1043+
1044+
def test_call_returns_unfrozen_string
1045+
context = MiniRacer::Context.new
1046+
context.eval('function hello(name) { return "Hello " + name + "!" }')
1047+
result = context.call('hello', 'George')
1048+
assert_equal("Hello George!", result)
1049+
assert_equal(false, result.frozen?)
1050+
end
1051+
1052+
def test_callback_string_arguments_are_not_frozen
1053+
context = MiniRacer::Context.new
1054+
context.attach("test", proc{ |text| text.frozen? })
1055+
1056+
frozen = context.eval("test('Hello George!')")
1057+
assert_equal(false, frozen)
1058+
end
10371059
end

0 commit comments

Comments
 (0)