summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2024-10-25 12:35:29 +0200
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2024-10-26 18:44:15 +0900
commit73142755480e6a5e2d6307805dcc5d0dde02abbc (patch)
tree388b14cd08eec9d2c4b952199b87f16f14512cb3 /test
parenta3c21756e91167fb7acc09bd21c9b660d1aa3d30 (diff)
json_pure: fix ractor compatibility
This actually never worked, because the test was always testing the ext version from the stdlib, never the pure version nor the current ext version.
Diffstat (limited to 'test')
-rw-r--r--test/json/ractor_test.rb28
1 files changed, 19 insertions, 9 deletions
diff --git a/test/json/ractor_test.rb b/test/json/ractor_test.rb
index e0116400f8..f857c9a8bf 100644
--- a/test/json/ractor_test.rb
+++ b/test/json/ractor_test.rb
@@ -9,10 +9,7 @@ end
class JSONInRactorTest < Test::Unit::TestCase
def test_generate
- assert_separately([], "#{<<~"begin;"}\n#{<<~'end;'}", ignore_stderr: true)
- begin;
- $VERBOSE = nil
- require "json"
+ pid = fork do
r = Ractor.new do
json = JSON.generate({
'a' => 2,
@@ -26,9 +23,22 @@ class JSONInRactorTest < Test::Unit::TestCase
})
JSON.parse(json)
end
- expected_json = '{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
- '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}'
- assert_equal(JSON.parse(expected_json), r.take)
- end;
+ expected_json = JSON.parse('{"a":2,"b":3.141,"c":"c","d":[1,"b",3.14],"e":{"foo":"bar"},' +
+ '"g":"\\"\\u0000\\u001f","h":1000.0,"i":0.001}')
+ actual_json = r.take
+
+ if expected_json == actual_json
+ exit 0
+ else
+ puts "Expected:"
+ puts expected_json
+ puts "Acutual:"
+ puts actual_json
+ puts
+ exit 1
+ end
+ end
+ _, status = Process.waitpid2(pid)
+ assert_predicate status, :success?
end
-end if defined?(Ractor)
+end if defined?(Ractor) && Process.respond_to?(:fork)