This commit is contained in:
Andrew Konchin 2024-06-07 19:01:53 +03:00 committed by Benoit Daloze
parent e8bd745c17
commit 3ebab4b64d
12 changed files with 1238 additions and 1268 deletions

View File

@ -1,7 +1,7 @@
inherit_from: .rubocop_todo.yml inherit_from: .rubocop_todo.yml
AllCops: AllCops:
TargetRubyVersion: 3.0 TargetRubyVersion: 3.1
DisplayCopNames: true DisplayCopNames: true
Exclude: Exclude:
- command_line/fixtures/bad_syntax.rb - command_line/fixtures/bad_syntax.rb

View File

@ -56,23 +56,20 @@ module ArraySpecs
101.621, 102.816, 104.010, 105.202, 106.393, 107.583, 108.771, 109.958, 111.144, 112.329, 101.621, 102.816, 104.010, 105.202, 106.393, 107.583, 108.771, 109.958, 111.144, 112.329,
113.512, 114.695, 115.876, 117.057, 118.236, 119.414, 120.591, 121.767, 122.942, 124.116, 113.512, 114.695, 115.876, 117.057, 118.236, 119.414, 120.591, 121.767, 122.942, 124.116,
125.289, 126.462, 127.633, 128.803, 129.973, 131.141, 132.309, 133.476, 134.642, 135.807, 125.289, 126.462, 127.633, 128.803, 129.973, 131.141, 132.309, 133.476, 134.642, 135.807,
] ]
def self.measure_sample_fairness(size, samples, iters) def self.measure_sample_fairness(size, samples, iters)
ary = Array.new(size) { |x| x } ary = Array.new(size) { |x| x }
expected = iters.fdiv size
(samples).times do |i| (samples).times do |i|
chi_results = [] chi_results = []
3.times do 3.times do
counts = Array.new(size) { 0 } counts = Array.new(size, 0)
expected = iters / size
iters.times do iters.times do
x = ary.sample(samples)[i] x = ary.sample(samples)[i]
counts[x] += 1 counts[x] += 1
end end
chi_squared = 0.0 chi_squared = counts.sum {|count| (count - expected) ** 2} / expected
counts.each do |count|
chi_squared += (((count - expected) ** 2) * 1.0 / expected)
end
chi_results << chi_squared chi_results << chi_squared
break if chi_squared <= CHI_SQUARED_CRITICAL_VALUES[size] break if chi_squared <= CHI_SQUARED_CRITICAL_VALUES[size]
end end
@ -83,17 +80,14 @@ module ArraySpecs
def self.measure_sample_fairness_large_sample_size(size, samples, iters) def self.measure_sample_fairness_large_sample_size(size, samples, iters)
ary = Array.new(size) { |x| x } ary = Array.new(size) { |x| x }
counts = Array.new(size) { 0 } counts = Array.new(size, 0)
expected = iters * samples / size expected = (iters * samples).fdiv size
iters.times do iters.times do
ary.sample(samples).each do |sample| ary.sample(samples).each do |sample|
counts[sample] += 1 counts[sample] += 1
end end
end end
chi_squared = 0.0 chi_squared = counts.sum {|count| (count - expected) ** 2} / expected
counts.each do |count|
chi_squared += (((count - expected) ** 2) * 1.0 / expected)
end
# Chi squared critical values for tests with 4 degrees of freedom # Chi squared critical values for tests with 4 degrees of freedom
# Values obtained from NIST Engineering Statistic Handbook at # Values obtained from NIST Engineering Statistic Handbook at
@ -223,366 +217,370 @@ module ArraySpecs
obj obj
end end
LargeArray = ["test_create_table_with_force_true_does_not_drop_nonexisting_table", LargeArray = [
"test_add_table", "test_create_table_with_force_true_does_not_drop_nonexisting_table",
"assert_difference", "test_add_table",
"assert_operator", "assert_difference",
"instance_variables", "assert_operator",
"class", "instance_variables",
"instance_variable_get", "class",
"__class__", "instance_variable_get",
"expects", "__class__",
"assert_no_difference", "expects",
"name", "assert_no_difference",
"assert_blank", "name",
"assert_not_same", "assert_blank",
"is_a?", "assert_not_same",
"test_add_table_with_decimals", "is_a?",
"test_create_table_with_timestamps_should_create_datetime_columns", "test_add_table_with_decimals",
"assert_present", "test_create_table_with_timestamps_should_create_datetime_columns",
"assert_no_match", "assert_present",
"__instance_of__", "assert_no_match",
"assert_deprecated", "__instance_of__",
"assert", "assert_deprecated",
"assert_throws", "assert",
"kind_of?", "assert_throws",
"try", "kind_of?",
"__instance_variable_get__", "try",
"object_id", "__instance_variable_get__",
"timeout", "object_id",
"instance_variable_set", "timeout",
"assert_nothing_thrown", "instance_variable_set",
"__instance_variable_set__", "assert_nothing_thrown",
"copy_object", "__instance_variable_set__",
"test_create_table_with_timestamps_should_create_datetime_columns_with_options", "copy_object",
"assert_not_deprecated", "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
"assert_in_delta", "assert_not_deprecated",
"id", "assert_in_delta",
"copy_metaclass", "id",
"test_create_table_without_a_block", "copy_metaclass",
"dup", "test_create_table_without_a_block",
"assert_not_nil", "dup",
"send", "assert_not_nil",
"__instance_variables__", "send",
"to_sql", "__instance_variables__",
"mock", "to_sql",
"assert_send", "mock",
"instance_variable_defined?", "assert_send",
"clone", "instance_variable_defined?",
"require", "clone",
"test_migrator", "require",
"__instance_variable_defined_eh__", "test_migrator",
"frozen?", "__instance_variable_defined_eh__",
"test_add_column_not_null_with_default", "frozen?",
"freeze", "test_add_column_not_null_with_default",
"test_migrator_one_up", "freeze",
"test_migrator_one_down", "test_migrator_one_up",
"singleton_methods", "test_migrator_one_down",
"method_exists?", "singleton_methods",
"create_fixtures", "method_exists?",
"test_migrator_one_up_one_down", "create_fixtures",
"test_native_decimal_insert_manual_vs_automatic", "test_migrator_one_up_one_down",
"instance_exec", "test_native_decimal_insert_manual_vs_automatic",
"__is_a__", "instance_exec",
"test_migrator_double_up", "__is_a__",
"stub", "test_migrator_double_up",
"private_methods", "stub",
"stubs", "private_methods",
"test_migrator_double_down", "stubs",
"fixture_path", "test_migrator_double_down",
"private_singleton_methods", "fixture_path",
"stub_everything", "private_singleton_methods",
"test_migrator_one_up_with_exception_and_rollback", "stub_everything",
"sequence", "test_migrator_one_up_with_exception_and_rollback",
"protected_methods", "sequence",
"enum_for", "protected_methods",
"test_finds_migrations", "enum_for",
"run_before_mocha", "test_finds_migrations",
"states", "run_before_mocha",
"protected_singleton_methods", "states",
"to_json", "protected_singleton_methods",
"instance_values", "to_json",
"==", "instance_values",
"mocha_setup", "==",
"public_methods", "mocha_setup",
"test_finds_pending_migrations", "public_methods",
"mocha_verify", "test_finds_pending_migrations",
"assert_kind_of", "mocha_verify",
"===", "assert_kind_of",
"=~", "===",
"test_relative_migrations", "=~",
"mocha_teardown", "test_relative_migrations",
"gem", "mocha_teardown",
"mocha", "gem",
"test_only_loads_pending_migrations", "mocha",
"test_add_column_with_precision_and_scale", "test_only_loads_pending_migrations",
"require_or_load", "test_add_column_with_precision_and_scale",
"eql?", "require_or_load",
"require_dependency", "eql?",
"test_native_types", "require_dependency",
"test_target_version_zero_should_run_only_once", "test_native_types",
"extend", "test_target_version_zero_should_run_only_once",
"to_matcher", "extend",
"unloadable", "to_matcher",
"require_association", "unloadable",
"hash", "require_association",
"__id__", "hash",
"load_dependency", "__id__",
"equals", "load_dependency",
"test_migrator_db_has_no_schema_migrations_table", "equals",
"test_migrator_verbosity", "test_migrator_db_has_no_schema_migrations_table",
"kind_of", "test_migrator_verbosity",
"to_yaml", "kind_of",
"to_bool", "to_yaml",
"test_migrator_verbosity_off", "to_bool",
"taint", "test_migrator_verbosity_off",
"test_migrator_going_down_due_to_version_target", "taint",
"tainted?", "test_migrator_going_down_due_to_version_target",
"mocha_inspect", "tainted?",
"test_migrator_rollback", "mocha_inspect",
"vim", "test_migrator_rollback",
"untaint", "vim",
"taguri=", "untaint",
"test_migrator_forward", "taguri=",
"test_schema_migrations_table_name", "test_migrator_forward",
"test_proper_table_name", "test_schema_migrations_table_name",
"all_of", "test_proper_table_name",
"test_add_drop_table_with_prefix_and_suffix", "all_of",
"_setup_callbacks", "test_add_drop_table_with_prefix_and_suffix",
"setup", "_setup_callbacks",
"Not", "setup",
"test_create_table_with_binary_column", "Not",
"assert_not_equal", "test_create_table_with_binary_column",
"enable_warnings", "assert_not_equal",
"acts_like?", "enable_warnings",
"Rational", "acts_like?",
"_removed_setup_callbacks", "Rational",
"Table", "_removed_setup_callbacks",
"bind", "Table",
"any_of", "bind",
"__method__", "any_of",
"test_migrator_with_duplicates", "__method__",
"_teardown_callbacks", "test_migrator_with_duplicates",
"method", "_teardown_callbacks",
"test_migrator_with_duplicate_names", "method",
"_removed_teardown_callbacks", "test_migrator_with_duplicate_names",
"any_parameters", "_removed_teardown_callbacks",
"test_migrator_with_missing_version_numbers", "any_parameters",
"test_add_remove_single_field_using_string_arguments", "test_migrator_with_missing_version_numbers",
"test_create_table_with_custom_sequence_name", "test_add_remove_single_field_using_string_arguments",
"test_add_remove_single_field_using_symbol_arguments", "test_create_table_with_custom_sequence_name",
"_one_time_conditions_valid_14?", "test_add_remove_single_field_using_symbol_arguments",
"_one_time_conditions_valid_16?", "_one_time_conditions_valid_14?",
"run_callbacks", "_one_time_conditions_valid_16?",
"anything", "run_callbacks",
"silence_warnings", "anything",
"instance_variable_names", "silence_warnings",
"_fixture_path", "instance_variable_names",
"copy_instance_variables_from", "_fixture_path",
"fixture_path?", "copy_instance_variables_from",
"has_entry", "fixture_path?",
"__marshal__", "has_entry",
"_fixture_table_names", "__marshal__",
"__kind_of__", "_fixture_table_names",
"fixture_table_names?", "__kind_of__",
"test_add_rename", "fixture_table_names?",
"assert_equal", "test_add_rename",
"_fixture_class_names", "assert_equal",
"fixture_class_names?", "_fixture_class_names",
"has_entries", "fixture_class_names?",
"_use_transactional_fixtures", "has_entries",
"people", "_use_transactional_fixtures",
"test_rename_column_using_symbol_arguments", "people",
"use_transactional_fixtures?", "test_rename_column_using_symbol_arguments",
"instance_eval", "use_transactional_fixtures?",
"blank?", "instance_eval",
"with_warnings", "blank?",
"__nil__", "with_warnings",
"load", "__nil__",
"metaclass", "load",
"_use_instantiated_fixtures", "metaclass",
"has_key", "_use_instantiated_fixtures",
"class_eval", "has_key",
"present?", "class_eval",
"test_rename_column", "present?",
"teardown", "test_rename_column",
"use_instantiated_fixtures?", "teardown",
"method_name", "use_instantiated_fixtures?",
"silence_stderr", "method_name",
"presence", "silence_stderr",
"test_rename_column_preserves_default_value_not_null", "presence",
"silence_stream", "test_rename_column_preserves_default_value_not_null",
"_pre_loaded_fixtures", "silence_stream",
"__metaclass__", "_pre_loaded_fixtures",
"__fixnum__", "__metaclass__",
"pre_loaded_fixtures?", "__fixnum__",
"has_value", "pre_loaded_fixtures?",
"suppress", "has_value",
"to_yaml_properties", "suppress",
"test_rename_nonexistent_column", "to_yaml_properties",
"test_add_index", "test_rename_nonexistent_column",
"includes", "test_add_index",
"find_correlate_in", "includes",
"equality_predicate_sql", "find_correlate_in",
"assert_nothing_raised", "equality_predicate_sql",
"let", "assert_nothing_raised",
"not_predicate_sql", "let",
"test_rename_column_with_sql_reserved_word", "not_predicate_sql",
"singleton_class", "test_rename_column_with_sql_reserved_word",
"test_rename_column_with_an_index", "singleton_class",
"display", "test_rename_column_with_an_index",
"taguri", "display",
"to_yaml_style", "taguri",
"test_remove_column_with_index", "to_yaml_style",
"size", "test_remove_column_with_index",
"current_adapter?", "size",
"test_remove_column_with_multi_column_index", "current_adapter?",
"respond_to?", "test_remove_column_with_multi_column_index",
"test_change_type_of_not_null_column", "respond_to?",
"is_a", "test_change_type_of_not_null_column",
"to_a", "is_a",
"test_rename_table_for_sqlite_should_work_with_reserved_words", "to_a",
"require_library_or_gem", "test_rename_table_for_sqlite_should_work_with_reserved_words",
"setup_fixtures", "require_library_or_gem",
"equal?", "setup_fixtures",
"teardown_fixtures", "equal?",
"nil?", "teardown_fixtures",
"fixture_table_names", "nil?",
"fixture_class_names", "fixture_table_names",
"test_create_table_without_id", "fixture_class_names",
"use_transactional_fixtures", "test_create_table_without_id",
"test_add_column_with_primary_key_attribute", "use_transactional_fixtures",
"repair_validations", "test_add_column_with_primary_key_attribute",
"use_instantiated_fixtures", "repair_validations",
"instance_of?", "use_instantiated_fixtures",
"test_create_table_adds_id", "instance_of?",
"test_rename_table", "test_create_table_adds_id",
"pre_loaded_fixtures", "test_rename_table",
"to_enum", "pre_loaded_fixtures",
"test_create_table_with_not_null_column", "to_enum",
"instance_of", "test_create_table_with_not_null_column",
"test_change_column_nullability", "instance_of",
"optionally", "test_change_column_nullability",
"test_rename_table_with_an_index", "optionally",
"run", "test_rename_table_with_an_index",
"test_change_column", "run",
"default_test", "test_change_column",
"assert_raise", "default_test",
"test_create_table_with_defaults", "assert_raise",
"assert_nil", "test_create_table_with_defaults",
"flunk", "assert_nil",
"regexp_matches", "flunk",
"duplicable?", "regexp_matches",
"reset_mocha", "duplicable?",
"stubba_method", "reset_mocha",
"filter_backtrace", "stubba_method",
"test_create_table_with_limits", "filter_backtrace",
"responds_with", "test_create_table_with_limits",
"stubba_object", "responds_with",
"test_change_column_with_nil_default", "stubba_object",
"assert_block", "test_change_column_with_nil_default",
"__show__", "assert_block",
"assert_date_from_db", "__show__",
"__respond_to_eh__", "assert_date_from_db",
"run_in_transaction?", "__respond_to_eh__",
"inspect", "run_in_transaction?",
"assert_sql", "inspect",
"test_change_column_with_new_default", "assert_sql",
"yaml_equivalent", "test_change_column_with_new_default",
"build_message", "yaml_equivalent",
"to_s", "build_message",
"test_change_column_default", "to_s",
"assert_queries", "test_change_column_default",
"pending", "assert_queries",
"as_json", "pending",
"assert_no_queries", "as_json",
"test_change_column_quotes_column_names", "assert_no_queries",
"assert_match", "test_change_column_quotes_column_names",
"test_keeping_default_and_notnull_constraint_on_change", "assert_match",
"methods", "test_keeping_default_and_notnull_constraint_on_change",
"connection_allow_concurrency_setup", "methods",
"connection_allow_concurrency_teardown", "connection_allow_concurrency_setup",
"test_create_table_with_primary_key_prefix_as_table_name_with_underscore", "connection_allow_concurrency_teardown",
"__send__", "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
"make_connection", "__send__",
"assert_raises", "make_connection",
"tap", "assert_raises",
"with_kcode", "tap",
"assert_instance_of", "with_kcode",
"test_create_table_with_primary_key_prefix_as_table_name", "assert_instance_of",
"assert_respond_to", "test_create_table_with_primary_key_prefix_as_table_name",
"test_change_column_default_to_null", "assert_respond_to",
"assert_same", "test_change_column_default_to_null",
"__extend__"] "assert_same",
"__extend__",
]
LargeTestArraySorted = ["test_add_column_not_null_with_default", LargeTestArraySorted = [
"test_add_column_with_precision_and_scale", "test_add_column_not_null_with_default",
"test_add_column_with_primary_key_attribute", "test_add_column_with_precision_and_scale",
"test_add_drop_table_with_prefix_and_suffix", "test_add_column_with_primary_key_attribute",
"test_add_index", "test_add_drop_table_with_prefix_and_suffix",
"test_add_remove_single_field_using_string_arguments", "test_add_index",
"test_add_remove_single_field_using_symbol_arguments", "test_add_remove_single_field_using_string_arguments",
"test_add_rename", "test_add_remove_single_field_using_symbol_arguments",
"test_add_table", "test_add_rename",
"test_add_table_with_decimals", "test_add_table",
"test_change_column", "test_add_table_with_decimals",
"test_change_column_default", "test_change_column",
"test_change_column_default_to_null", "test_change_column_default",
"test_change_column_nullability", "test_change_column_default_to_null",
"test_change_column_quotes_column_names", "test_change_column_nullability",
"test_change_column_with_new_default", "test_change_column_quotes_column_names",
"test_change_column_with_nil_default", "test_change_column_with_new_default",
"test_change_type_of_not_null_column", "test_change_column_with_nil_default",
"test_create_table_adds_id", "test_change_type_of_not_null_column",
"test_create_table_with_binary_column", "test_create_table_adds_id",
"test_create_table_with_custom_sequence_name", "test_create_table_with_binary_column",
"test_create_table_with_defaults", "test_create_table_with_custom_sequence_name",
"test_create_table_with_force_true_does_not_drop_nonexisting_table", "test_create_table_with_defaults",
"test_create_table_with_limits", "test_create_table_with_force_true_does_not_drop_nonexisting_table",
"test_create_table_with_not_null_column", "test_create_table_with_limits",
"test_create_table_with_primary_key_prefix_as_table_name", "test_create_table_with_not_null_column",
"test_create_table_with_primary_key_prefix_as_table_name_with_underscore", "test_create_table_with_primary_key_prefix_as_table_name",
"test_create_table_with_timestamps_should_create_datetime_columns", "test_create_table_with_primary_key_prefix_as_table_name_with_underscore",
"test_create_table_with_timestamps_should_create_datetime_columns_with_options", "test_create_table_with_timestamps_should_create_datetime_columns",
"test_create_table_without_a_block", "test_create_table_with_timestamps_should_create_datetime_columns_with_options",
"test_create_table_without_id", "test_create_table_without_a_block",
"test_finds_migrations", "test_create_table_without_id",
"test_finds_pending_migrations", "test_finds_migrations",
"test_keeping_default_and_notnull_constraint_on_change", "test_finds_pending_migrations",
"test_migrator", "test_keeping_default_and_notnull_constraint_on_change",
"test_migrator_db_has_no_schema_migrations_table", "test_migrator",
"test_migrator_double_down", "test_migrator_db_has_no_schema_migrations_table",
"test_migrator_double_up", "test_migrator_double_down",
"test_migrator_forward", "test_migrator_double_up",
"test_migrator_going_down_due_to_version_target", "test_migrator_forward",
"test_migrator_one_down", "test_migrator_going_down_due_to_version_target",
"test_migrator_one_up", "test_migrator_one_down",
"test_migrator_one_up_one_down", "test_migrator_one_up",
"test_migrator_one_up_with_exception_and_rollback", "test_migrator_one_up_one_down",
"test_migrator_rollback", "test_migrator_one_up_with_exception_and_rollback",
"test_migrator_verbosity", "test_migrator_rollback",
"test_migrator_verbosity_off", "test_migrator_verbosity",
"test_migrator_with_duplicate_names", "test_migrator_verbosity_off",
"test_migrator_with_duplicates", "test_migrator_with_duplicate_names",
"test_migrator_with_missing_version_numbers", "test_migrator_with_duplicates",
"test_native_decimal_insert_manual_vs_automatic", "test_migrator_with_missing_version_numbers",
"test_native_types", "test_native_decimal_insert_manual_vs_automatic",
"test_only_loads_pending_migrations", "test_native_types",
"test_proper_table_name", "test_only_loads_pending_migrations",
"test_relative_migrations", "test_proper_table_name",
"test_remove_column_with_index", "test_relative_migrations",
"test_remove_column_with_multi_column_index", "test_remove_column_with_index",
"test_rename_column", "test_remove_column_with_multi_column_index",
"test_rename_column_preserves_default_value_not_null", "test_rename_column",
"test_rename_column_using_symbol_arguments", "test_rename_column_preserves_default_value_not_null",
"test_rename_column_with_an_index", "test_rename_column_using_symbol_arguments",
"test_rename_column_with_sql_reserved_word", "test_rename_column_with_an_index",
"test_rename_nonexistent_column", "test_rename_column_with_sql_reserved_word",
"test_rename_table", "test_rename_nonexistent_column",
"test_rename_table_for_sqlite_should_work_with_reserved_words", "test_rename_table",
"test_rename_table_with_an_index", "test_rename_table_for_sqlite_should_work_with_reserved_words",
"test_schema_migrations_table_name", "test_rename_table_with_an_index",
"test_target_version_zero_should_run_only_once"] "test_schema_migrations_table_name",
"test_target_version_zero_should_run_only_once",
]
class PrivateToAry class PrivateToAry
private private

