Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 53 additions & 1 deletion test/duckdb_test/scalar_function_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def test_set_function
end

def test_register_scalar_function
skip 'Scalar functions with Ruby test' if Gem.win_platform?

Comment on lines 57 to +59
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

python - <<'PY'
from pathlib import Path
import re

text = Path("test/duckdb_test/scalar_function_test.rb").read_text()
pattern = re.compile(r'^\s*def\s+(test_[^\s(]+).*?(?=^\s*def\s+|\Z)', re.M | re.S)

for match in pattern.finditer(text):
    name = match.group(1)
    body = match.group(0)
    if ("set_function" in body or "register_scalar_function" in body) and "Gem.win_platform?" not in body:
        print(name)
PY

Repository: suketa/ruby-duckdb

Length of output: 144


🏁 Script executed:

cd test/duckdb_test && sed -n '1,100p' scalar_function_test.rb | cat -n

Repository: suketa/ruby-duckdb

Length of output: 3393


🏁 Script executed:

# Extract the two unguarded tests
cd test/duckdb_test && python3 - <<'PYEOF'
from pathlib import Path
import re

text = Path("scalar_function_test.rb").read_text()
lines = text.split('\n')

# Find line numbers for both tests
pattern = re.compile(r'^\s*def\s+(test_set_function|test_register_scalar_function_raises_error_without_single_thread)')
for i, line in enumerate(lines, 1):
    if pattern.search(line):
        print(f"Found '{pattern.search(line).group(1)}' at line {i}")

# Extract full test_set_function (should be around line 17)
print("\n=== test_set_function ===")
for i in range(16, 75):
    print(f"{i+1:3d} | {lines[i]}")

# Extract full test_register_scalar_function_raises_error_without_single_thread (should be around line 75)
print("\n=== test_register_scalar_function_raises_error_without_single_thread ===")
for i in range(74, 95):
    print(f"{i+1:3d} | {lines[i]}")
PYEOF

Repository: suketa/ruby-duckdb

Length of output: 3039


🏁 Script executed:

# Get the full content with line numbers for context
cd test/duckdb_test && wc -l scalar_function_test.rb

Repository: suketa/ruby-duckdb

Length of output: 89


🏁 Script executed:

# Let's look at lines around the two unguarded tests
cd test/duckdb_test && sed -n '17,100p' scalar_function_test.rb | cat -n

Repository: suketa/ruby-duckdb

Length of output: 3022


Add Windows skip to test_register_scalar_function_raises_error_without_single_thread.

