summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroshi SHIBATA <[email protected]>2025-01-09 13:27:56 +0900
committerHiroshi SHIBATA <[email protected]>2025-01-10 10:19:39 +0900
commit31855506232194ef15d0b8ed12370e4890f220b8 (patch)
tree1bf6809819c1d376bf5a5cadac366cbf8b1eb008
parent1089282acc3d3a284b092dcaa06fc241bceb4b02 (diff)
Make Pstore tests as optional
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12537
-rw-r--r--lib/cgi/session/pstore.rb7
-rw-r--r--test/cgi/test_cgi_session.rb2
-rw-r--r--test/psych/test_yamlstore.rb16
-rw-r--r--test/yaml/test_store.rb10
4 files changed, 23 insertions, 12 deletions
diff --git a/lib/cgi/session/pstore.rb b/lib/cgi/session/pstore.rb
index 45d0d8ae2c..6e3d10f075 100644
--- a/lib/cgi/session/pstore.rb
+++ b/lib/cgi/session/pstore.rb
@@ -11,7 +11,10 @@
# cgi/session.rb for more details on session storage managers.
require_relative '../session'
-require 'pstore'
+begin
+ require 'pstore'
+rescue LoadError
+end
class CGI
class Session
@@ -82,7 +85,7 @@ class CGI
File::unlink path
end
- end
+ end if defined?(::PStore)
end
end
# :enddoc:
diff --git a/test/cgi/test_cgi_session.rb b/test/cgi/test_cgi_session.rb
index b16b69766e..32b907d741 100644
--- a/test/cgi/test_cgi_session.rb
+++ b/test/cgi/test_cgi_session.rb
@@ -91,7 +91,7 @@ class CGISessionTest < Test::Unit::TestCase
assert_equal(value1,session["key1"])
assert_equal(value2,session["key2"])
session.close
- end
+ end if defined?(::PStore)
def test_cgi_session_specify_session_id
update_env(
'REQUEST_METHOD' => 'GET',
diff --git a/test/psych/test_yamlstore.rb b/test/psych/test_yamlstore.rb
index 1a1be3700e..c2721c41ea 100644
--- a/test/psych/test_yamlstore.rb
+++ b/test/psych/test_yamlstore.rb
@@ -23,14 +23,18 @@ module Psych
class YAMLStoreTest < TestCase
def setup
- @dir = Dir.mktmpdir("rubytest-file")
- File.chown(-1, Process.gid, @dir)
- @yamlstore_file = make_tmp_filename("yamlstore")
- @yamlstore = YAML::Store.new(@yamlstore_file)
+ if defined?(::PStore)
+ @dir = Dir.mktmpdir("rubytest-file")
+ File.chown(-1, Process.gid, @dir)
+ @yamlstore_file = make_tmp_filename("yamlstore")
+ @yamlstore = YAML::Store.new(@yamlstore_file)
+ else
+ omit "PStore is not available"
+ end
end
def teardown
- FileUtils.remove_entry_secure @dir
+ FileUtils.remove_entry_secure(@dir) if @dir
end
def make_tmp_filename(prefix)
@@ -97,5 +101,5 @@ module Psych
end
end
end
- end
+ end if defined?(::PStore)
end if defined?(Psych)
diff --git a/test/yaml/test_store.rb b/test/yaml/test_store.rb
index d389530271..6da8fabf9b 100644
--- a/test/yaml/test_store.rb
+++ b/test/yaml/test_store.rb
@@ -5,8 +5,12 @@ require 'tmpdir'
class YAMLStoreTest < Test::Unit::TestCase
def setup
- @yaml_store_file = File.join(Dir.tmpdir, "yaml_store.tmp.#{Process.pid}")
- @yaml_store = YAML::Store.new(@yaml_store_file)
+ if defined?(::PStore)
+ @yaml_store_file = File.join(Dir.tmpdir, "yaml_store.tmp.#{Process.pid}")
+ @yaml_store = YAML::Store.new(@yaml_store_file)
+ else
+ omit "PStore is not available"
+ end
end
def teardown
@@ -177,4 +181,4 @@ class YAMLStoreTest < Test::Unit::TestCase
end
assert_equal(indentation_3_yaml, File.read(@yaml_store_file), bug12800)
end
-end if defined?(::YAML::Store)
+end