View File

@ -28,6 +28,16 @@ describe "Array#pack with :buffer option" do
TypeError, "buffer must be String, not Array") TypeError, "buffer must be String, not Array")
end end
it "raise FrozenError if buffer is frozen" do
-> { [65].pack("c", buffer: "frozen-string".freeze) }.should raise_error(FrozenError)
end
it "preserves the encoding of the given buffer" do
buffer = ''.encode(Encoding::ISO_8859_1)
[65, 66, 67].pack("ccc", buffer: buffer)
buffer.encoding.should == Encoding::ISO_8859_1
end
context "offset (@) is specified" do context "offset (@) is specified" do
it 'keeps buffer content if it is longer than offset' do it 'keeps buffer content if it is longer than offset' do
n = [ 65, 66, 67 ] n = [ 65, 66, 67 ]

View File

@ -1,12 +1,12 @@
module IOWaitSpec module IOSpec
def self.exhaust_write_buffer(io) def self.exhaust_write_buffer(io)
written = 0 written = 0
buf = " " * 4096 buf = " " * 4096
begin while true
written += io.write_nonblock(buf) written += io.write_nonblock(buf)
rescue Errno::EAGAIN, Errno::EWOULDBLOCK end
return written rescue Errno::EAGAIN, Errno::EWOULDBLOCK
end while true written
end end
end end

