diff --git a/test/helper.rb b/test/helper.rb index 9f159247..32ac8dd8 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -21,5 +21,9 @@ def i_am_running_in_valgrind # https://stackoverflow.com/questions/365458/how-can-i-detect-if-a-program-is-running-from-within-valgrind/62364698#62364698 ENV["LD_PRELOAD"] =~ /valgrind|vgpreload/ end + + def windows? + ::RUBY_PLATFORM =~ /mingw|mswin/ + end end end diff --git a/test/test_database_uri.rb b/test/test_database_uri.rb index 6c3dfe31..909c93c5 100644 --- a/test/test_database_uri.rb +++ b/test/test_database_uri.rb @@ -5,27 +5,39 @@ module SQLite3 class TestDatabaseURI < SQLite3::TestCase def test_open_absolute_file_uri + skip("windows uri paths are hard") if windows? + Tempfile.open "test.db" do |file| - assert SQLite3::Database.new("file:#{file.path}") + db = SQLite3::Database.new("file:#{file.path}") + assert db + db.close end end def test_open_relative_file_uri + skip("windows uri paths are hard") if windows? + Dir.mktmpdir do |dir| Dir.chdir dir do - assert SQLite3::Database.new("file:test.db") + db = SQLite3::Database.new("file:test.db") + assert db assert_path_exists "test.db" + db.close end end end def test_open_file_uri_readonly + skip("windows uri paths are hard") if windows? + Tempfile.open "test.db" do |file| db = SQLite3::Database.new("file:#{file.path}?mode=ro") assert_raise(SQLite3::ReadOnlyException) do db.execute("CREATE TABLE foos (id integer)") end + + db.close end end end