This test at lines 75-88 calls @con.register_scalar_function(sf) and asserts the error message matches /single-threaded execution/ and /SET threads=1/. If Ruby callback registration is not supported on Windows, the error will be raised but with a different message, causing the assert_match assertions to fail. Add skip 'Scalar functions with Ruby test' if Gem.win_platform? to the beginning of this test to match the guard pattern used in test_register_scalar_function.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@test/duckdb_test/scalar_function_test.rb` around lines 57 - 59, The test
method test_register_scalar_function_raises_error_without_single_thread should
be skipped on Windows like test_register_scalar_function: add the same guard
line "skip 'Scalar functions with Ruby test' if Gem.win_platform?" at the start
of the test_register_scalar_function_raises_error_without_single_thread method
so the Ruby callback-registration error assertions (the calls to
`@con.register_scalar_function`(sf) and the assert_match checks for
/single-threaded execution/ and /SET threads=1/) are not run on Windows where
messages differ.

# Scalar functions with Ruby callbacks require single-threaded execution
@con.execute('SET threads=1')

Expand Down Expand Up @@ -117,6 +119,8 @@ def test_add_parameter_raises_error_for_invalid_argument
end

def test_scalar_function_with_one_parameter # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value INTEGER)')
@con.execute('INSERT INTO test_table VALUES (5), (10), (15)')
Expand All @@ -133,7 +137,9 @@ def test_scalar_function_with_one_parameter # rubocop:disable Metrics/MethodLeng
assert_equal [[10], [20], [30]], result.to_a
end

def test_scalar_function_with_two_parameters # rubocop:disable Metrics/MethodLength
def test_scalar_function_with_two_parameters # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (a INTEGER, b INTEGER)')
@con.execute('INSERT INTO test_table VALUES (5, 3), (10, 2), (15, 4)')
Expand All @@ -152,6 +158,8 @@ def test_scalar_function_with_two_parameters # rubocop:disable Metrics/MethodLen
end

def test_scalar_function_with_null_input # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value INTEGER)')
@con.execute('INSERT INTO test_table VALUES (5), (NULL), (15)')
Expand All @@ -169,6 +177,8 @@ def test_scalar_function_with_null_input # rubocop:disable Metrics/MethodLength
end

def test_scalar_function_bigint_return_type # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value BIGINT)')
@con.execute('INSERT INTO test_table VALUES (9223372036854775807)') # Max int64
Expand All @@ -186,6 +196,8 @@ def test_scalar_function_bigint_return_type # rubocop:disable Metrics/MethodLeng
end

def test_scalar_function_double_return_type # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value DOUBLE)')
@con.execute('INSERT INTO test_table VALUES (3.14159)')
Expand All @@ -203,6 +215,8 @@ def test_scalar_function_double_return_type # rubocop:disable Metrics/MethodLeng
end

def test_scalar_function_boolean_return_type # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value INTEGER)')
@con.execute('INSERT INTO test_table VALUES (5), (10), (15)')
Expand All @@ -220,6 +234,8 @@ def test_scalar_function_boolean_return_type # rubocop:disable Metrics/MethodLen
end

def test_scalar_function_float_return_type # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value FLOAT)')
@con.execute('INSERT INTO test_table VALUES (2.5)')
Expand All @@ -237,6 +253,8 @@ def test_scalar_function_float_return_type # rubocop:disable Metrics/MethodLengt
end

def test_scalar_function_varchar_return_type # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (name VARCHAR)')
@con.execute("INSERT INTO test_table VALUES ('Alice'), ('Bob')")
Expand All @@ -254,6 +272,8 @@ def test_scalar_function_varchar_return_type # rubocop:disable Metrics/MethodLen
end

def test_scalar_function_blob_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (data BLOB)')
@con.execute("INSERT INTO test_table VALUES ('\\x00\\x01\\x02\\x03'::BLOB), ('\\x00\\xAA\\xBB\\xCC'::BLOB)")
Expand All @@ -274,6 +294,8 @@ def test_scalar_function_blob_return_type # rubocop:disable Metrics/AbcSize, Met
end

def test_scalar_function_timestamp_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (ts TIMESTAMP)')
@con.execute("INSERT INTO test_table VALUES ('2024-01-15 10:30:00'), ('2024-12-25 23:59:59')")
Expand All @@ -294,6 +316,8 @@ def test_scalar_function_timestamp_return_type # rubocop:disable Metrics/AbcSize
end

def test_scalar_function_date_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (d DATE)')
@con.execute("INSERT INTO test_table VALUES ('2024-01-15'), ('2024-12-25')")
Expand All @@ -314,6 +338,8 @@ def test_scalar_function_date_return_type # rubocop:disable Metrics/AbcSize, Met
end

def test_scalar_function_time_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (t TIME)')
@con.execute("INSERT INTO test_table VALUES ('10:30:00'), ('23:59:59')")
Expand All @@ -338,6 +364,8 @@ def test_scalar_function_time_return_type # rubocop:disable Metrics/AbcSize, Met
end

def test_scalar_function_smallint_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value SMALLINT)')
@con.execute('INSERT INTO test_table VALUES (32767), (-32768), (1000)')
Expand All @@ -359,6 +387,8 @@ def test_scalar_function_smallint_return_type # rubocop:disable Metrics/AbcSize,
end

def test_scalar_function_tinyint_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value TINYINT)')
@con.execute('INSERT INTO test_table VALUES (100), (-50), (0)')
Expand All @@ -380,6 +410,8 @@ def test_scalar_function_tinyint_return_type # rubocop:disable Metrics/AbcSize,
end

def test_scalar_function_utinyint_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value UTINYINT)')
@con.execute('INSERT INTO test_table VALUES (255), (0), (100)')
Expand All @@ -402,6 +434,8 @@ def test_scalar_function_utinyint_return_type # rubocop:disable Metrics/AbcSize,
end

def test_scalar_function_usmallint_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value USMALLINT)')
@con.execute('INSERT INTO test_table VALUES (65535), (0), (1000)')
Expand All @@ -423,6 +457,8 @@ def test_scalar_function_usmallint_return_type # rubocop:disable Metrics/AbcSize
end

def test_scalar_function_uinteger_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value UINTEGER)')
@con.execute('INSERT INTO test_table VALUES (4294967200), (0), (1000000)')
Expand All @@ -444,6 +480,8 @@ def test_scalar_function_uinteger_return_type # rubocop:disable Metrics/AbcSize,
end

def test_scalar_function_ubigint_return_type # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Minitest/MultipleAssertions
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')
@con.execute('CREATE TABLE test_table (value UBIGINT)')
@con.execute('INSERT INTO test_table VALUES (9223372036854775807), (0), (1000000000)')
Expand All @@ -465,6 +503,8 @@ def test_scalar_function_ubigint_return_type # rubocop:disable Metrics/AbcSize,
end

def test_scalar_function_gc_safety # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')

# Register function and immediately lose reference
Expand Down Expand Up @@ -556,6 +596,8 @@ def test_gc_compaction_with_table_scan # rubocop:disable Metrics/AbcSize, Metric
# Tests for ScalarFunction.create class method

def test_create_with_single_parameter # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')

sf = DuckDB::ScalarFunction.create(
Expand All @@ -575,6 +617,8 @@ def test_create_with_single_parameter # rubocop:disable Metrics/MethodLength
end

def test_create_with_multiple_parameters # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')

sf = DuckDB::ScalarFunction.create(
Expand All @@ -594,6 +638,8 @@ def test_create_with_multiple_parameters # rubocop:disable Metrics/MethodLength
end

def test_create_with_no_parameters # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')

sf = DuckDB::ScalarFunction.create(
Expand Down Expand Up @@ -636,6 +682,8 @@ def test_create_rejects_both_parameter_type_and_parameter_types
end

def test_create_accepts_symbol_for_name
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')

sf = DuckDB::ScalarFunction.create(
Expand All @@ -651,6 +699,8 @@ def test_create_accepts_symbol_for_name
end

def test_create_accepts_string_for_name
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')

sf = DuckDB::ScalarFunction.create(
Expand All @@ -666,6 +716,8 @@ def test_create_accepts_string_for_name
end

def test_create_with_different_types # rubocop:disable Metrics/MethodLength
skip 'Scalar functions with Ruby test' if Gem.win_platform?

@con.execute('SET threads=1')

sf = DuckDB::ScalarFunction.create(
Expand Down
Loading