View File

@ -427,7 +427,7 @@ describe "The 'case'-construct" do
:bar :bar
end end
RUBY RUBY
}.should complain(/warning: duplicated .when' clause with line \d+ is ignored/, verbose: true) }.should complain(/warning: (duplicated .when' clause with line \d+ is ignored|'when' clause on line \d+ duplicates 'when' clause on line \d+ and is ignored)/, verbose: true)
end end
end end

View File

@ -0,0 +1,75 @@
describe "Pattern matching" do
before :each do
ScratchPad.record []
end
describe "Ruby 3.1 improvements" do
ruby_version_is "3.1" do
it "can omit parentheses in one line pattern matching" do
[1, 2] => a, b
[a, b].should == [1, 2]
{a: 1} => a:
a.should == 1
end
it "supports pinning instance variables" do
@a = /a/
case 'abc'
in ^@a
true
end.should == true
end
it "supports pinning class variables" do
result = nil
Module.new do
result = module_eval(<<~RUBY)
@@a = 0..10
case 2
in ^@@a
true
end
RUBY
end
result.should == true
end
it "supports pinning global variables" do
$a = /a/
case 'abc'
in ^$a
true
end.should == true
end
it "supports pinning expressions" do
case 'abc'
in ^(/a/)
true
end.should == true
case 0
in ^(0 + 0)
true
end.should == true
end
it "supports pinning expressions in array pattern" do
case [3]
in [^(1 + 2)]
true
end.should == true
end
it "supports pinning expressions in hash pattern" do
case {name: '2.6', released_at: Time.new(2018, 12, 25)}
in {released_at: ^(Time.new(2010)..Time.new(2020))}
true
end.should == true
end
end
end
end

File diff suppressed because it is too large Load Diff

View File

@ -24,4 +24,23 @@ describe "IO#wait_readable" do
it "waits for the IO to become readable with the given large timeout" do it "waits for the IO to become readable with the given large timeout" do
@io.wait_readable(365 * 24 * 60 * 60).should == @io @io.wait_readable(365 * 24 * 60 * 60).should == @io
end end
it "can be interrupted" do
rd, wr = IO.pipe
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
rd.wait_readable(10)
end
Thread.pass until t.stop?
t.kill
t.join
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
ensure
rd.close
wr.close
end
end end

View File

@ -1,5 +1,5 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative 'fixtures/classes' require_relative '../../fixtures/io'
ruby_version_is ''...'3.2' do ruby_version_is ''...'3.2' do
require 'io/wait' require 'io/wait'
@ -55,7 +55,7 @@ describe "IO#wait" do
end end
it "waits for the WRITABLE event to be ready" do it "waits for the WRITABLE event to be ready" do
written_bytes = IOWaitSpec.exhaust_write_buffer(@w) written_bytes = IOSpec.exhaust_write_buffer(@w)
@w.wait(IO::WRITABLE, 0).should == nil @w.wait(IO::WRITABLE, 0).should == nil
@r.read(written_bytes) @r.read(written_bytes)
@ -67,7 +67,7 @@ describe "IO#wait" do
end end
it "returns nil when the WRITABLE event is not ready during the timeout" do it "returns nil when the WRITABLE event is not ready during the timeout" do
IOWaitSpec.exhaust_write_buffer(@w) IOSpec.exhaust_write_buffer(@w)
@w.wait(IO::WRITABLE, 0).should == nil @w.wait(IO::WRITABLE, 0).should == nil
end end
@ -92,7 +92,7 @@ describe "IO#wait" do
end end
it "changes thread status to 'sleep' when waits for WRITABLE event" do it "changes thread status to 'sleep' when waits for WRITABLE event" do
written_bytes = IOWaitSpec.exhaust_write_buffer(@w) IOSpec.exhaust_write_buffer(@w)
t = Thread.new { @w.wait(IO::WRITABLE, 10) } t = Thread.new { @w.wait(IO::WRITABLE, 10) }
sleep 1 sleep 1
@ -100,6 +100,37 @@ describe "IO#wait" do
t.kill t.kill
t.join # Thread#kill doesn't wait for the thread to end t.join # Thread#kill doesn't wait for the thread to end
end end
it "can be interrupted when waiting for READABLE event" do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
@r.wait(IO::READABLE, 10)
end
Thread.pass until t.stop?
t.kill
t.join # Thread#kill doesn't wait for the thread to end
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
end
it "can be interrupted when waiting for WRITABLE event" do
IOSpec.exhaust_write_buffer(@w)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
@w.wait(IO::WRITABLE, 10)
end
Thread.pass until t.stop?
t.kill
t.join # Thread#kill doesn't wait for the thread to end
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
end
end end
context "[timeout, mode] passed" do context "[timeout, mode] passed" do

View File

@ -1,4 +1,5 @@
require_relative '../../spec_helper' require_relative '../../spec_helper'
require_relative '../../fixtures/io'
ruby_version_is ''...'3.2' do ruby_version_is ''...'3.2' do
require 'io/wait' require 'io/wait'
@ -17,4 +18,24 @@ describe "IO#wait_writable" do
# Represents one year and is larger than a 32-bit int # Represents one year and is larger than a 32-bit int
STDOUT.wait_writable(365 * 24 * 60 * 60).should == STDOUT STDOUT.wait_writable(365 * 24 * 60 * 60).should == STDOUT
end end
it "can be interrupted" do
rd, wr = IO.pipe
IOSpec.exhaust_write_buffer(wr)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
wr.wait_writable(10)
end
Thread.pass until t.stop?
t.kill
t.join
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
ensure
rd.close unless rd.closed?
wr.close unless wr.closed?
end
end end

View File

@ -88,6 +88,30 @@ describe 'RbConfig::CONFIG' do
end end
end end
end end
guard -> { %w[aarch64 arm64].include? RbConfig::CONFIG['host_cpu'] } do
it "['host_cpu'] returns CPU architecture properly for AArch64" do
platform_is :darwin do
RbConfig::CONFIG['host_cpu'].should == 'arm64'
end
platform_is_not :darwin do
RbConfig::CONFIG['host_cpu'].should == 'aarch64'
end
end
end
guard -> { platform_is(:linux) || platform_is(:darwin) } do
it "['host_os'] returns a proper OS name or platform" do
platform_is :darwin do
RbConfig::CONFIG['host_os'].should.match?(/darwin/)
end
platform_is :linux do
RbConfig::CONFIG['host_os'].should.match?(/linux/)
end
end
end
end end
describe "RbConfig::TOPDIR" do describe "RbConfig::TOPDIR" do
@ -99,3 +123,32 @@ describe "RbConfig::TOPDIR" do
end end
end end
end end
describe "RUBY_PLATFORM" do
it "RUBY_PLATFORM contains a proper CPU architecture" do
RUBY_PLATFORM.should.include? RbConfig::CONFIG['host_cpu']
end
guard -> { platform_is(:linux) || platform_is(:darwin) } do
it "RUBY_PLATFORM contains OS name" do
# don't use RbConfig::CONFIG['host_os'] as far as it could be slightly different, e.g. linux-gnu
platform_is(:linux) do
RUBY_PLATFORM.should.include? 'linux'
end
platform_is(:darwin) do
RUBY_PLATFORM.should.include? 'darwin'
end
end
end
end
describe "RUBY_DESCRIPTION" do
it "contains version" do
RUBY_DESCRIPTION.should.include? RUBY_VERSION
end
it "contains RUBY_PLATFORM" do
RUBY_DESCRIPTION.should.include? RUBY_PLATFORM
end
end

View File

@ -1,4 +1,5 @@
require_relative 'spec_helper' require_relative 'spec_helper'
require_relative '../../fixtures/io'
load_extension('io') load_extension('io')
@ -279,6 +280,22 @@ describe "C-API IO function" do
it "raises an IOError if the IO is not initialized" do it "raises an IOError if the IO is not initialized" do
-> { @o.rb_io_maybe_wait_writable(0, IO.allocate, nil) }.should raise_error(IOError, "uninitialized stream") -> { @o.rb_io_maybe_wait_writable(0, IO.allocate, nil) }.should raise_error(IOError, "uninitialized stream")
end end
it "can be interrupted" do
IOSpec.exhaust_write_buffer(@w_io)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
@o.rb_io_maybe_wait_writable(0, @w_io, 10)
end
Thread.pass until t.stop?
t.kill
t.join
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
end
end end
end end
@ -355,6 +372,21 @@ describe "C-API IO function" do
thr.join thr.join
end end
it "can be interrupted" do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
@o.rb_io_maybe_wait_readable(0, @r_io, 10, false)
end
Thread.pass until t.stop?
t.kill
t.join
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
end
it "raises an IOError if the IO is closed" do it "raises an IOError if the IO is closed" do
@r_io.close @r_io.close
-> { @o.rb_io_maybe_wait_readable(0, @r_io, nil, false) }.should raise_error(IOError, "closed stream") -> { @o.rb_io_maybe_wait_readable(0, @r_io, nil, false) }.should raise_error(IOError, "closed stream")
@ -438,6 +470,37 @@ describe "C-API IO function" do
it "raises an IOError if the IO is not initialized" do it "raises an IOError if the IO is not initialized" do
-> { @o.rb_io_maybe_wait(0, IO.allocate, IO::WRITABLE, nil) }.should raise_error(IOError, "uninitialized stream") -> { @o.rb_io_maybe_wait(0, IO.allocate, IO::WRITABLE, nil) }.should raise_error(IOError, "uninitialized stream")
end end
it "can be interrupted when waiting for READABLE event" do
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
@o.rb_io_maybe_wait(0, @r_io, IO::READABLE, 10)
end
Thread.pass until t.stop?
t.kill
t.join
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
end
it "can be interrupted when waiting for WRITABLE event" do
IOSpec.exhaust_write_buffer(@w_io)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
t = Thread.new do
@o.rb_io_maybe_wait(0, @w_io, IO::WRITABLE, 10)
end
Thread.pass until t.stop?
t.kill
t.join
finish = Process.clock_gettime(Process::CLOCK_MONOTONIC)
(finish - start).should < 9
end
end end
end end