summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2022-10-21 13:36:03 +0900
committernagachika <nagachika@ruby-lang.org>2022-10-21 13:36:03 +0900
commit5d4bfaccabe66d89460739ee682f1f78698c93a3 (patch)
tree40d4021286b3a88aac9bad2276ee487b730fdaee /test
parent83ffa0d8e16cd829dc033d1d567353243845d86a (diff)
merge revision(s) ab3cb29bd9bff9c16cfb9d19cc02026998282c12:
Avoid defining the same test class in multiple files Should fix issues with parallel testing sometimes not running all tests. This should be viewed skipping whitespace changes. Fixes [Bug #18731] --- test/-ext-/bignum/test_big2str.rb | 38 +- test/-ext-/bignum/test_bigzero.rb | 20 +- test/-ext-/bignum/test_div.rb | 38 +- test/-ext-/bignum/test_mul.rb | 260 ++++++------ test/-ext-/bignum/test_pack.rb | 653 +++++++++++++++---------------- test/-ext-/bignum/test_str2big.rb | 52 ++- test/-ext-/funcall/test_funcall.rb | 11 - test/-ext-/funcall/test_passing_block.rb | 5 + test/date/test_date_ractor.rb | 2 +- test/fileutils/clobber.rb | 5 +- test/fileutils/test_dryrun.rb | 2 +- test/fileutils/test_nowrite.rb | 2 +- test/fileutils/test_verbose.rb | 2 +- test/fileutils/visibility_tests.rb | 5 +- test/mkmf/base.rb | 225 ++++++----- test/mkmf/test_config.rb | 16 +- test/mkmf/test_constant.rb | 56 ++- test/mkmf/test_convertible.rb | 48 ++- test/mkmf/test_egrep_cpp.rb | 14 +- test/mkmf/test_find_executable.rb | 82 ++-- test/mkmf/test_flags.rb | 92 +++-- test/mkmf/test_framework.rb | 70 ++-- test/mkmf/test_have_func.rb | 18 +- test/mkmf/test_have_library.rb | 84 ++-- test/mkmf/test_have_macro.rb | 46 ++- test/mkmf/test_install.rb | 38 +- test/mkmf/test_libs.rb | 156 ++++---- test/mkmf/test_mkmf.rb | 14 +- test/mkmf/test_pkg_config.rb | 98 +++-- test/mkmf/test_signedness.rb | 38 +- test/mkmf/test_sizeof.rb | 74 ++-- test/optparse/test_acceptable.rb | 2 +- test/optparse/test_autoconf.rb | 4 +- test/optparse/test_bash_completion.rb | 4 +- test/optparse/test_cclass.rb | 2 +- test/optparse/test_did_you_mean.rb | 2 +- test/optparse/test_getopts.rb | 4 +- test/optparse/test_kwargs.rb | 4 +- test/optparse/test_noarg.rb | 6 +- test/optparse/test_optarg.rb | 2 +- test/optparse/test_placearg.rb | 2 +- test/optparse/test_reqarg.rb | 10 +- test/optparse/test_summary.rb | 2 +- test/optparse/test_zsh_completion.rb | 4 +- test/ruby/enc/test_emoji_breaks.rb | 207 +++++----- test/ruby/enc/test_grapheme_breaks.rb | 115 +++--- test/ruby/test_inlinecache.rb | 2 +- 47 files changed, 1280 insertions(+), 1356 deletions(-) delete mode 100644 test/-ext-/funcall/test_funcall.rb
Diffstat (limited to 'test')
-rw-r--r--test/-ext-/bignum/test_big2str.rb38
-rw-r--r--test/-ext-/bignum/test_bigzero.rb20
-rw-r--r--test/-ext-/bignum/test_div.rb38
-rw-r--r--test/-ext-/bignum/test_mul.rb260
-rw-r--r--test/-ext-/bignum/test_pack.rb653
-rw-r--r--test/-ext-/bignum/test_str2big.rb52
-rw-r--r--test/-ext-/funcall/test_funcall.rb11
-rw-r--r--test/-ext-/funcall/test_passing_block.rb5
-rw-r--r--test/date/test_date_ractor.rb2
-rw-r--r--test/fileutils/clobber.rb5
-rw-r--r--test/fileutils/test_dryrun.rb2
-rw-r--r--test/fileutils/test_nowrite.rb2
-rw-r--r--test/fileutils/test_verbose.rb2
-rw-r--r--test/fileutils/visibility_tests.rb5
-rw-r--r--test/mkmf/base.rb225
-rw-r--r--test/mkmf/test_config.rb16
-rw-r--r--test/mkmf/test_constant.rb56
-rw-r--r--test/mkmf/test_convertible.rb48
-rw-r--r--test/mkmf/test_egrep_cpp.rb14
-rw-r--r--test/mkmf/test_find_executable.rb82
-rw-r--r--test/mkmf/test_flags.rb92
-rw-r--r--test/mkmf/test_framework.rb70
-rw-r--r--test/mkmf/test_have_func.rb18
-rw-r--r--test/mkmf/test_have_library.rb84
-rw-r--r--test/mkmf/test_have_macro.rb46
-rw-r--r--test/mkmf/test_install.rb38
-rw-r--r--test/mkmf/test_libs.rb156
-rw-r--r--test/mkmf/test_mkmf.rb14
-rw-r--r--test/mkmf/test_pkg_config.rb98
-rw-r--r--test/mkmf/test_signedness.rb38
-rw-r--r--test/mkmf/test_sizeof.rb74
-rw-r--r--test/optparse/test_acceptable.rb2
-rw-r--r--test/optparse/test_autoconf.rb4
-rw-r--r--test/optparse/test_bash_completion.rb4
-rw-r--r--test/optparse/test_cclass.rb2
-rw-r--r--test/optparse/test_did_you_mean.rb2
-rw-r--r--test/optparse/test_getopts.rb4
-rw-r--r--test/optparse/test_kwargs.rb4
-rw-r--r--test/optparse/test_noarg.rb6
-rw-r--r--test/optparse/test_optarg.rb2
-rw-r--r--test/optparse/test_placearg.rb2
-rw-r--r--test/optparse/test_reqarg.rb10
-rw-r--r--test/optparse/test_summary.rb2
-rw-r--r--test/optparse/test_zsh_completion.rb4
-rw-r--r--test/ruby/enc/test_grapheme_breaks.rb115
-rw-r--r--test/ruby/test_inlinecache.rb2
46 files changed, 1178 insertions, 1251 deletions
diff --git a/test/-ext-/bignum/test_big2str.rb b/test/-ext-/bignum/test_big2str.rb
index f8d6320338..88e35a7294 100644
--- a/test/-ext-/bignum/test_big2str.rb
+++ b/test/-ext-/bignum/test_big2str.rb
@@ -2,29 +2,27 @@
require 'test/unit'
require "-test-/bignum"
-class Test_Bignum < Test::Unit::TestCase
- class TestBig2str < Test::Unit::TestCase
+class TestBignum_Big2str < Test::Unit::TestCase
- SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
- BITSPERDIG = Bug::Bignum::BITSPERDIG
- BDIGMAX = (1 << BITSPERDIG) - 1
+ SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
+ BITSPERDIG = Bug::Bignum::BITSPERDIG
+ BDIGMAX = (1 << BITSPERDIG) - 1
- def test_big2str_generic
- x = 10**1000
- assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_generic(x, 10))
- end
-
- def test_big2str_poweroftwo
- e = BITSPERDIG*2
- x = 0b10**e
- assert_equal("1" + "0" * e, Bug::Bignum.big2str_poweroftwo(x, 2))
- end
+ def test_big2str_generic
+ x = 10**1000
+ assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_generic(x, 10))
+ end
- def test_big2str_gmp
- x = 10**1000
- assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_gmp(x, 10))
- rescue NotImplementedError
- end
+ def test_big2str_poweroftwo
+ e = BITSPERDIG*2
+ x = 0b10**e
+ assert_equal("1" + "0" * e, Bug::Bignum.big2str_poweroftwo(x, 2))
+ end
+ def test_big2str_gmp
+ x = 10**1000
+ assert_equal("1" + "0" * 1000, Bug::Bignum.big2str_gmp(x, 10))
+ rescue NotImplementedError
end
+
end
diff --git a/test/-ext-/bignum/test_bigzero.rb b/test/-ext-/bignum/test_bigzero.rb
index cf34964acd..6dfa3486c1 100644
--- a/test/-ext-/bignum/test_bigzero.rb
+++ b/test/-ext-/bignum/test_bigzero.rb
@@ -2,19 +2,17 @@
require 'test/unit'
require "-test-/bignum"
-class Test_Bignum < Test::Unit::TestCase
- class TestBigZero < Test::Unit::TestCase
- def test_equal_0
- bug8204 = '[ruby-core:53893] [Bug #8204]'
- (0..10).each do |i|
- assert_equal(0, Bug::Bignum.zero(i), "#{bug8204} Bignum.zero(#{i})")
- end
+class TestBignum_BigZero < Test::Unit::TestCase
+ def test_equal_0
+ bug8204 = '[ruby-core:53893] [Bug #8204]'
+ (0..10).each do |i|
+ assert_equal(0, Bug::Bignum.zero(i), "#{bug8204} Bignum.zero(#{i})")
end
+ end
- def test_zero?
- (0..10).each do |i|
- assert_equal(true, Bug::Bignum.zero(i).zero?)
- end
+ def test_zero?
+ (0..10).each do |i|
+ assert_equal(true, Bug::Bignum.zero(i).zero?)
end
end
end
diff --git a/test/-ext-/bignum/test_div.rb b/test/-ext-/bignum/test_div.rb
index e61fc2ced5..0c6f635ae8 100644
--- a/test/-ext-/bignum/test_div.rb
+++ b/test/-ext-/bignum/test_div.rb
@@ -2,28 +2,26 @@
require 'test/unit'
require "-test-/bignum"
-class Test_Bignum < Test::Unit::TestCase
- class TestDiv < Test::Unit::TestCase
+class TestBignum_Div < Test::Unit::TestCase
- SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
- BITSPERDIG = Bug::Bignum::BITSPERDIG
- BDIGMAX = (1 << BITSPERDIG) - 1
+ SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
+ BITSPERDIG = Bug::Bignum::BITSPERDIG
+ BDIGMAX = (1 << BITSPERDIG) - 1
- def test_divrem_normal
- x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
- y = (1 << BITSPERDIG) | 1
- q = (1 << BITSPERDIG) | 1
- r = 2
- assert_equal([q, r], Bug::Bignum.big_divrem_normal(x, y))
- end
+ def test_divrem_normal
+ x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
+ y = (1 << BITSPERDIG) | 1
+ q = (1 << BITSPERDIG) | 1
+ r = 2
+ assert_equal([q, r], Bug::Bignum.big_divrem_normal(x, y))
+ end
- def test_divrem_gmp
- x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
- y = (1 << BITSPERDIG) | 1
- q = (1 << BITSPERDIG) | 1
- r = 2
- assert_equal([q, r], Bug::Bignum.big_divrem_gmp(x, y))
- rescue NotImplementedError
- end
+ def test_divrem_gmp
+ x = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 3
+ y = (1 << BITSPERDIG) | 1
+ q = (1 << BITSPERDIG) | 1
+ r = 2
+ assert_equal([q, r], Bug::Bignum.big_divrem_gmp(x, y))
+ rescue NotImplementedError
end
end
diff --git a/test/-ext-/bignum/test_mul.rb b/test/-ext-/bignum/test_mul.rb
index 7653a8e37a..95186bbf76 100644
--- a/test/-ext-/bignum/test_mul.rb
+++ b/test/-ext-/bignum/test_mul.rb
@@ -2,137 +2,135 @@
require 'test/unit'
require "-test-/bignum"
-class Test_Bignum < Test::Unit::TestCase
- class TestMul < Test::Unit::TestCase
-
- SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
- BITSPERDIG = Bug::Bignum::BITSPERDIG
- BDIGMAX = (1 << BITSPERDIG) - 1
-
- def test_mul_normal
- x = (1 << BITSPERDIG) | 1
- y = (1 << BITSPERDIG) | 1
- z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
- assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
- end
-
- def test_mul_normal_zero_in_x
- x = (1 << (2*BITSPERDIG)) | 1
- y = (1 << BITSPERDIG) | 1
- z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
- assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
- end
-
- def test_mul_normal_zero_in_y
- x = (1 << BITSPERDIG) | 1
- y = (1 << (2*BITSPERDIG)) | 1
- z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
- assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
- end
-
- def test_mul_normal_max_max
- x = (1 << (2*BITSPERDIG)) - 1
- y = (1 << (2*BITSPERDIG)) - 1
- z = (1 << (4*BITSPERDIG)) - (1 << (2*BITSPERDIG+1)) + 1
- assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
- end
-
- def test_sq_fast
- x = (1 << BITSPERDIG) | 1
- z = (1 << 2*BITSPERDIG) | (2 << BITSPERDIG) | 1
- assert_equal(z, Bug::Bignum.big_sq_fast(x))
- end
-
- def test_sq_fast_max2
- x = (BDIGMAX << BITSPERDIG) | BDIGMAX
- assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
- end
-
- def test_sq_fast_zero_in_middle
- x = (BDIGMAX << 2*BITSPERDIG) | BDIGMAX
- assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
- end
-
- def test_mul_balance
- x = (1 << BITSPERDIG) | 1
- y = (1 << BITSPERDIG) | 1
- z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
- assert_equal(z, Bug::Bignum.big_mul_balance(x, y))
- end
-
- def test_mul_balance_2x16
- x = (1 << BITSPERDIG) | 1
- y = (1 << BITSPERDIG*16) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
- end
-
- def test_mul_balance_2x17
- x = (1 << BITSPERDIG) | 1
- y = (1 << BITSPERDIG*17) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
- end
-
- def test_mul_karatsuba
- x = (1 << BITSPERDIG) | 1
- y = (1 << BITSPERDIG) | 1
- z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
- assert_equal(z, Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_karatsuba_odd_y
- x = (1 << BITSPERDIG) | 1
- y = (1 << (2*BITSPERDIG)) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_karatsuba_odd_xy
- x = (1 << (2*BITSPERDIG)) | 1
- y = (1 << (2*BITSPERDIG)) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_karatsuba_x1_gt_x0
- x = (2 << BITSPERDIG) | 1
- y = (1 << BITSPERDIG) | 2
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_karatsuba_y1_gt_y0
- x = (1 << BITSPERDIG) | 2
- y = (2 << BITSPERDIG) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_karatsuba_x1_gt_x0_and_y1_gt_y0
- x = (2 << BITSPERDIG) | 1
- y = (2 << BITSPERDIG) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_karatsuba_carry2
- x = (1 << BITSPERDIG) | BDIGMAX
- y = (1 << BITSPERDIG) | BDIGMAX
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_karatsuba_borrow
- x = (BDIGMAX << BITSPERDIG) | 1
- y = (BDIGMAX << BITSPERDIG) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
- end
-
- def test_mul_toom3
- x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
- y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_toom3(x, y))
- end
-
- def test_mul_gmp
- x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
- y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
- assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_gmp(x, y))
- rescue NotImplementedError
- end
+class TestBignum_Mul < Test::Unit::TestCase
+ SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
+ BITSPERDIG = Bug::Bignum::BITSPERDIG
+ BDIGMAX = (1 << BITSPERDIG) - 1
+
+ def test_mul_normal
+ x = (1 << BITSPERDIG) | 1
+ y = (1 << BITSPERDIG) | 1
+ z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
+ assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
+ end
+
+ def test_mul_normal_zero_in_x
+ x = (1 << (2*BITSPERDIG)) | 1
+ y = (1 << BITSPERDIG) | 1
+ z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
+ assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
+ end
+
+ def test_mul_normal_zero_in_y
+ x = (1 << BITSPERDIG) | 1
+ y = (1 << (2*BITSPERDIG)) | 1
+ z = (1 << (BITSPERDIG*3)) | (1 << (BITSPERDIG*2)) | (1 << BITSPERDIG) | 1
+ assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
+ end
+
+ def test_mul_normal_max_max
+ x = (1 << (2*BITSPERDIG)) - 1
+ y = (1 << (2*BITSPERDIG)) - 1
+ z = (1 << (4*BITSPERDIG)) - (1 << (2*BITSPERDIG+1)) + 1
+ assert_equal(z, Bug::Bignum.big_mul_normal(x, y))
+ end
+
+ def test_sq_fast
+ x = (1 << BITSPERDIG) | 1
+ z = (1 << 2*BITSPERDIG) | (2 << BITSPERDIG) | 1
+ assert_equal(z, Bug::Bignum.big_sq_fast(x))
+ end
+
+ def test_sq_fast_max2
+ x = (BDIGMAX << BITSPERDIG) | BDIGMAX
+ assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
+ end
+
+ def test_sq_fast_zero_in_middle
+ x = (BDIGMAX << 2*BITSPERDIG) | BDIGMAX
+ assert_equal(Bug::Bignum.big_mul_normal(x, x), Bug::Bignum.big_sq_fast(x))
+ end
+
+ def test_mul_balance
+ x = (1 << BITSPERDIG) | 1
+ y = (1 << BITSPERDIG) | 1
+ z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
+ assert_equal(z, Bug::Bignum.big_mul_balance(x, y))
+ end
+
+ def test_mul_balance_2x16
+ x = (1 << BITSPERDIG) | 1
+ y = (1 << BITSPERDIG*16) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
+ end
+
+ def test_mul_balance_2x17
+ x = (1 << BITSPERDIG) | 1
+ y = (1 << BITSPERDIG*17) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_balance(x, y))
+ end
+
+ def test_mul_karatsuba
+ x = (1 << BITSPERDIG) | 1
+ y = (1 << BITSPERDIG) | 1
+ z = (1 << (BITSPERDIG*2)) | (2 << BITSPERDIG) | 1
+ assert_equal(z, Bug::Bignum.big_mul_karatsuba(x, y))
+ end
+
+ def test_mul_karatsuba_odd_y
+ x = (1 << BITSPERDIG) | 1
+ y = (1 << (2*BITSPERDIG)) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
+ end
+
+ def test_mul_karatsuba_odd_xy
+ x = (1 << (2*BITSPERDIG)) | 1
+ y = (1 << (2*BITSPERDIG)) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
+ end
+
+ def test_mul_karatsuba_x1_gt_x0
+ x = (2 << BITSPERDIG) | 1
+ y = (1 << BITSPERDIG) | 2
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
+ end
+
+ def test_mul_karatsuba_y1_gt_y0
+ x = (1 << BITSPERDIG) | 2
+ y = (2 << BITSPERDIG) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
+ end
+
+ def test_mul_karatsuba_x1_gt_x0_and_y1_gt_y0
+ x = (2 << BITSPERDIG) | 1
+ y = (2 << BITSPERDIG) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
+ end
+
+ def test_mul_karatsuba_carry2
+ x = (1 << BITSPERDIG) | BDIGMAX
+ y = (1 << BITSPERDIG) | BDIGMAX
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
+ end
+
+ def test_mul_karatsuba_borrow
+ x = (BDIGMAX << BITSPERDIG) | 1
+ y = (BDIGMAX << BITSPERDIG) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_karatsuba(x, y))
end
+
+ def test_mul_toom3
+ x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
+ y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_toom3(x, y))
+ end
+
+ def test_mul_gmp
+ x = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
+ y = (1 << 2*BITSPERDIG) | (1 << BITSPERDIG) | 1
+ assert_equal(Bug::Bignum.big_mul_normal(x, y), Bug::Bignum.big_mul_gmp(x, y))
+ rescue NotImplementedError
+ end
+
end
diff --git a/test/-ext-/bignum/test_pack.rb b/test/-ext-/bignum/test_pack.rb
index d5605236f7..b7aea9ab68 100644
--- a/test/-ext-/bignum/test_pack.rb
+++ b/test/-ext-/bignum/test_pack.rb
@@ -4,348 +4,346 @@
require 'test/unit'
require "-test-/bignum"
-class Test_Bignum < Test::Unit::TestCase
- class TestPack < Test::Unit::TestCase
-
- MSWORD_FIRST = Bug::Bignum::INTEGER_PACK_MSWORD_FIRST
- LSWORD_FIRST = Bug::Bignum::INTEGER_PACK_LSWORD_FIRST
- MSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_MSBYTE_FIRST
- LSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_LSBYTE_FIRST
- NATIVE_BYTE_ORDER = Bug::Bignum::INTEGER_PACK_NATIVE_BYTE_ORDER
- TWOCOMP = Bug::Bignum::INTEGER_PACK_2COMP
- LITTLE_ENDIAN = Bug::Bignum::INTEGER_PACK_LITTLE_ENDIAN
- BIG_ENDIAN = Bug::Bignum::INTEGER_PACK_BIG_ENDIAN
- NEGATIVE = Bug::Bignum::INTEGER_PACK_NEGATIVE
- GENERIC = Bug::Bignum::INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION
-
- def test_pack_zero
- assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, BIG_ENDIAN))
- end
-
- def test_pack_argument_check
- assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 2, 1, 0, MSBYTE_FIRST) }
- assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 0, MSWORD_FIRST) }
- assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 0, 0, BIG_ENDIAN) }
- assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 8, BIG_ENDIAN) }
-
- # assume sizeof(ssize_t) == sizeof(intptr_t)
- assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
- end
-
- def test_pack_wordsize
- assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, BIG_ENDIAN))
- assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(1, 1, 2, 0, BIG_ENDIAN))
- assert_equal([1, "\x00\x00\x01"], Bug::Bignum.test_pack(1, 1, 3, 0, BIG_ENDIAN))
- assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, LITTLE_ENDIAN))
- assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(1, 1, 2, 0, LITTLE_ENDIAN))
- assert_equal([1, "\x01\x00\x00"], Bug::Bignum.test_pack(1, 1, 3, 0, LITTLE_ENDIAN))
- end
-
- def test_pack_fixed_buffer
- assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, BIG_ENDIAN))
- assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(0x01, 2, 1, 0, BIG_ENDIAN))
- assert_equal([1, "\x02\x01"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, BIG_ENDIAN))
- assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, BIG_ENDIAN))
- assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, BIG_ENDIAN))
- assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, LITTLE_ENDIAN))
- assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(0x01, 2, 1, 0, LITTLE_ENDIAN))
- assert_equal([1, "\x01\x02"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, LITTLE_ENDIAN))
- assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, LITTLE_ENDIAN))
- assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, LITTLE_ENDIAN))
- end
-
- def test_pack_wordorder_and_endian
- assert_equal([1, "\x12\x34\x56\x78"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
- assert_equal([1, "\x34\x12\x78\x56"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
- assert_equal([1, "\x56\x78\x12\x34"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
- assert_equal([1, "\x78\x56\x34\x12"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
- end
-
- def test_pack_native_endian
- assert_equal([1, [0x1234].pack("S!")], Bug::Bignum.test_pack(0x1234, 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
- end
-
- def test_pack_nail
- assert_equal([1, "\x01\x00\x00\x00\x01\x01"], Bug::Bignum.test_pack(0b100011, 6, 1, 7, BIG_ENDIAN))
- assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08"], Bug::Bignum.test_pack(0x12345678, 8, 1, 4, BIG_ENDIAN))
- assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78"], Bug::Bignum.test_pack(0x12345678, 4, 2, 8, BIG_ENDIAN))
- end
-
- def test_pack_overflow
- assert_equal([-2, "\x1"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, BIG_ENDIAN))
- assert_equal([-2, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, BIG_ENDIAN))
- assert_equal([-1, "\xF"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, BIG_ENDIAN))
- assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, BIG_ENDIAN))
- assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, BIG_ENDIAN))
- assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, BIG_ENDIAN))
-
- assert_equal([-2, "\x01"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, BIG_ENDIAN))
- assert_equal([-2, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, BIG_ENDIAN))
- assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, BIG_ENDIAN))
- assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, BIG_ENDIAN))
- assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, BIG_ENDIAN))
- assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, BIG_ENDIAN))
-
- assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
- assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
- assert_equal([-1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
- assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
- assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
- assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
-
- 1.upto(16) {|wordsize|
- 1.upto(20) {|numwords|
- w = numwords*wordsize
- n = 256**w
- assert_equal([-2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, BIG_ENDIAN))
- assert_equal([-2, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, BIG_ENDIAN))
- assert_equal([-1, "\xFF"*w], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, BIG_ENDIAN))
- assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, BIG_ENDIAN))
- assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, BIG_ENDIAN))
- assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, BIG_ENDIAN))
- }
- }
+class TestBignum_Pack < Test::Unit::TestCase
+
+ MSWORD_FIRST = Bug::Bignum::INTEGER_PACK_MSWORD_FIRST
+ LSWORD_FIRST = Bug::Bignum::INTEGER_PACK_LSWORD_FIRST
+ MSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_MSBYTE_FIRST
+ LSBYTE_FIRST = Bug::Bignum::INTEGER_PACK_LSBYTE_FIRST
+ NATIVE_BYTE_ORDER = Bug::Bignum::INTEGER_PACK_NATIVE_BYTE_ORDER
+ TWOCOMP = Bug::Bignum::INTEGER_PACK_2COMP
+ LITTLE_ENDIAN = Bug::Bignum::INTEGER_PACK_LITTLE_ENDIAN
+ BIG_ENDIAN = Bug::Bignum::INTEGER_PACK_BIG_ENDIAN
+ NEGATIVE = Bug::Bignum::INTEGER_PACK_NEGATIVE
+ GENERIC = Bug::Bignum::INTEGER_PACK_FORCE_GENERIC_IMPLEMENTATION
+
+ def test_pack_zero
+ assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, BIG_ENDIAN))
+ end
- 1.upto(16) {|wordsize|
- 1.upto(20) {|numwords|
- w = numwords*wordsize
- n = 256**w
- assert_equal([-2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
- assert_equal([-2, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, LITTLE_ENDIAN))
- assert_equal([-1, "\xFF"*w], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
- assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
- assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, LITTLE_ENDIAN))
- assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
- }
+ def test_pack_argument_check
+ assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 2, 1, 0, MSBYTE_FIRST) }
+ assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 0, MSWORD_FIRST) }
+ assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 0, 0, BIG_ENDIAN) }
+ assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 0, 1, 8, BIG_ENDIAN) }
+
+ # assume sizeof(ssize_t) == sizeof(intptr_t)
+ assert_raise(ArgumentError) { Bug::Bignum.test_pack_raw(0, "", 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
+ end
+
+ def test_pack_wordsize
+ assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, BIG_ENDIAN))
+ assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(1, 1, 2, 0, BIG_ENDIAN))
+ assert_equal([1, "\x00\x00\x01"], Bug::Bignum.test_pack(1, 1, 3, 0, BIG_ENDIAN))
+ assert_equal([1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, LITTLE_ENDIAN))
+ assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(1, 1, 2, 0, LITTLE_ENDIAN))
+ assert_equal([1, "\x01\x00\x00"], Bug::Bignum.test_pack(1, 1, 3, 0, LITTLE_ENDIAN))
+ end
+
+ def test_pack_fixed_buffer
+ assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, BIG_ENDIAN))
+ assert_equal([1, "\x00\x01"], Bug::Bignum.test_pack(0x01, 2, 1, 0, BIG_ENDIAN))
+ assert_equal([1, "\x02\x01"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, BIG_ENDIAN))
+ assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, BIG_ENDIAN))
+ assert_equal([2, "\x02\x01"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, BIG_ENDIAN))
+ assert_equal([0, "\x00\x00"], Bug::Bignum.test_pack(0, 2, 1, 0, LITTLE_ENDIAN))
+ assert_equal([1, "\x01\x00"], Bug::Bignum.test_pack(0x01, 2, 1, 0, LITTLE_ENDIAN))
+ assert_equal([1, "\x01\x02"], Bug::Bignum.test_pack(0x0201, 2, 1, 0, LITTLE_ENDIAN))
+ assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x030201, 2, 1, 0, LITTLE_ENDIAN))
+ assert_equal([2, "\x01\x02"], Bug::Bignum.test_pack(0x04030201, 2, 1, 0, LITTLE_ENDIAN))
+ end
+
+ def test_pack_wordorder_and_endian
+ assert_equal([1, "\x12\x34\x56\x78"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
+ assert_equal([1, "\x34\x12\x78\x56"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
+ assert_equal([1, "\x56\x78\x12\x34"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
+ assert_equal([1, "\x78\x56\x34\x12"], Bug::Bignum.test_pack(0x12345678, 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
+ end
+
+ def test_pack_native_endian
+ assert_equal([1, [0x1234].pack("S!")], Bug::Bignum.test_pack(0x1234, 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
+ end
+
+ def test_pack_nail
+ assert_equal([1, "\x01\x00\x00\x00\x01\x01"], Bug::Bignum.test_pack(0b100011, 6, 1, 7, BIG_ENDIAN))
+ assert_equal([1, "\x01\x02\x03\x04\x05\x06\x07\x08"], Bug::Bignum.test_pack(0x12345678, 8, 1, 4, BIG_ENDIAN))
+ assert_equal([1, "\x00\x12\x00\x34\x00\x56\x00\x78"], Bug::Bignum.test_pack(0x12345678, 4, 2, 8, BIG_ENDIAN))
+ end
+
+ def test_pack_overflow
+ assert_equal([-2, "\x1"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, BIG_ENDIAN))
+ assert_equal([-2, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, BIG_ENDIAN))
+ assert_equal([-1, "\xF"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, BIG_ENDIAN))
+ assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, BIG_ENDIAN))
+ assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, BIG_ENDIAN))
+ assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, BIG_ENDIAN))
+
+ assert_equal([-2, "\x01"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, BIG_ENDIAN))
+ assert_equal([-2, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, BIG_ENDIAN))
+ assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, BIG_ENDIAN))
+ assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, BIG_ENDIAN))
+ assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, BIG_ENDIAN))
+ assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, BIG_ENDIAN))
+
+ assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
+ assert_equal([-2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
+ assert_equal([-1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
+ assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, BIG_ENDIAN))
+ assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, BIG_ENDIAN))
+ assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, BIG_ENDIAN))
+
+ 1.upto(16) {|wordsize|
+ 1.upto(20) {|numwords|
+ w = numwords*wordsize
+ n = 256**w
+ assert_equal([-2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, BIG_ENDIAN))
+ assert_equal([-2, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, BIG_ENDIAN))
+ assert_equal([-1, "\xFF"*w], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, BIG_ENDIAN))
+ assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, BIG_ENDIAN))
+ assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, BIG_ENDIAN))
+ assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, BIG_ENDIAN))
}
- end
-
- def test_pack_sign
- assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-1), 1, 1, 0, BIG_ENDIAN))
- assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10"], Bug::Bignum.test_pack((-0x8070605040302010), 8, 1, 0, BIG_ENDIAN))
- end
-
- def test_pack_orders
- [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
- [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
- 1.upto(16) {|wordsize|
- 1.upto(20) {|numwords|
- w = numwords*wordsize
- n = 0;
- 0.upto(w) {|i|
- n |= ((i+1) % 256) << (i*8)
- }
- assert_equal(Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order|GENERIC),
- Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order),
- "#{'%#x' % n}.test_pack(#{numwords}, #{wordsize}, 0, #{'%#x' % (word_order|byte_order)})")
+ }
+
+ 1.upto(16) {|wordsize|
+ 1.upto(20) {|numwords|
+ w = numwords*wordsize
+ n = 256**w
+ assert_equal([-2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
+ assert_equal([-2, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, LITTLE_ENDIAN))
+ assert_equal([-1, "\xFF"*w], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
+ assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, LITTLE_ENDIAN))
+ assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, LITTLE_ENDIAN))
+ assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, LITTLE_ENDIAN))
+ }
+ }
+ end
+
+ def test_pack_sign
+ assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-1), 1, 1, 0, BIG_ENDIAN))
+ assert_equal([-1, "\x80\x70\x60\x50\x40\x30\x20\x10"], Bug::Bignum.test_pack((-0x8070605040302010), 8, 1, 0, BIG_ENDIAN))
+ end
+
+ def test_pack_orders
+ [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
+ [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
+ 1.upto(16) {|wordsize|
+ 1.upto(20) {|numwords|
+ w = numwords*wordsize
+ n = 0;
+ 0.upto(w) {|i|
+ n |= ((i+1) % 256) << (i*8)
}
+ assert_equal(Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order|GENERIC),
+ Bug::Bignum.test_pack(n, numwords, wordsize, 0, word_order|byte_order),
+ "#{'%#x' % n}.test_pack(#{numwords}, #{wordsize}, 0, #{'%#x' % (word_order|byte_order)})")
}
}
}
- end
-
- def test_pack2comp_zero
- assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
- end
-
- def test_pack2comp_emptybuf
- assert_equal([-2, ""], Bug::Bignum.test_pack((-3), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-2, ""], Bug::Bignum.test_pack((-2), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, ""], Bug::Bignum.test_pack((-1), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([ 0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, ""], Bug::Bignum.test_pack(1, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, ""], Bug::Bignum.test_pack(2, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
- end
-
- def test_pack2comp_nearly_zero
- assert_equal([-1, "\xFE"], Bug::Bignum.test_pack((-2), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-1), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([ 0, "\x00"], Bug::Bignum.test_pack(0, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+1, "\x02"], Bug::Bignum.test_pack(2, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- end
-
- def test_pack2comp_overflow
- assert_equal([-2, "\xF"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x1"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
- assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
-
- assert_equal([-2, "\xFF"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
-
- assert_equal([-2, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
-
- 1.upto(16) {|wordsize|
- 1.upto(20) {|numwords|
- w = numwords*wordsize
- n = 256**w
- assert_equal([-2, "\xFF"*w ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([-1, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
- }
- }
+ }
+ end
- 1.upto(16) {|wordsize|
- 1.upto(20) {|numwords|
- w = numwords*wordsize
- n = 256**w
- assert_equal([-2, "\xFF"*w ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
- assert_equal([-1, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
- assert_equal([-1, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
- assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
- assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
- assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
- }
- }
+ def test_pack2comp_zero
+ assert_equal([0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
+ end
- 2.upto(16) {|wordsize|
- w = wordsize
- b = 8*wordsize-1
- n = 2**b
- assert_equal([-2, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
- assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
- assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
- assert_equal([+1, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
- assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
- assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
- }
+ def test_pack2comp_emptybuf
+ assert_equal([-2, ""], Bug::Bignum.test_pack((-3), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-2, ""], Bug::Bignum.test_pack((-2), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, ""], Bug::Bignum.test_pack((-1), 0, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([ 0, ""], Bug::Bignum.test_pack(0, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, ""], Bug::Bignum.test_pack(1, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, ""], Bug::Bignum.test_pack(2, 0, 1, 0, TWOCOMP|BIG_ENDIAN))
+ end
- 2.upto(16) {|wordsize|
- w = wordsize
- b = 8*wordsize-1
- n = 2**b
- assert_equal([-2, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
- assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
- assert_equal([-1, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
- assert_equal([+1, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
- assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
- assert_equal([+2, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+ def test_pack2comp_nearly_zero
+ assert_equal([-1, "\xFE"], Bug::Bignum.test_pack((-2), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\xFF"], Bug::Bignum.test_pack((-1), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([ 0, "\x00"], Bug::Bignum.test_pack(0, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+1, "\x01"], Bug::Bignum.test_pack(1, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+1, "\x02"], Bug::Bignum.test_pack(2, 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ end
+
+ def test_pack2comp_overflow
+ assert_equal([-2, "\xF"], Bug::Bignum.test_pack((-0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x0"], Bug::Bignum.test_pack((-0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x1"], Bug::Bignum.test_pack((-0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+1, "\xF"], Bug::Bignum.test_pack((+0x0F), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x0"], Bug::Bignum.test_pack((+0x10), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x1"], Bug::Bignum.test_pack((+0x11), 1, 1, 4, TWOCOMP|BIG_ENDIAN))
+
+ assert_equal([-2, "\xFF"], Bug::Bignum.test_pack((-0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x00"], Bug::Bignum.test_pack((-0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x01"], Bug::Bignum.test_pack((-0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+1, "\xFF"], Bug::Bignum.test_pack((+0x0FF), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x00"], Bug::Bignum.test_pack((+0x100), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x01"], Bug::Bignum.test_pack((+0x101), 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+
+ assert_equal([-2, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((-0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((-0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((-0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+1, "\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], Bug::Bignum.test_pack((+0x0FFFFFFFFFFFFFFFF), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x00"], Bug::Bignum.test_pack((+0x10000000000000000), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x00\x00\x00\x00\x00\x00\x00\x01"], Bug::Bignum.test_pack((+0x10000000000000001), 2, 4, 0, TWOCOMP|BIG_ENDIAN))
+
+ 1.upto(16) {|wordsize|
+ 1.upto(20) {|numwords|
+ w = numwords*wordsize
+ n = 256**w
+ assert_equal([-2, "\xFF"*w ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([-1, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal([+2, "\x00"*(w-1)+"\x01"], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|BIG_ENDIAN))
}
+ }
+
+ 1.upto(16) {|wordsize|
+ 1.upto(20) {|numwords|
+ w = numwords*wordsize
+ n = 256**w
+ assert_equal([-2, "\xFF"*w ], Bug::Bignum.test_pack((-n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
+ assert_equal([-1, "\x00"*w], Bug::Bignum.test_pack((-n ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
+ assert_equal([-1, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((-n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
+ assert_equal([+1, "\xFF"*w], Bug::Bignum.test_pack((+n-1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
+ assert_equal([+2, "\x00"*w], Bug::Bignum.test_pack((+n ), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
+ assert_equal([+2, "\x01"+"\x00"*(w-1)], Bug::Bignum.test_pack((+n+1), numwords, wordsize, 0, TWOCOMP|LITTLE_ENDIAN))
+ }
+ }
+
+ 2.upto(16) {|wordsize|
+ w = wordsize
+ b = 8*wordsize-1
+ n = 2**b
+ assert_equal([-2, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+ assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+ assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+ assert_equal([+1, "\x7F"+"\xFF"*(w-2)+"\xFF"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+ assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n ), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+ assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x01"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|MSBYTE_FIRST))
+ }
+
+ 2.upto(16) {|wordsize|
+ w = wordsize
+ b = 8*wordsize-1
+ n = 2**b
+ assert_equal([-2, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((-n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+ assert_equal([-1, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+ assert_equal([-1, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((-n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+ assert_equal([+1, "\xFF"+"\xFF"*(w-2)+"\x7F"], Bug::Bignum.test_pack((+n-1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+ assert_equal([+2, "\x00"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n ), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+ assert_equal([+2, "\x01"+"\x00"*(w-2)+"\x00"], Bug::Bignum.test_pack((+n+1), 1, wordsize, 1, TWOCOMP|LSBYTE_FIRST))
+ }
+
+ end
+
+ def test_unpack_zero
+ assert_equal(0, Bug::Bignum.test_unpack("", 0, 1, 0, BIG_ENDIAN))
+ end
+
+ def test_unpack_argument_check
+ assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 2, 1, 0, MSBYTE_FIRST) }
+ assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 0, MSWORD_FIRST) }
+ assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 0, 0, BIG_ENDIAN) }
+ assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 8, BIG_ENDIAN) }
+
+ # assume sizeof(ssize_t) == sizeof(intptr_t)
+ assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
+ end
+
+ def test_unpack_wordsize
+ assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN))
+ assert_equal(1, Bug::Bignum.test_unpack("\x00\x01", 1, 2, 0, BIG_ENDIAN))
+ assert_equal(1, Bug::Bignum.test_unpack("\x00\x00\x01", 1, 3, 0, BIG_ENDIAN))
+ assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, LITTLE_ENDIAN))
+ assert_equal(1, Bug::Bignum.test_unpack("\x01\x00", 1, 2, 0, LITTLE_ENDIAN))
+ assert_equal(1, Bug::Bignum.test_unpack("\x01\x00\x00", 1, 3, 0, LITTLE_ENDIAN))
+ end
+
+ def test_unpack_wordorder_and_endian
+ assert_equal(0x01020304, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
+ assert_equal(0x02010403, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
+ assert_equal(0x03040102, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
+ assert_equal(0x04030201, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
+ end
+
+ def test_unpack_native_endian
+ assert_equal("\x12\x34".unpack("S!")[0], Bug::Bignum.test_unpack("\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
+ end
+
+ def test_unpack_nail
+ assert_equal(0b100011, Bug::Bignum.test_unpack("\x01\x00\x00\x00\x01\x01", 6, 1, 7, BIG_ENDIAN))
+ assert_equal(0x12345678, Bug::Bignum.test_unpack("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 4, BIG_ENDIAN))
+ assert_equal(0x12345678, Bug::Bignum.test_unpack("\x00\x12\x00\x34\x00\x56\x00\x78", 4, 2, 8, BIG_ENDIAN))
+ end
+
+ def test_unpack_sign
+ assert_equal(-1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN|NEGATIVE))
+ assert_equal(-0x8070605040302010, Bug::Bignum.test_unpack("\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN|NEGATIVE))
+ end
- end
-
- def test_unpack_zero
- assert_equal(0, Bug::Bignum.test_unpack("", 0, 1, 0, BIG_ENDIAN))
- end
-
- def test_unpack_argument_check
- assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 2, 1, 0, MSBYTE_FIRST) }
- assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 0, MSWORD_FIRST) }
- assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 0, 0, BIG_ENDIAN) }
- assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1, 8, BIG_ENDIAN) }
-
- # assume sizeof(ssize_t) == sizeof(intptr_t)
- assert_raise(ArgumentError) { Bug::Bignum.test_unpack("x", 1, 1 << ([""].pack("p").length * 8 - 1), 0, BIG_ENDIAN) }
- end
-
- def test_unpack_wordsize
- assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN))
- assert_equal(1, Bug::Bignum.test_unpack("\x00\x01", 1, 2, 0, BIG_ENDIAN))
- assert_equal(1, Bug::Bignum.test_unpack("\x00\x00\x01", 1, 3, 0, BIG_ENDIAN))
- assert_equal(1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, LITTLE_ENDIAN))
- assert_equal(1, Bug::Bignum.test_unpack("\x01\x00", 1, 2, 0, LITTLE_ENDIAN))
- assert_equal(1, Bug::Bignum.test_unpack("\x01\x00\x00", 1, 3, 0, LITTLE_ENDIAN))
- end
-
- def test_unpack_wordorder_and_endian
- assert_equal(0x01020304, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|MSBYTE_FIRST))
- assert_equal(0x02010403, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, MSWORD_FIRST|LSBYTE_FIRST))
- assert_equal(0x03040102, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|MSBYTE_FIRST))
- assert_equal(0x04030201, Bug::Bignum.test_unpack("\x01\x02\x03\x04", 2, 2, 0, LSWORD_FIRST|LSBYTE_FIRST))
- end
-
- def test_unpack_native_endian
- assert_equal("\x12\x34".unpack("S!")[0], Bug::Bignum.test_unpack("\x12\x34", 1, 2, 0, MSWORD_FIRST|NATIVE_BYTE_ORDER))
- end
-
- def test_unpack_nail
- assert_equal(0b100011, Bug::Bignum.test_unpack("\x01\x00\x00\x00\x01\x01", 6, 1, 7, BIG_ENDIAN))
- assert_equal(0x12345678, Bug::Bignum.test_unpack("\x01\x02\x03\x04\x05\x06\x07\x08", 8, 1, 4, BIG_ENDIAN))
- assert_equal(0x12345678, Bug::Bignum.test_unpack("\x00\x12\x00\x34\x00\x56\x00\x78", 4, 2, 8, BIG_ENDIAN))
- end
-
- def test_unpack_sign
- assert_equal(-1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, BIG_ENDIAN|NEGATIVE))
- assert_equal(-0x8070605040302010, Bug::Bignum.test_unpack("\x80\x70\x60\x50\x40\x30\x20\x10", 8, 1, 0, BIG_ENDIAN|NEGATIVE))
- end
-
- def test_unpack_orders
- [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
- [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
- 1.upto(16) {|wordsize|
- 1.upto(20) {|numwords|
- w = numwords*wordsize
- ary = []
- 0.upto(w) {|i|
- ary << ((i+1) % 256);
- }
- str = ary.pack("C*")
- flags = word_order|byte_order
- assert_equal(Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags|GENERIC),
- Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags),
- "Bug::Bignum.test_unpack(#{str.dump}, #{numwords}, #{wordsize}, 0, #{'%#x' % flags})")
+ def test_unpack_orders
+ [MSWORD_FIRST, LSWORD_FIRST].each {|word_order|
+ [MSBYTE_FIRST, LSBYTE_FIRST, NATIVE_BYTE_ORDER].each {|byte_order|
+ 1.upto(16) {|wordsize|
+ 1.upto(20) {|numwords|
+ w = numwords*wordsize
+ ary = []
+ 0.upto(w) {|i|
+ ary << ((i+1) % 256);
}
+ str = ary.pack("C*")
+ flags = word_order|byte_order
+ assert_equal(Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags|GENERIC),
+ Bug::Bignum.test_unpack(str, numwords, wordsize, 0, flags),
+ "Bug::Bignum.test_unpack(#{str.dump}, #{numwords}, #{wordsize}, 0, #{'%#x' % flags})")
}
}
}
- end
-
- def test_unpack2comp_single_byte
- assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal( -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal( -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal( 0, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal( 1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal( 2, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal( 127, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
- end
-
- def test_unpack2comp_sequence_of_ff
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*2, 2, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*3, 3, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*4, 4, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*5, 5, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*6, 6, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*7, 7, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*8, 8, 1, 0, TWOCOMP|BIG_ENDIAN))
- assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*9, 9, 1, 0, TWOCOMP|BIG_ENDIAN))
- end
-
- def test_unpack2comp_negative_single_byte
- assert_equal(-256, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
- assert_equal(-255, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
- assert_equal(-254, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
- assert_equal(-129, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
- assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
- assert_equal( -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
- assert_equal( -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
- end
-
- def test_unpack2comp_negative_zero
- 0.upto(100) {|n|
- str = "\x00"*n
- flags = TWOCOMP|BIG_ENDIAN|NEGATIVE
- assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags))
- flags = TWOCOMP|LITTLE_ENDIAN|NEGATIVE
- assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags),
- "Bug::Bignum.test_unpack(#{str.dump}, #{n}, 1, 0, #{'%#x' % flags})")
- }
- end
+ }
+ end
+
+ def test_unpack2comp_single_byte
+ assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal( -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal( -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal( 0, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal( 1, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal( 2, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal( 127, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN))
+ end
+
+ def test_unpack2comp_sequence_of_ff
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*2, 2, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*3, 3, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*4, 4, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*5, 5, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*6, 6, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*7, 7, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*8, 8, 1, 0, TWOCOMP|BIG_ENDIAN))
+ assert_equal(-1, Bug::Bignum.test_unpack("\xFF"*9, 9, 1, 0, TWOCOMP|BIG_ENDIAN))
+ end
+
+ def test_unpack2comp_negative_single_byte
+ assert_equal(-256, Bug::Bignum.test_unpack("\x00", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
+ assert_equal(-255, Bug::Bignum.test_unpack("\x01", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
+ assert_equal(-254, Bug::Bignum.test_unpack("\x02", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
+ assert_equal(-129, Bug::Bignum.test_unpack("\x7F", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
+ assert_equal(-128, Bug::Bignum.test_unpack("\x80", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
+ assert_equal( -2, Bug::Bignum.test_unpack("\xFE", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
+ assert_equal( -1, Bug::Bignum.test_unpack("\xFF", 1, 1, 0, TWOCOMP|BIG_ENDIAN|NEGATIVE))
+ end
+
+ def test_unpack2comp_negative_zero
+ 0.upto(100) {|n|
+ str = "\x00"*n
+ flags = TWOCOMP|BIG_ENDIAN|NEGATIVE
+ assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags))
+ flags = TWOCOMP|LITTLE_ENDIAN|NEGATIVE
+ assert_equal(-(256**n), Bug::Bignum.test_unpack(str, n, 1, 0, flags),
+ "Bug::Bignum.test_unpack(#{str.dump}, #{n}, 1, 0, #{'%#x' % flags})")
+ }
end
def test_numbits_2comp
@@ -395,5 +393,4 @@ class Test_Bignum < Test::Unit::TestCase
assert_equal(5, Bug::Bignum.test_numbytes_2comp_with_sign(0x7fffffffff))
assert_equal(6, Bug::Bignum.test_numbytes_2comp_with_sign(0x8000000000))
end
-
end
diff --git a/test/-ext-/bignum/test_str2big.rb b/test/-ext-/bignum/test_str2big.rb
index d5bd72a85b..d27e4d23f7 100644
--- a/test/-ext-/bignum/test_str2big.rb
+++ b/test/-ext-/bignum/test_str2big.rb
@@ -2,37 +2,35 @@
require 'test/unit'
require "-test-/bignum"
-class Test_Bignum < Test::Unit::TestCase
- class TestStr2big < Test::Unit::TestCase
+class TestBignum_Str2big < Test::Unit::TestCase
- SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
- BITSPERDIG = Bug::Bignum::BITSPERDIG
- BDIGMAX = (1 << BITSPERDIG) - 1
+ SIZEOF_BDIGIT = Bug::Bignum::SIZEOF_BDIGIT
+ BITSPERDIG = Bug::Bignum::BITSPERDIG
+ BDIGMAX = (1 << BITSPERDIG) - 1
- def test_str2big_poweroftwo
- s = "1" + "0" * 1000
- n = 16 ** 1000
- assert_equal(n, Bug::Bignum.str2big_poweroftwo(s, 16, true))
- end
-
- def test_str2big_normal
- s = "1" + "0" * 1000
- n = 10 ** 1000
- assert_equal(n, Bug::Bignum.str2big_normal(s, 10, true))
- end
+ def test_str2big_poweroftwo
+ s = "1" + "0" * 1000
+ n = 16 ** 1000
+ assert_equal(n, Bug::Bignum.str2big_poweroftwo(s, 16, true))
+ end
- def test_str2big_karatsuba
- s = "1" + "0" * 1000
- n = 10 ** 1000
- assert_equal(n, Bug::Bignum.str2big_karatsuba(s, 10, true))
- end
+ def test_str2big_normal
+ s = "1" + "0" * 1000
+ n = 10 ** 1000
+ assert_equal(n, Bug::Bignum.str2big_normal(s, 10, true))
+ end
- def test_str2big_gmp
- s = "1" + "0" * 1000
- n = 10 ** 1000
- assert_equal(n, Bug::Bignum.str2big_gmp(s, 10, true))
- rescue NotImplementedError
- end
+ def test_str2big_karatsuba
+ s = "1" + "0" * 1000
+ n = 10 ** 1000
+ assert_equal(n, Bug::Bignum.str2big_karatsuba(s, 10, true))
+ end
+ def test_str2big_gmp
+ s = "1" + "0" * 1000
+ n = 10 ** 1000
+ assert_equal(n, Bug::Bignum.str2big_gmp(s, 10, true))
+ rescue NotImplementedError
end
+
end
diff --git a/test/-ext-/funcall/test_funcall.rb b/test/-ext-/funcall/test_funcall.rb
deleted file mode 100644
index 01a03bf5ef..0000000000
--- a/test/-ext-/funcall/test_funcall.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-require 'test/unit'
-
-class TestFuncall < Test::Unit::TestCase
- require '-test-/funcall'
-
- def test_funcall_extra_args
- assert_equal 'TestFuncall', TestFuncall.extra_args_name,
- '[ruby-core:85266] [Bug #14425]'
- end
-end
diff --git a/test/-ext-/funcall/test_passing_block.rb b/test/-ext-/funcall/test_passing_block.rb
index 71c9d905be..8964403494 100644
--- a/test/-ext-/funcall/test_passing_block.rb
+++ b/test/-ext-/funcall/test_passing_block.rb
@@ -9,6 +9,11 @@ class TestFuncall < Test::Unit::TestCase
end
require '-test-/funcall'
+ def test_funcall_extra_args
+ assert_equal 'TestFuncall', TestFuncall.extra_args_name,
+ '[ruby-core:85266] [Bug #14425]'
+ end
+
def test_with_funcall2
ok = nil
Relay.with_funcall2("feature#4504") {|arg| ok = arg || true}
diff --git a/test/date/test_date_ractor.rb b/test/date/test_date_ractor.rb
index 7b0c3f4911..7ec953d87a 100644
--- a/test/date/test_date_ractor.rb
+++ b/test/date/test_date_ractor.rb
@@ -2,7 +2,7 @@
require 'test/unit'
require 'date'
-class TestDateParse < Test::Unit::TestCase
+class TestDateParseRactor < Test::Unit::TestCase
def code(klass = Date, share: false)
<<~RUBY.gsub('Date', klass.name)
share = #{share}
diff --git a/test/fileutils/clobber.rb b/test/fileutils/clobber.rb
index fdcecd5e08..ac5c8c79c0 100644
--- a/test/fileutils/clobber.rb
+++ b/test/fileutils/clobber.rb
@@ -4,10 +4,7 @@ require 'test/unit'
require 'tmpdir'
require_relative 'fileasserts'
-class TestFileUtils < Test::Unit::TestCase
-end
-
-module TestFileUtils::Clobber
+module TestFileUtilsClobber
include Test::Unit::FileAssertions
def my_rm_rf(path)
diff --git a/test/fileutils/test_dryrun.rb b/test/fileutils/test_dryrun.rb
index fd8a7805ec..a3efbb4bdf 100644
--- a/test/fileutils/test_dryrun.rb
+++ b/test/fileutils/test_dryrun.rb
@@ -8,7 +8,7 @@ require_relative 'visibility_tests'
class TestFileUtilsDryRun < Test::Unit::TestCase
include FileUtils::DryRun
- include TestFileUtilsInc::Visibility
+ include TestFileUtilsIncVisibility
def setup
super
diff --git a/test/fileutils/test_nowrite.rb b/test/fileutils/test_nowrite.rb
index 543fa39f5a..659fa20886 100644
--- a/test/fileutils/test_nowrite.rb
+++ b/test/fileutils/test_nowrite.rb
@@ -8,7 +8,7 @@ require_relative 'visibility_tests'
class TestFileUtilsNoWrite < Test::Unit::TestCase
include FileUtils::NoWrite
- include TestFileUtilsInc::Visibility
+ include TestFileUtilsIncVisibility
def setup
super
diff --git a/test/fileutils/test_verbose.rb b/test/fileutils/test_verbose.rb
index cf65be8e03..7987af2395 100644
--- a/test/fileutils/test_verbose.rb
+++ b/test/fileutils/test_verbose.rb
@@ -8,7 +8,7 @@ require_relative 'visibility_tests'
class TestFileUtilsVerbose < Test::Unit::TestCase
include FileUtils::Verbose
- include TestFileUtilsInc::Visibility
+ include TestFileUtilsIncVisibility
def setup
super
diff --git a/test/fileutils/visibility_tests.rb b/test/fileutils/visibility_tests.rb
index 4c02c9d207..9f8f8dc9e1 100644
--- a/test/fileutils/visibility_tests.rb
+++ b/test/fileutils/visibility_tests.rb
@@ -2,14 +2,11 @@
require 'test/unit'
require 'fileutils'
-class TestFileUtilsInc < Test::Unit::TestCase
-end
-
##
# These tests are reused in the FileUtils::Verbose, FileUtils::NoWrite and
# FileUtils::DryRun tests
-module TestFileUtilsInc::Visibility
+module TestFileUtilsIncVisibility
FileUtils::METHODS.each do |m|
define_method "test_singleton_visibility_#{m}" do
diff --git a/test/mkmf/base.rb b/test/mkmf/base.rb
index 4f67478a56..e097c396d6 100644
--- a/test/mkmf/base.rb
+++ b/test/mkmf/base.rb
@@ -20,134 +20,131 @@ $INCFLAGS << " -I."
$extout_prefix = "$(extout)$(target_prefix)/"
class TestMkmf < Test::Unit::TestCase
-end
-
-module TestMkmf::Base
- MKMFLOG = proc {File.read("mkmf.log") rescue ""}
+ module Base
+ MKMFLOG = proc {File.read("mkmf.log") rescue ""}
- class Capture
- attr_accessor :origin
- def initialize
- @buffer = ""
- @filter = nil
- @out = true
- @origin = nil
- end
- def clear
- @buffer.clear
- end
- def flush
- STDOUT.print @filter ? @filter.call(@buffer) : @buffer
- clear
- end
- def reopen(io)
- case io
- when Capture
- initialize_copy(io)
- when File
- @out = false
- @origin.reopen(io) if @origin
- when IO
+ class Capture
+ attr_accessor :origin
+ def initialize
+ @buffer = ""
+ @filter = nil
@out = true
- @origin.reopen(io) if @origin
- else
- @out = false
+ @origin = nil
end
- end
- def filter(&block)
- @filter = block
- end
- def write(*s)
- if @out
- @buffer.concat(*s)
- elsif @origin
- @origin.write(*s)
+ def clear
+ @buffer.clear
+ end
+ def flush
+ STDOUT.print @filter ? @filter.call(@buffer) : @buffer
+ clear
+ end
+ def reopen(io)
+ case io
+ when Capture
+ initialize_copy(io)
+ when File
+ @out = false
+ @origin.reopen(io) if @origin
+ when IO
+ @out = true
+ @origin.reopen(io) if @origin
+ else
+ @out = false
+ end
+ end
+ def filter(&block)
+ @filter = block
+ end
+ def write(*s)
+ if @out
+ @buffer.concat(*s)
+ elsif @origin
+ @origin.write(*s)
+ end
end
end
- end
- attr_reader :stdout
+ attr_reader :stdout
- def mkmflog(msg)
- proc {MKMFLOG[] << msg}
- end
+ def mkmflog(msg)
+ proc {MKMFLOG[] << msg}
+ end
- def setup
- @rbconfig = rbconfig0 = RbConfig::CONFIG
- @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG
- rbconfig = {
- "hdrdir" => $hdrdir,
- "srcdir" => $srcdir,
- "topdir" => $topdir,
- }
- mkconfig = {
- "hdrdir" => "$(top_srcdir)/include",
- "srcdir" => "$(top_srcdir)",
- "topdir" => $topdir,
- }
- rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup}
- mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup}
- RbConfig.module_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, rbconfig)
- remove_const(:MAKEFILE_CONFIG)
- const_set(:MAKEFILE_CONFIG, mkconfig)
- }
- MakeMakefile.class_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, mkconfig)
- }
- @tmpdir = Dir.mktmpdir
- @curdir = Dir.pwd
- @mkmfobj = Object.new
- @stdout = Capture.new
- Dir.chdir(@tmpdir)
- @quiet, Logging.quiet = Logging.quiet, true
- init_mkmf
- $INCFLAGS[0, 0] = "-I. "
- end
+ def setup
+ @rbconfig = rbconfig0 = RbConfig::CONFIG
+ @mkconfig = mkconfig0 = RbConfig::MAKEFILE_CONFIG
+ rbconfig = {
+ "hdrdir" => $hdrdir,
+ "srcdir" => $srcdir,
+ "topdir" => $topdir,
+ }
+ mkconfig = {
+ "hdrdir" => "$(top_srcdir)/include",
+ "srcdir" => "$(top_srcdir)",
+ "topdir" => $topdir,
+ }
+ rbconfig0.each_pair {|key, val| rbconfig[key] ||= val.dup}
+ mkconfig0.each_pair {|key, val| mkconfig[key] ||= val.dup}
+ RbConfig.module_eval {
+ remove_const(:CONFIG)
+ const_set(:CONFIG, rbconfig)
+ remove_const(:MAKEFILE_CONFIG)
+ const_set(:MAKEFILE_CONFIG, mkconfig)
+ }
+ MakeMakefile.class_eval {
+ remove_const(:CONFIG)
+ const_set(:CONFIG, mkconfig)
+ }
+ @tmpdir = Dir.mktmpdir
+ @curdir = Dir.pwd
+ @mkmfobj = Object.new
+ @stdout = Capture.new
+ Dir.chdir(@tmpdir)
+ @quiet, Logging.quiet = Logging.quiet, true
+ init_mkmf
+ $INCFLAGS[0, 0] = "-I. "
+ end
- def teardown
- rbconfig0 = @rbconfig
- mkconfig0 = @mkconfig
- RbConfig.module_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, rbconfig0)
- remove_const(:MAKEFILE_CONFIG)
- const_set(:MAKEFILE_CONFIG, mkconfig0)
- }
- MakeMakefile.class_eval {
- remove_const(:CONFIG)
- const_set(:CONFIG, mkconfig0)
- }
- Logging.quiet = @quiet
- Logging.log_close
- FileUtils.rm_f("mkmf.log")
- Dir.chdir(@curdir)
- FileUtils.rm_rf(@tmpdir)
- end
+ def teardown
+ rbconfig0 = @rbconfig
+ mkconfig0 = @mkconfig
+ RbConfig.module_eval {
+ remove_const(:CONFIG)
+ const_set(:CONFIG, rbconfig0)
+ remove_const(:MAKEFILE_CONFIG)
+ const_set(:MAKEFILE_CONFIG, mkconfig0)
+ }
+ MakeMakefile.class_eval {
+ remove_const(:CONFIG)
+ const_set(:CONFIG, mkconfig0)
+ }
+ Logging.quiet = @quiet
+ Logging.log_close
+ FileUtils.rm_f("mkmf.log")
+ Dir.chdir(@curdir)
+ FileUtils.rm_rf(@tmpdir)
+ end
- def mkmf(*args, &block)
- @stdout.clear
- stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout
- verbose, $VERBOSE = $VERBOSE, false
- @mkmfobj.instance_eval(*args, &block)
- ensure
- $VERBOSE = verbose
- $stdout, @stdout.origin = @stdout.origin, stdout
- end
+ def mkmf(*args, &block)
+ @stdout.clear
+ stdout, @stdout.origin, $stdout = @stdout.origin, $stdout, @stdout
+ verbose, $VERBOSE = $VERBOSE, false
+ @mkmfobj.instance_eval(*args, &block)
+ ensure
+ $VERBOSE = verbose
+ $stdout, @stdout.origin = @stdout.origin, stdout
+ end
- def config_value(name)
- create_tmpsrc("---config-value=#{name}")
- xpopen(cpp_command('')) do |f|
- f.grep(/^---config-value=(.*)/) {return $1}
+ def config_value(name)
+ create_tmpsrc("---config-value=#{name}")
+ xpopen(cpp_command('')) do |f|
+ f.grep(/^---config-value=(.*)/) {return $1}
+ end
+ nil
end
- nil
end
-end
-class TestMkmf
- include TestMkmf::Base
+ include Base
def assert_separately(args, src, *rest, **options)
super(args + ["-r#{__FILE__}"], "extend TestMkmf::Base; setup\nEND{teardown}\n#{src}", *rest, **options)
diff --git a/test/mkmf/test_config.rb b/test/mkmf/test_config.rb
index 07ed641415..3878db1964 100644
--- a/test/mkmf/test_config.rb
+++ b/test/mkmf/test_config.rb
@@ -4,14 +4,12 @@ $extmk = true
require 'test/unit'
require 'mkmf'
-class TestMkmf < Test::Unit::TestCase
- class TestConfig < Test::Unit::TestCase
- def test_dir_config
- bug8074 = '[Bug #8074]'
- lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"")
- assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{
- assert_equal(%w[/test/foo/include /test/foo#{lib}], dir_config("foo"), #{bug8074.dump})
- }
- end
+class TestMkmfConfig < Test::Unit::TestCase
+ def test_dir_config
+ bug8074 = '[Bug #8074]'
+ lib = RbConfig.expand(RbConfig::MAKEFILE_CONFIG["libdir"], "exec_prefix"=>"")
+ assert_separately %w[-rmkmf - -- --with-foo-dir=/test/foo], %{
+ assert_equal(%w[/test/foo/include /test/foo#{lib}], dir_config("foo"), #{bug8074.dump})
+ }
end
end
diff --git a/test/mkmf/test_constant.rb b/test/mkmf/test_constant.rb
index f5a87a1caa..f6834c7f28 100644
--- a/test/mkmf/test_constant.rb
+++ b/test/mkmf/test_constant.rb
@@ -1,38 +1,36 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestTryConstant < TestMkmf
- def test_simple
- assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG)
- assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG)
- assert_equal(-1, mkmf {try_constant("-1")}, MKMFLOG)
- end
-
- def test_sizeof
- assert_equal(config_value("SIZEOF_INT").to_i, mkmf {try_constant("sizeof(int)")}, MKMFLOG)
- assert_equal(config_value("SIZEOF_LONG").to_i, mkmf {try_constant("sizeof(long)")}, MKMFLOG)
- assert_equal(config_value("SIZEOF_VOIDP").to_i, mkmf {try_constant("sizeof(void*)")}, MKMFLOG)
- assert_equal(config_value("SIZEOF_VALUE").to_i, mkmf {try_constant("sizeof(Qnil)")}, MKMFLOG)
- end
+class TestMkmfTryConstant < TestMkmf
+ def test_simple
+ assert_equal( 0, mkmf {try_constant("0")}, MKMFLOG)
+ assert_equal( 1, mkmf {try_constant("1")}, MKMFLOG)
+ assert_equal(-1, mkmf {try_constant("-1")}, MKMFLOG)
+ end
- def test_long
- sizeof_int = config_value("SIZEOF_INT").to_i
- sizeof_long = config_value("SIZEOF_LONG").to_i
- if sizeof_long > sizeof_int
- type = 'long'
- else
- sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
- return if !sizeof_long_long or sizeof_long_long <= sizeof_int
- type = 'LONG_LONG'
- end
+ def test_sizeof
+ assert_equal(config_value("SIZEOF_INT").to_i, mkmf {try_constant("sizeof(int)")}, MKMFLOG)
+ assert_equal(config_value("SIZEOF_LONG").to_i, mkmf {try_constant("sizeof(long)")}, MKMFLOG)
+ assert_equal(config_value("SIZEOF_VOIDP").to_i, mkmf {try_constant("sizeof(void*)")}, MKMFLOG)
+ assert_equal(config_value("SIZEOF_VALUE").to_i, mkmf {try_constant("sizeof(Qnil)")}, MKMFLOG)
+ end
- decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))"
- assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG)
+ def test_long
+ sizeof_int = config_value("SIZEOF_INT").to_i
+ sizeof_long = config_value("SIZEOF_LONG").to_i
+ if sizeof_long > sizeof_int
+ type = 'long'
+ else
+ sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
+ return if !sizeof_long_long or sizeof_long_long <= sizeof_int
+ type = 'LONG_LONG'
end
- def test_large_unsigned
- assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG)
- end
+ decl = "#define CONFTEST_VALUE (unsigned #{type})(((unsigned #{type})1)<<(CHAR_BIT*sizeof(int)))"
+ assert_operator(mkmf {try_constant("CONFTEST_VALUE", [[decl]])}, :>, 0, MKMFLOG)
+ end
+
+ def test_large_unsigned
+ assert_operator(mkmf {try_constant("1U<<(CHAR_BIT*sizeof(int)-1)")}, :>, 0, MKMFLOG)
end
end
diff --git a/test/mkmf/test_convertible.rb b/test/mkmf/test_convertible.rb
index 1baf892842..d65db4265b 100644
--- a/test/mkmf/test_convertible.rb
+++ b/test/mkmf/test_convertible.rb
@@ -1,35 +1,33 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestConvertible < TestMkmf
- def test_typeof_builtin
- ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
- %w[short int long].each do |type|
- assert_equal((prefix || signed)+type,
- mkmf {convertible_int(signed+type)}, MKMFLOG)
- end
+class TestMkmfConvertible < TestMkmf
+ def test_typeof_builtin
+ ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
+ %w[short int long].each do |type|
+ assert_equal((prefix || signed)+type,
+ mkmf {convertible_int(signed+type)}, MKMFLOG)
end
end
+ end
- def test_typeof_typedef
- ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
- %w[short int long].each do |type|
- open("confdefs.h", "w") {|f|
- f.puts "typedef #{signed}#{type} test1_t;"
- }
- $defs.clear
- assert_equal((prefix || signed)+type,
- mkmf {convertible_int("test1_t", "confdefs.h")}, MKMFLOG)
- (u = signed[/^u/]) and u.upcase!
- assert_include($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote)
- assert_include($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX")
- assert_include($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM")
- assert_include($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}")
- end
+ def test_typeof_typedef
+ ["", ["signed ", ""], "unsigned "].each do |signed, prefix|
+ %w[short int long].each do |type|
+ open("confdefs.h", "w") {|f|
+ f.puts "typedef #{signed}#{type} test1_t;"
+ }
+ $defs.clear
+ assert_equal((prefix || signed)+type,
+ mkmf {convertible_int("test1_t", "confdefs.h")}, MKMFLOG)
+ (u = signed[/^u/]) and u.upcase!
+ assert_include($defs, "-DTYPEOF_TEST1_T="+"#{prefix||signed}#{type}".quote)
+ assert_include($defs, "-DPRI_TEST1T_PREFIX=PRI_#{type.upcase}_PREFIX")
+ assert_include($defs, "-DTEST1T2NUM=#{u}#{type.upcase}2NUM")
+ assert_include($defs, "-DNUM2TEST1T=NUM2#{u}#{type.upcase}")
end
- ensure
- File.unlink("confdefs.h")
end
+ ensure
+ File.unlink("confdefs.h")
end
end
diff --git a/test/mkmf/test_egrep_cpp.rb b/test/mkmf/test_egrep_cpp.rb
index ce276bef20..7ac0e60010 100644
--- a/test/mkmf/test_egrep_cpp.rb
+++ b/test/mkmf/test_egrep_cpp.rb
@@ -2,14 +2,12 @@
require_relative 'base'
require 'tempfile'
-class TestMkmf
- class TestEgrepCpp < TestMkmf
- def test_egrep_cpp
- assert_equal(true, egrep_cpp(/ruby_init/, ""), MKMFLOG)
- end
+class TestMkmfEgrepCpp < TestMkmf
+ def test_egrep_cpp
+ assert_equal(true, egrep_cpp(/ruby_init/, ""), MKMFLOG)
+ end
- def test_not_have_func
- assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG)
- end
+ def test_not_have_func
+ assert_equal(false, egrep_cpp(/never match/, ""), MKMFLOG)
end
end
diff --git a/test/mkmf/test_find_executable.rb b/test/mkmf/test_find_executable.rb
index 7ffc28ecc8..88b70c21c0 100644
--- a/test/mkmf/test_find_executable.rb
+++ b/test/mkmf/test_find_executable.rb
@@ -1,58 +1,56 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestFindExecutable < TestMkmf
- def setup
- super
- @path, ENV["PATH"] = ENV["PATH"], @tmpdir
- end
+class TestMkmfFindExecutable < TestMkmf
+ def setup
+ super
+ @path, ENV["PATH"] = ENV["PATH"], @tmpdir
+ end
- def each_exts(&block)
- name = "foobar#{$$}#{rand(1000)}"
- stdout.filter {|s| s.sub(name, "<executable>")}
- exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
- exts[0] ||= ""
- exts.each do |ext|
- yield name+ext, name
- end
+ def each_exts(&block)
+ name = "foobar#{$$}#{rand(1000)}"
+ stdout.filter {|s| s.sub(name, "<executable>")}
+ exts = mkmf {self.class::CONFIG['EXECUTABLE_EXTS']}.split
+ exts[0] ||= ""
+ exts.each do |ext|
+ yield name+ext, name
end
+ end
- def teardown
- ENV["PATH"] = @path
- super
- end
+ def teardown
+ ENV["PATH"] = @path
+ super
+ end
- def test_find_executable
- bug2669 = '[ruby-core:27912]'
- each_exts do |full, name|
- begin
- open(full, "w") {|ff| ff.chmod(0755)}
- result = mkmf {find_executable(name)}
- ensure
- File.unlink(full)
- end
- assert_equal("#{@tmpdir}/#{full}", result, bug2669)
+ def test_find_executable
+ bug2669 = '[ruby-core:27912]'
+ each_exts do |full, name|
+ begin
+ open(full, "w") {|ff| ff.chmod(0755)}
+ result = mkmf {find_executable(name)}
+ ensure
+ File.unlink(full)
end
+ assert_equal("#{@tmpdir}/#{full}", result, bug2669)
end
+ end
- def test_find_executable_dir
- each_exts do |full, name|
- begin
- Dir.mkdir(full)
- result = mkmf {find_executable(name)}
- ensure
- Dir.rmdir(full)
- end
- assert_nil(result)
+ def test_find_executable_dir
+ each_exts do |full, name|
+ begin
+ Dir.mkdir(full)
+ result = mkmf {find_executable(name)}
+ ensure
+ Dir.rmdir(full)
end
+ assert_nil(result)
end
+ end
- if /mingw|mswin/ =~ RUBY_PLATFORM
- def test_quoted_path_on_windows
- ENV["PATH"] = %["#{@tmpdir}"]
- test_find_executable
- end
+ if /mingw|mswin/ =~ RUBY_PLATFORM
+ def test_quoted_path_on_windows
+ ENV["PATH"] = %["#{@tmpdir}"]
+ test_find_executable
end
end
end
diff --git a/test/mkmf/test_flags.rb b/test/mkmf/test_flags.rb
index b28ac5d672..aedf06b610 100644
--- a/test/mkmf/test_flags.rb
+++ b/test/mkmf/test_flags.rb
@@ -1,57 +1,55 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestFlags < TestMkmf
- def test_valid_warnflags
- val = $extmk
- warnflags = $warnflags
- makefile = mkmf do
- $extmk = false
- self.class::CONFIG['warnflags'] = %w"-Wextra
- -Wno-unused-parameter -Wno-parentheses -Wno-long-long
- -Wno-missing-field-initializers -Werror=pointer-arith
- -Werror=write-strings -Werror=declaration-after-statement
- -Werror=shorten-64-to-32
- -Werror-implicit-function-declaration
- ".join(' ')
- self.class::CONFIG['GCC'] = 'yes'
- init_mkmf(self.class::CONFIG)
- configuration '.'
- end
- generated_flags = makefile.grep(/warnflags/).first[/^warnflags = (.*)$/, 1].split
+class TestMkmfFlags < TestMkmf
+ def test_valid_warnflags
+ val = $extmk
+ warnflags = $warnflags
+ makefile = mkmf do
+ $extmk = false
+ self.class::CONFIG['warnflags'] = %w"-Wextra
+ -Wno-unused-parameter -Wno-parentheses -Wno-long-long
+ -Wno-missing-field-initializers -Werror=pointer-arith
+ -Werror=write-strings -Werror=declaration-after-statement
+ -Werror=shorten-64-to-32
+ -Werror-implicit-function-declaration
+ ".join(' ')
+ self.class::CONFIG['GCC'] = 'yes'
+ init_mkmf(self.class::CONFIG)
+ configuration '.'
+ end
+ generated_flags = makefile.grep(/warnflags/).first[/^warnflags = (.*)$/, 1].split
- assert_equal %w"
- -Wextra -Wno-unused-parameter -Wno-parentheses
- -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith
- -Wwrite-strings -Wdeclaration-after-statement
- -Wshorten-64-to-32 -Werror-implicit-function-declaration
- ", generated_flags
+ assert_equal %w"
+ -Wextra -Wno-unused-parameter -Wno-parentheses
+ -Wno-long-long -Wno-missing-field-initializers -Wpointer-arith
+ -Wwrite-strings -Wdeclaration-after-statement
+ -Wshorten-64-to-32 -Werror-implicit-function-declaration
+ ", generated_flags
- ensure
- $warnflags = warnflags
- $extmk = val
- end
+ ensure
+ $warnflags = warnflags
+ $extmk = val
+ end
- def test_try_ldflag_invalid_opt
- assert_separately([], <<-'end;') #do
- assert(!try_ldflags("nosuch.c"), TestMkmf::MKMFLOG)
- assert(have_devel?, TestMkmf::MKMFLOG)
- end;
- end
+ def test_try_ldflag_invalid_opt
+ assert_separately([], <<-'end;') #do
+ assert(!try_ldflags("nosuch.c"), TestMkmf::MKMFLOG)
+ assert(have_devel?, TestMkmf::MKMFLOG)
+ end;
+ end
- def test_try_cflag_invalid_opt
- assert_separately([], <<-'end;', timeout: 30) #do
- assert(!try_cflags("nosuch.c"), TestMkmf::MKMFLOG)
- assert(have_devel?, TestMkmf::MKMFLOG)
- end;
- end
+ def test_try_cflag_invalid_opt
+ assert_separately([], <<-'end;', timeout: 30) #do
+ assert(!try_cflags("nosuch.c"), TestMkmf::MKMFLOG)
+ assert(have_devel?, TestMkmf::MKMFLOG)
+ end;
+ end
- def test_try_cppflag_invalid_opt
- assert_separately([], <<-'end;') #do
- assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG)
- assert(have_devel?, TestMkmf::MKMFLOG)
- end;
- end
+ def test_try_cppflag_invalid_opt
+ assert_separately([], <<-'end;') #do
+ assert(!try_cppflags("nosuch.c"), TestMkmf::MKMFLOG)
+ assert(have_devel?, TestMkmf::MKMFLOG)
+ end;
end
end
diff --git a/test/mkmf/test_framework.rb b/test/mkmf/test_framework.rb
index ba15299ae0..3245e43c75 100644
--- a/test/mkmf/test_framework.rb
+++ b/test/mkmf/test_framework.rb
@@ -1,49 +1,47 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestHaveFramework < TestMkmf
- def create_framework(fw, hdrname = "#{fw}.h")
- Dir.mktmpdir("frameworks") do |dir|
- fwdir = "#{dir}/#{fw}.framework"
- hdrdir = "#{fwdir}/Headers"
- FileUtils.mkdir_p(hdrdir)
- File.write("#{hdrdir}/#{hdrname}", "")
- src = "#{fwdir}/main.c"
- File.write(src, "void #{fw}(void) {}\n")
- cmd = LINK_SO.dup
- RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src))
- cmd.gsub!("$@", "#{fwdir}/#{fw}")
- cmd.gsub!(/ -bundle /, ' -dynamiclib ')
- assert(xsystem(cmd), MKMFLOG)
- $INCFLAGS << " " << "-F#{dir}".quote
- yield fw, hdrname
- end
+class TestMkmfHaveFramework < TestMkmf
+ def create_framework(fw, hdrname = "#{fw}.h")
+ Dir.mktmpdir("frameworks") do |dir|
+ fwdir = "#{dir}/#{fw}.framework"
+ hdrdir = "#{fwdir}/Headers"
+ FileUtils.mkdir_p(hdrdir)
+ File.write("#{hdrdir}/#{hdrname}", "")
+ src = "#{fwdir}/main.c"
+ File.write(src, "void #{fw}(void) {}\n")
+ cmd = LINK_SO.dup
+ RbConfig.expand(cmd, RbConfig::CONFIG.merge("OBJS"=>src))
+ cmd.gsub!("$@", "#{fwdir}/#{fw}")
+ cmd.gsub!(/ -bundle /, ' -dynamiclib ')
+ assert(xsystem(cmd), MKMFLOG)
+ $INCFLAGS << " " << "-F#{dir}".quote
+ yield fw, hdrname
end
+ end
- def test_single_framework
- assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
- end
+ def test_single_framework
+ assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
+ end
- def test_multi_frameworks
- assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
- create_framework("MkmfTest") do |fw|
- assert(have_framework(fw), MKMFLOG)
- end
+ def test_multi_frameworks
+ assert(have_framework(%w"Ruby ruby.h"), mkmflog("try as Objective-C"))
+ create_framework("MkmfTest") do |fw|
+ assert(have_framework(fw), MKMFLOG)
end
+ end
- def test_empty_framework
- create_framework("MkmfTest") do |fw|
- assert(have_framework(fw), MKMFLOG)
- end
+ def test_empty_framework
+ create_framework("MkmfTest") do |fw|
+ assert(have_framework(fw), MKMFLOG)
end
+ end
- def test_different_name_header
- _bug8593 = '[ruby-core:55745] [Bug #8593]'
- create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname|
- assert(!have_framework(fw), MKMFLOG)
- assert(have_framework([fw, hdrname]), MKMFLOG)
- end
+ def test_different_name_header
+ _bug8593 = '[ruby-core:55745] [Bug #8593]'
+ create_framework("MkmfTest", "test_mkmf.h") do |fw, hdrname|
+ assert(!have_framework(fw), MKMFLOG)
+ assert(have_framework([fw, hdrname]), MKMFLOG)
end
end
end if /darwin/ =~ RUBY_PLATFORM
diff --git a/test/mkmf/test_have_func.rb b/test/mkmf/test_have_func.rb
index 6204ab24f0..521a0bb435 100644
--- a/test/mkmf/test_have_func.rb
+++ b/test/mkmf/test_have_func.rb
@@ -2,16 +2,14 @@
require_relative 'base'
require 'tempfile'
-class TestMkmf
- class TestHaveFunc < TestMkmf
- def test_have_func
- assert_equal(true, have_func("ruby_init"), MKMFLOG)
- assert_include($defs, '-DHAVE_RUBY_INIT')
- end
+class TestMkmfHaveFunc < TestMkmf
+ def test_have_func
+ assert_equal(true, have_func("ruby_init"), MKMFLOG)
+ assert_include($defs, '-DHAVE_RUBY_INIT')
+ end
- def test_not_have_func
- assert_equal(false, have_func("no_ruby_init"), MKMFLOG)
- assert_not_include($defs, '-DHAVE_RUBY_INIT')
- end
+ def test_not_have_func
+ assert_equal(false, have_func("no_ruby_init"), MKMFLOG)
+ assert_not_include($defs, '-DHAVE_RUBY_INIT')
end
end
diff --git a/test/mkmf/test_have_library.rb b/test/mkmf/test_have_library.rb
index bb9ce6972d..e34a9b06da 100644
--- a/test/mkmf/test_have_library.rb
+++ b/test/mkmf/test_have_library.rb
@@ -2,55 +2,53 @@
require_relative 'base'
require 'tempfile'
-class TestMkmf
- class TestHaveLibrary < TestMkmf
- LIBRARY_NAME = 'mkmftest'
- HEADER_NAME = "#{LIBRARY_NAME}.h"
- FUNC_NAME = 'ruby_mkmftest_foo'
- ARPREFIX = config_string('LIBRUBY_A') {|lib| lib[/\A\w+/]}
-
- def create_library(libname = LIBRARY_NAME)
- lib = "#{ARPREFIX}#{libname}.#{$LIBEXT}"
- open(HEADER_NAME, "w") do |hdr|
- hdr.puts "void #{FUNC_NAME}(void);"
- hdr.puts "void #{FUNC_NAME}_fake(void);"
- end
- create_tmpsrc("#include \"#{HEADER_NAME}\"\n""void #{FUNC_NAME}(void) {}")
- assert(xsystem(cc_command), "compile failed: #{cc_command}")
- command = "#{CONFIG['AR']} #{config_string('ARFLAGS') || 'cru '}#{lib} #{CONFTEST}.#{$OBJEXT}"
- assert(xsystem(command), "making library failed: #{command}")
- File.unlink("#{CONFTEST}.#{$OBJEXT}")
- config_string('RANLIB') do |ranlib|
- command = "#{ranlib} #{lib}"
- assert(xsystem(command), "ranlib failed: #{command}")
- end
+class TestMkmfHaveLibrary < TestMkmf
+ LIBRARY_NAME = 'mkmftest'
+ HEADER_NAME = "#{LIBRARY_NAME}.h"
+ FUNC_NAME = 'ruby_mkmftest_foo'
+ ARPREFIX = config_string('LIBRUBY_A') {|lib| lib[/\A\w+/]}
+
+ def create_library(libname = LIBRARY_NAME)
+ lib = "#{ARPREFIX}#{libname}.#{$LIBEXT}"
+ open(HEADER_NAME, "w") do |hdr|
+ hdr.puts "void #{FUNC_NAME}(void);"
+ hdr.puts "void #{FUNC_NAME}_fake(void);"
end
-
- def assert_have_library(*args)
- assert_equal(true, have_library(LIBRARY_NAME, *args), MKMFLOG)
+ create_tmpsrc("#include \"#{HEADER_NAME}\"\n""void #{FUNC_NAME}(void) {}")
+ assert(xsystem(cc_command), "compile failed: #{cc_command}")
+ command = "#{CONFIG['AR']} #{config_string('ARFLAGS') || 'cru '}#{lib} #{CONFTEST}.#{$OBJEXT}"
+ assert(xsystem(command), "making library failed: #{command}")
+ File.unlink("#{CONFTEST}.#{$OBJEXT}")
+ config_string('RANLIB') do |ranlib|
+ command = "#{ranlib} #{lib}"
+ assert(xsystem(command), "ranlib failed: #{command}")
end
+ end
- def assert_not_have_library(*args)
- assert_equal(false, have_library(LIBRARY_NAME, *args), MKMFLOG)
- end
+ def assert_have_library(*args)
+ assert_equal(true, have_library(LIBRARY_NAME, *args), MKMFLOG)
+ end
- def test_have_library
- create_library
- assert_have_library
- end
+ def assert_not_have_library(*args)
+ assert_equal(false, have_library(LIBRARY_NAME, *args), MKMFLOG)
+ end
- def test_have_library_with_name
- create_library
- assert_have_library(FUNC_NAME, HEADER_NAME)
- end
+ def test_have_library
+ create_library
+ assert_have_library
+ end
- def test_not_have_library
- assert_not_have_library
- end
+ def test_have_library_with_name
+ create_library
+ assert_have_library(FUNC_NAME, HEADER_NAME)
+ end
- def test_not_have_library_with_name
- create_library
- assert_not_have_library("#{FUNC_NAME}_fake", HEADER_NAME)
- end
+ def test_not_have_library
+ assert_not_have_library
+ end
+
+ def test_not_have_library_with_name
+ create_library
+ assert_not_have_library("#{FUNC_NAME}_fake", HEADER_NAME)
end
end
diff --git a/test/mkmf/test_have_macro.rb b/test/mkmf/test_have_macro.rb
index ebc5648097..3178bfea0b 100644
--- a/test/mkmf/test_have_macro.rb
+++ b/test/mkmf/test_have_macro.rb
@@ -2,35 +2,33 @@
require_relative 'base'
require 'tempfile'
-class TestMkmf
- class TestHaveMacro < TestMkmf
- MACRO_NAME = "RUBY_MKMFTEST_FOOBAR"
+class TestMkmfHaveMacro < TestMkmf
+ MACRO_NAME = "RUBY_MKMFTEST_FOOBAR"
- def test_have_macro_opt
- assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG)
- end
+ def test_have_macro_opt
+ assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG)
+ end
- def test_have_macro_header
- Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
- tmp.puts("#undef #{MACRO_NAME}")
- tmp.puts("#define #{MACRO_NAME} 1")
- tmp.close
- base = File.basename(tmp.path)
- assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
- end
+ def test_have_macro_header
+ Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
+ tmp.puts("#undef #{MACRO_NAME}")
+ tmp.puts("#define #{MACRO_NAME} 1")
+ tmp.close
+ base = File.basename(tmp.path)
+ assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
end
+ end
- def test_not_have_macro_opt
- assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG)
- end
+ def test_not_have_macro_opt
+ assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG)
+ end
- def test_not_have_macro_header
- Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
- tmp.puts("#undef #{MACRO_NAME}")
- tmp.close
- base = File.basename(tmp.path)
- assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
- end
+ def test_not_have_macro_header
+ Tempfile.create(%w"test_mkmf .h", ".") do |tmp|
+ tmp.puts("#undef #{MACRO_NAME}")
+ tmp.close
+ base = File.basename(tmp.path)
+ assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
end
end
end
diff --git a/test/mkmf/test_install.rb b/test/mkmf/test_install.rb
index 7f8c603d42..009d55f72d 100644
--- a/test/mkmf/test_install.rb
+++ b/test/mkmf/test_install.rb
@@ -1,27 +1,25 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestInstall < TestMkmf
- def test_install_dirs
- Dir.mktmpdir do |dir|
- File.write(dir+"/extconf.rb", "require 'mkmf'; create_makefile('test')")
- all_assertions do |a|
+class TestMkmfInstall < TestMkmf
+ def test_install_dirs
+ Dir.mktmpdir do |dir|
+ File.write(dir+"/extconf.rb", "require 'mkmf'; create_makefile('test')")
+ all_assertions do |a|
+ a.foreach(
+ ["site"],
+ ["vendor", "--vendor"],
+ ) do |dest, *options|
+ assert_ruby_status(["-C", dir, "extconf.rb", *options])
+ mf = File.read(dir+"/Makefile")
a.foreach(
- ["site"],
- ["vendor", "--vendor"],
- ) do |dest, *options|
- assert_ruby_status(["-C", dir, "extconf.rb", *options])
- mf = File.read(dir+"/Makefile")
- a.foreach(
- ["RUBYCOMMONDIR", "$(#{dest}dir)$(target_prefix)"],
- ["RUBYLIBDIR", "$(#{dest}libdir)$(target_prefix)"],
- ["RUBYARCHDIR", "$(#{dest}archdir)$(target_prefix)"],
- ["HDRDIR", "$(#{dest}hdrdir)$(target_prefix)"],
- ["ARCHHDRDIR", "$(#{dest}archhdrdir)$(target_prefix)"],
- ) do |(var, path)|
- assert_equal path, mf[/^#{var}\s*=\s*(.*)$/, 1]
- end
+ ["RUBYCOMMONDIR", "$(#{dest}dir)$(target_prefix)"],
+ ["RUBYLIBDIR", "$(#{dest}libdir)$(target_prefix)"],
+ ["RUBYARCHDIR", "$(#{dest}archdir)$(target_prefix)"],
+ ["HDRDIR", "$(#{dest}hdrdir)$(target_prefix)"],
+ ["ARCHHDRDIR", "$(#{dest}archhdrdir)$(target_prefix)"],
+ ) do |(var, path)|
+ assert_equal path, mf[/^#{var}\s*=\s*(.*)$/, 1]
end
end
end
diff --git a/test/mkmf/test_libs.rb b/test/mkmf/test_libs.rb
index 9c5e1d29fb..2f84d024e2 100644
--- a/test/mkmf/test_libs.rb
+++ b/test/mkmf/test_libs.rb
@@ -1,94 +1,92 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestLibs < TestMkmf
- def test_split_libs
- assert_equal(%w[-lfoo -lbar], split_libs("-lfoo -lbar"))
- end
+class TestMkmfLibs < TestMkmf
+ def test_split_libs
+ assert_equal(%w[-lfoo -lbar], split_libs("-lfoo -lbar"))
+ end
- def test_split_libs_macos
- assert_equal(%w[-ObjC -framework\ Ruby], split_libs("-ObjC -framework Ruby"), 'Bug #6987')
- end if /darwin/ =~ RUBY_PLATFORM
+ def test_split_libs_macos
+ assert_equal(%w[-ObjC -framework\ Ruby], split_libs("-ObjC -framework Ruby"), 'Bug #6987')
+ end if /darwin/ =~ RUBY_PLATFORM
- def test_split_libs_windows
- assert_equal(%w[zdll.lib libffi.lib], split_libs("zdll.lib libffi.lib"))
- end if /mswin/ =~ RUBY_PLATFORM
+ def test_split_libs_windows
+ assert_equal(%w[zdll.lib libffi.lib], split_libs("zdll.lib libffi.lib"))
+ end if /mswin/ =~ RUBY_PLATFORM
- def assert_in_order(array, x, y, mesg = nil)
- mesg = "#{x} must proceed to #{y}#{': ' if mesg}#{mesg}"
- assert_operator(array.index(x), :<, array.rindex(y), mesg)
- end
+ def assert_in_order(array, x, y, mesg = nil)
+ mesg = "#{x} must proceed to #{y}#{': ' if mesg}#{mesg}"
+ assert_operator(array.index(x), :<, array.rindex(y), mesg)
+ end
- def test_merge_simple
- bug = '[ruby-dev:21765]'
- assert_equal([], merge_libs(%w[]))
- assert_equal(%w[a b], merge_libs(%w[a], %w[b]))
- array = merge_libs(%w[a c], %w[b])
- assert_in_order(array, "a", "c", bug)
- end
+ def test_merge_simple
+ bug = '[ruby-dev:21765]'
+ assert_equal([], merge_libs(%w[]))
+ assert_equal(%w[a b], merge_libs(%w[a], %w[b]))
+ array = merge_libs(%w[a c], %w[b])
+ assert_in_order(array, "a", "c", bug)
+ end
- def test_merge_seq
- bug = '[ruby-dev:21765]'
- array = merge_libs(%w[a c d], %w[c b e])
- assert_in_order(array, "a", "c", bug)
- assert_in_order(array, "c", "d", bug)
- assert_in_order(array, "c", "b", bug)
- assert_in_order(array, "b", "e", bug)
- end
+ def test_merge_seq
+ bug = '[ruby-dev:21765]'
+ array = merge_libs(%w[a c d], %w[c b e])
+ assert_in_order(array, "a", "c", bug)
+ assert_in_order(array, "c", "d", bug)
+ assert_in_order(array, "c", "b", bug)
+ assert_in_order(array, "b", "e", bug)
+ end
- def test_merge_seq_pre
- bug = '[ruby-dev:21765]'
- array = merge_libs(%w[a c d], %w[b c d e])
- assert_in_order(array, "a", "c", bug)
- assert_in_order(array, "c", "d", bug)
- assert_in_order(array, "b", "c", bug)
- assert_in_order(array, "d", "e", bug)
- end
+ def test_merge_seq_pre
+ bug = '[ruby-dev:21765]'
+ array = merge_libs(%w[a c d], %w[b c d e])
+ assert_in_order(array, "a", "c", bug)
+ assert_in_order(array, "c", "d", bug)
+ assert_in_order(array, "b", "c", bug)
+ assert_in_order(array, "d", "e", bug)
+ end
- def test_merge_cyclic
- bug = '[ruby-dev:21765]'
- array = merge_libs(%w[a c d], %w[b c b])
- assert_in_order(array, "a", "c", bug)
- assert_in_order(array, "c", "d", bug)
- assert_in_order(array, "b", "c", bug)
- assert_in_order(array, "c", "b", bug)
- end
+ def test_merge_cyclic
+ bug = '[ruby-dev:21765]'
+ array = merge_libs(%w[a c d], %w[b c b])
+ assert_in_order(array, "a", "c", bug)
+ assert_in_order(array, "c", "d", bug)
+ assert_in_order(array, "b", "c", bug)
+ assert_in_order(array, "c", "b", bug)
+ end
- def test_merge_cyclic_2
- bug = '[ruby-dev:21765]'
- array = merge_libs(%w[a c a d], %w[b c b])
- assert_in_order(array, "a", "c", bug)
- assert_in_order(array, "c", "a", bug)
- assert_in_order(array, "c", "d", bug)
- assert_in_order(array, "a", "d", bug)
- assert_in_order(array, "b", "c", bug)
- assert_in_order(array, "c", "b", bug)
- end
+ def test_merge_cyclic_2
+ bug = '[ruby-dev:21765]'
+ array = merge_libs(%w[a c a d], %w[b c b])
+ assert_in_order(array, "a", "c", bug)
+ assert_in_order(array, "c", "a", bug)
+ assert_in_order(array, "c", "d", bug)
+ assert_in_order(array, "a", "d", bug)
+ assert_in_order(array, "b", "c", bug)
+ assert_in_order(array, "c", "b", bug)
+ end
- def test_merge_reversal
- bug = '[ruby-dev:22440]'
- array = merge_libs(%w[a b c], %w[c d a])
- assert_in_order(array, "a", "b" , bug)
- assert_in_order(array, "c", "d" , bug)
- ## assume that a and c have no dependency
- end
+ def test_merge_reversal
+ bug = '[ruby-dev:22440]'
+ array = merge_libs(%w[a b c], %w[c d a])
+ assert_in_order(array, "a", "b" , bug)
+ assert_in_order(array, "c", "d" , bug)
+ ## assume that a and c have no dependency
+ end
- def test_merge_reversal_followed
- bug7467 = '[ruby-core:50314] [Bug #7467]'
- array = nil
- assert_nothing_raised(bug7467) {
- array = merge_libs(%w[a b c d e f g h], %w[d c d e], [])
- }
- assert_in_order(array, "a", "b", bug7467)
- assert_in_order(array, "b", "c", bug7467)
- assert_in_order(array, "c", "d", bug7467)
- assert_in_order(array, "d", "e", bug7467)
- assert_in_order(array, "e", "f", bug7467)
- assert_in_order(array, "f", "g", bug7467)
- assert_in_order(array, "g", "h", bug7467)
- assert_in_order(array, "d", "c", bug7467)
- assert_in_order(array, "c", "e", bug7467)
- end
+ def test_merge_reversal_followed
+ bug7467 = '[ruby-core:50314] [Bug #7467]'
+ array = nil
+ assert_nothing_raised(bug7467) {
+ array = merge_libs(%w[a b c d e f g h], %w[d c d e], [])
+ }
+ assert_in_order(array, "a", "b", bug7467)
+ assert_in_order(array, "b", "c", bug7467)
+ assert_in_order(array, "c", "d", bug7467)
+ assert_in_order(array, "d", "e", bug7467)
+ assert_in_order(array, "e", "f", bug7467)
+ assert_in_order(array, "f", "g", bug7467)
+ assert_in_order(array, "g", "h", bug7467)
+ assert_in_order(array, "d", "c", bug7467)
+ assert_in_order(array, "c", "e", bug7467)
end
end if RUBY_ENGINE == "ruby"
diff --git a/test/mkmf/test_mkmf.rb b/test/mkmf/test_mkmf.rb
index adb86eca8d..55f9aa3b88 100644
--- a/test/mkmf/test_mkmf.rb
+++ b/test/mkmf/test_mkmf.rb
@@ -2,14 +2,12 @@
require 'test/unit'
require 'mkmf'
-class TestMkmf < Test::Unit::TestCase
- class TestGlobal < TestMkmf
- main = TOPLEVEL_BINDING.receiver
- MakeMakefile.public_instance_methods(false).each do |m|
- define_method(:"test_global_#{m}") do
- assert_respond_to(main, [m, true])
- assert_not_respond_to(main, [m, false])
- end
+class TestMkmfGlobal < Test::Unit::TestCase
+ main = TOPLEVEL_BINDING.receiver
+ MakeMakefile.public_instance_methods(false).each do |m|
+ define_method(:"test_global_#{m}") do
+ assert_respond_to(main, [m, true])
+ assert_not_respond_to(main, [m, false])
end
end
end
diff --git a/test/mkmf/test_pkg_config.rb b/test/mkmf/test_pkg_config.rb
index 1f4f48db12..72efb4ba81 100644
--- a/test/mkmf/test_pkg_config.rb
+++ b/test/mkmf/test_pkg_config.rb
@@ -2,67 +2,65 @@
require_relative 'base'
require 'shellwords'
-class TestMkmf
- class TestPkgConfig < TestMkmf
- PKG_CONFIG = find_executable0("pkg-config")
+class TestMkmfPkgConfig < TestMkmf
+ PKG_CONFIG = find_executable0("pkg-config")
- def setup
- super
+ def setup
+ super
- if PKG_CONFIG
- @fixtures_dir = File.join(Dir.pwd, "fixtures")
- @fixtures_lib_dir = File.join(@fixtures_dir, "lib")
- @fixtures_inc_dir = File.join(@fixtures_dir, "include")
+ if PKG_CONFIG
+ @fixtures_dir = File.join(Dir.pwd, "fixtures")
+ @fixtures_lib_dir = File.join(@fixtures_dir, "lib")
+ @fixtures_inc_dir = File.join(@fixtures_dir, "include")
- FileUtils.mkdir(@fixtures_dir)
- File.write("fixtures/test1.pc", <<~EOF)
- libdir=#{@fixtures_lib_dir}
- includedir=#{@fixtures_inc_dir}
+ FileUtils.mkdir(@fixtures_dir)
+ File.write("fixtures/test1.pc", <<~EOF)
+ libdir=#{@fixtures_lib_dir}
+ includedir=#{@fixtures_inc_dir}
- Name: test1
- Description: Test for mkmf pkg-config method
- Version: 1.2.3
- Libs: -L${libdir} -ltest1-public
- Libs.private: -ltest1-private
- Cflags: -I${includedir}/cflags-I --cflags-other
- EOF
+ Name: test1
+ Description: Test for mkmf pkg-config method
+ Version: 1.2.3
+ Libs: -L${libdir} -ltest1-public
+ Libs.private: -ltest1-private
+ Cflags: -I${includedir}/cflags-I --cflags-other
+ EOF
- @pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], File.join(Dir.pwd, "fixtures")
- end
+ @pkg_config_path, ENV["PKG_CONFIG_PATH"] = ENV["PKG_CONFIG_PATH"], File.join(Dir.pwd, "fixtures")
end
+ end
- def teardown
- if PKG_CONFIG
- ENV["PKG_CONFIG_PATH"] = @pkg_config_path
- end
-
- super
+ def teardown
+ if PKG_CONFIG
+ ENV["PKG_CONFIG_PATH"] = @pkg_config_path
end
- def test_pkgconfig_with_option_returns_nil_on_error
- pend("skipping because pkg-config is not installed") unless PKG_CONFIG
- assert_nil(pkg_config("package-does-not-exist", "exists"), MKMFLOG)
- end
+ super
+ end
- def test_pkgconfig_with_libs_option_returns_output
- pend("skipping because pkg-config is not installed") unless PKG_CONFIG
- expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public"].sort
- actual = pkg_config("test1", "libs").shellsplit.sort
- assert_equal(expected, actual, MKMFLOG)
- end
+ def test_pkgconfig_with_option_returns_nil_on_error
+ pend("skipping because pkg-config is not installed") unless PKG_CONFIG
+ assert_nil(pkg_config("package-does-not-exist", "exists"), MKMFLOG)
+ end
- def test_pkgconfig_with_cflags_option_returns_output
- pend("skipping because pkg-config is not installed") unless PKG_CONFIG
- expected = ["--cflags-other", "-I#{@fixtures_inc_dir}/cflags-I"].sort
- actual = pkg_config("test1", "cflags").shellsplit.sort
- assert_equal(expected, actual, MKMFLOG)
- end
+ def test_pkgconfig_with_libs_option_returns_output
+ pend("skipping because pkg-config is not installed") unless PKG_CONFIG
+ expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public"].sort
+ actual = pkg_config("test1", "libs").shellsplit.sort
+ assert_equal(expected, actual, MKMFLOG)
+ end
- def test_pkgconfig_with_multiple_options
- pend("skipping because pkg-config is not installed") unless PKG_CONFIG
- expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort
- actual = pkg_config("test1", "libs", "static").shellsplit.sort
- assert_equal(expected, actual, MKMFLOG)
- end
+ def test_pkgconfig_with_cflags_option_returns_output
+ pend("skipping because pkg-config is not installed") unless PKG_CONFIG
+ expected = ["--cflags-other", "-I#{@fixtures_inc_dir}/cflags-I"].sort
+ actual = pkg_config("test1", "cflags").shellsplit.sort
+ assert_equal(expected, actual, MKMFLOG)
+ end
+
+ def test_pkgconfig_with_multiple_options
+ pend("skipping because pkg-config is not installed") unless PKG_CONFIG
+ expected = ["-L#{@fixtures_lib_dir}", "-ltest1-public", "-ltest1-private"].sort
+ actual = pkg_config("test1", "libs", "static").shellsplit.sort
+ assert_equal(expected, actual, MKMFLOG)
end
end
diff --git a/test/mkmf/test_signedness.rb b/test/mkmf/test_signedness.rb
index 589dcb56e8..a59e3548a2 100644
--- a/test/mkmf/test_signedness.rb
+++ b/test/mkmf/test_signedness.rb
@@ -1,30 +1,28 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestSignedness < TestMkmf
- def test_typeof_builtin
- bug4144 = '[ruby-dev:42731]'
- [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
- %w[short int long].each do |type|
- assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144))
- end
+class TestMkmfSignedness < TestMkmf
+ def test_typeof_builtin
+ bug4144 = '[ruby-dev:42731]'
+ [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
+ %w[short int long].each do |type|
+ assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144))
end
end
+ end
- def test_typeof_typedef
- [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
- %w[short int long].each do |type|
- open("confdefs.h", "w") {|f|
- f.puts "typedef #{signed}#{type} test1_t;"
- }
- $defs.clear
- assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG)
- assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}")
- end
+ def test_typeof_typedef
+ [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
+ %w[short int long].each do |type|
+ open("confdefs.h", "w") {|f|
+ f.puts "typedef #{signed}#{type} test1_t;"
+ }
+ $defs.clear
+ assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG)
+ assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}")
end
- ensure
- File.unlink("confdefs.h")
end
+ ensure
+ File.unlink("confdefs.h")
end
end
diff --git a/test/mkmf/test_sizeof.rb b/test/mkmf/test_sizeof.rb
index 742c3d6454..6fb0a6a8f6 100644
--- a/test/mkmf/test_sizeof.rb
+++ b/test/mkmf/test_sizeof.rb
@@ -1,48 +1,46 @@
# frozen_string_literal: false
require_relative 'base'
-class TestMkmf
- class TestSizeof < TestMkmf
- def setup
- super
- @sizeof_short = config_value("SIZEOF_SHORT").to_i
- @sizeof_int = config_value("SIZEOF_INT").to_i
- @sizeof_long = config_value("SIZEOF_LONG").to_i
- @sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
- @sizeof___int64 = config_value("SIZEOF___INT64").to_i
- end
+class TestMkmfSizeof < TestMkmf
+ def setup
+ super
+ @sizeof_short = config_value("SIZEOF_SHORT").to_i
+ @sizeof_int = config_value("SIZEOF_INT").to_i
+ @sizeof_long = config_value("SIZEOF_LONG").to_i
+ @sizeof_long_long = config_value("SIZEOF_LONG_LONG").to_i
+ @sizeof___int64 = config_value("SIZEOF___INT64").to_i
+ end
- def test_sizeof_builtin
- %w[char short int long float double void*].each do |type|
- assert_kind_of(Integer, mkmf {check_sizeof(type)}, MKMFLOG)
- end
- assert_operator(@sizeof_short, :<=, @sizeof_int)
- assert_operator(@sizeof_int, :<=, @sizeof_long)
- assert_operator(@sizeof_long, :<=, @sizeof_long_long) unless @sizeof_long_long.zero?
- assert_equal(8, @sizeof___int64) unless @sizeof___int64.zero?
+ def test_sizeof_builtin
+ %w[char short int long float double void*].each do |type|
+ assert_kind_of(Integer, mkmf {check_sizeof(type)}, MKMFLOG)
end
+ assert_operator(@sizeof_short, :<=, @sizeof_int)
+ assert_operator(@sizeof_int, :<=, @sizeof_long)
+ assert_operator(@sizeof_long, :<=, @sizeof_long_long) unless @sizeof_long_long.zero?
+ assert_equal(8, @sizeof___int64) unless @sizeof___int64.zero?
+ end
- def test_sizeof_struct
- open("confdefs.h", "w") {|f|
- f.puts "typedef struct {char x;} test1_t;"
- }
- assert_equal(1, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
+ def test_sizeof_struct
+ open("confdefs.h", "w") {|f|
+ f.puts "typedef struct {char x;} test1_t;"
+ }
+ assert_equal(1, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
- open("confdefs.h", "w") {|f|
- f.puts "typedef struct {char x, y;} test1_t;"
- }
- assert_equal(2, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
+ open("confdefs.h", "w") {|f|
+ f.puts "typedef struct {char x, y;} test1_t;"
+ }
+ assert_equal(2, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
- open("confdefs.h", "w") {|f|
- f.puts "typedef struct {int x;} test1_t;"
- }
- assert_equal(@sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
- open("confdefs.h", "w") {|f|
- f.puts "typedef struct {int x, y;} test1_t;"
- }
- assert_equal(2 * @sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
- ensure
- File.unlink("confdefs.h")
- end
+ open("confdefs.h", "w") {|f|
+ f.puts "typedef struct {int x;} test1_t;"
+ }
+ assert_equal(@sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
+ open("confdefs.h", "w") {|f|
+ f.puts "typedef struct {int x, y;} test1_t;"
+ }
+ assert_equal(2 * @sizeof_int, mkmf {check_sizeof("test1_t", "confdefs.h")}, MKMFLOG)
+ ensure
+ File.unlink("confdefs.h")
end
end
diff --git a/test/optparse/test_acceptable.rb b/test/optparse/test_acceptable.rb
index 12f7886538..12f5322726 100644
--- a/test/optparse/test_acceptable.rb
+++ b/test/optparse/test_acceptable.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
require_relative 'test_optparse'
-class TestOptionParser::Acceptable < TestOptionParser
+class TestOptionParserAcceptable < TestOptionParser
def setup
super
diff --git a/test/optparse/test_autoconf.rb b/test/optparse/test_autoconf.rb
index 45f2ba09b2..ec87744633 100644
--- a/test/optparse/test_autoconf.rb
+++ b/test/optparse/test_autoconf.rb
@@ -2,9 +2,7 @@
require 'test/unit'
require 'optparse/ac'
-class TestOptionParser < Test::Unit::TestCase; end
-
-class TestOptionParser::AutoConf < Test::Unit::TestCase
+class TestOptionParserAutoConf < Test::Unit::TestCase
def setup
@opt = OptionParser::AC.new
@foo = @bar = self.class
diff --git a/test/optparse/test_bash_completion.rb b/test/optparse/test_bash_completion.rb
index 513e986f66..60c82f7136 100644
--- a/test/optparse/test_bash_completion.rb
+++ b/test/optparse/test_bash_completion.rb
@@ -2,9 +2,7 @@
require 'test/unit'
require 'optparse'
-class TestOptionParser < Test::Unit::TestCase
-end
-class TestOptionParser::BashCompletion < Test::Unit::TestCase
+class TestOptionParserBashCompletion < Test::Unit::TestCase
def setup
@opt = OptionParser.new
@opt.define("-z", "zzz") {}
diff --git a/test/optparse/test_cclass.rb b/test/optparse/test_cclass.rb
index ac46f46bb2..0ded61f60e 100644
--- a/test/optparse/test_cclass.rb
+++ b/test/optparse/test_cclass.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
require_relative 'test_optparse'
-class TestOptionParser::CClass < TestOptionParser
+class TestOptionParserCClass < TestOptionParser
def test_no_argument
flags = []
@opt.def_option("-[a-z]") {|x| flags << x}
diff --git a/test/optparse/test_did_you_mean.rb b/test/optparse/test_did_you_mean.rb
index a9ad051f03..d1514b73eb 100644
--- a/test/optparse/test_did_you_mean.rb
+++ b/test/optparse/test_did_you_mean.rb
@@ -6,7 +6,7 @@ rescue LoadError
return
end
-class TestOptionParser::DidYouMean < TestOptionParser
+class TestOptionParserDidYouMean < TestOptionParser
def setup
super
@opt.def_option("--foo", Integer) { |v| @foo = v }
diff --git a/test/optparse/test_getopts.rb b/test/optparse/test_getopts.rb
index 3711e6f269..7d9160f7af 100644
--- a/test/optparse/test_getopts.rb
+++ b/test/optparse/test_getopts.rb
@@ -2,9 +2,7 @@
require 'test/unit'
require 'optparse'
-class TestOptionParser < Test::Unit::TestCase
-end
-class TestOptionParser::Getopts < Test::Unit::TestCase
+class TestOptionParserGetopts < Test::Unit::TestCase
def setup
@opt = OptionParser.new
end
diff --git a/test/optparse/test_kwargs.rb b/test/optparse/test_kwargs.rb
index 78d7e2ee9c..2e826bfd12 100644
--- a/test/optparse/test_kwargs.rb
+++ b/test/optparse/test_kwargs.rb
@@ -3,9 +3,7 @@ require 'test/unit'
require 'optparse'
require 'optparse/kwargs'
-class TestOptionParser < Test::Unit::TestCase
-end
-class TestOptionParser::KwArg < Test::Unit::TestCase
+class TestOptionParserKwArg < Test::Unit::TestCase
class K
def initialize(host:, port: 8080)
@host = host
diff --git a/test/optparse/test_noarg.rb b/test/optparse/test_noarg.rb
index 8f20519408..a53399afc2 100644
--- a/test/optparse/test_noarg.rb
+++ b/test/optparse/test_noarg.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
require_relative 'test_optparse'
-module TestOptionParser::NoArg
+module TestOptionParserNoArg
def setup
super
@opt.def_option "--with_underscore" do |x| @flag = x end
@@ -9,7 +9,7 @@ module TestOptionParser::NoArg
end
class Def1 < TestOptionParser
- include NoArg
+ include TestOptionParserNoArg
def setup
super
@opt.def_option("-x") {|x| @flag = x}
@@ -17,7 +17,7 @@ module TestOptionParser::NoArg
end
end
class Def2 < TestOptionParser
- include NoArg
+ include TestOptionParserNoArg
def setup
super
@opt.def_option("-x", "--option") {|x| @flag = x}
diff --git a/test/optparse/test_optarg.rb b/test/optparse/test_optarg.rb
index 14584f7e89..81127a8a37 100644
--- a/test/optparse/test_optarg.rb
+++ b/test/optparse/test_optarg.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
require_relative 'test_optparse'
-class TestOptionParser::OptArg < TestOptionParser
+class TestOptionParserOptArg < TestOptionParser
def setup
super
@opt.def_option("-x[VAL]") {|x| @flag = x}
diff --git a/test/optparse/test_placearg.rb b/test/optparse/test_placearg.rb
index 8acfdb2161..94cfb0e819 100644
--- a/test/optparse/test_placearg.rb
+++ b/test/optparse/test_placearg.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
require_relative 'test_optparse'
-class TestOptionParser::PlaceArg < TestOptionParser
+class TestOptionParserPlaceArg < TestOptionParser
def setup
super
@opt.def_option("-x [VAL]") {|x| @flag = x}
diff --git a/test/optparse/test_reqarg.rb b/test/optparse/test_reqarg.rb
index b2e4755f80..d5686d13aa 100644
--- a/test/optparse/test_reqarg.rb
+++ b/test/optparse/test_reqarg.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
require_relative 'test_optparse'
-module TestOptionParser::ReqArg
+module TestOptionParserReqArg
def setup
super
@opt.def_option "--with_underscore=VAL" do |x| @flag = x end
@@ -9,7 +9,7 @@ module TestOptionParser::ReqArg
end
class Def1 < TestOptionParser
- include ReqArg
+ include TestOptionParserReqArg
def setup
super
@opt.def_option("-xVAL") {|x| @flag = x}
@@ -19,21 +19,21 @@ module TestOptionParser::ReqArg
end
end
class Def2 < TestOptionParser
- include ReqArg
+ include TestOptionParserReqArg
def setup
super
@opt.def_option("-x", "--option=VAL") {|x| @flag = x}
end
end
class Def3 < TestOptionParser
- include ReqArg
+ include TestOptionParserReqArg
def setup
super
@opt.def_option("--option=VAL", "-x") {|x| @flag = x}
end
end
class Def4 < TestOptionParser
- include ReqArg
+ include TestOptionParserReqArg
def setup
super
@opt.def_option("-xVAL", "--option=VAL") {|x| @flag = x}
diff --git a/test/optparse/test_summary.rb b/test/optparse/test_summary.rb
index 67b05672d4..6b36ce3c76 100644
--- a/test/optparse/test_summary.rb
+++ b/test/optparse/test_summary.rb
@@ -1,7 +1,7 @@
# frozen_string_literal: false
require_relative 'test_optparse'
-class TestOptionParser::SummaryTest < TestOptionParser
+class TestOptionParserSummaryTest < TestOptionParser
def test_short_clash
r = nil
o = OptionParser.new do |opts|
diff --git a/test/optparse/test_zsh_completion.rb b/test/optparse/test_zsh_completion.rb
index c548d4af8a..76f0a73f32 100644
--- a/test/optparse/test_zsh_completion.rb
+++ b/test/optparse/test_zsh_completion.rb
@@ -2,9 +2,7 @@
require 'test/unit'
require 'optparse'
-class TestOptionParser < Test::Unit::TestCase
-end
-class TestOptionParser::ZshCompletion < Test::Unit::TestCase
+class TestOptionParserZshCompletion < Test::Unit::TestCase
def setup
@opt = OptionParser.new
@opt.define("-z", "zzz") {}
diff --git a/test/ruby/enc/test_grapheme_breaks.rb b/test/ruby/enc/test_grapheme_breaks.rb
index 2d210946a9..e8f3aa04a7 100644
--- a/test/ruby/enc/test_grapheme_breaks.rb
+++ b/test/ruby/enc/test_grapheme_breaks.rb
@@ -4,31 +4,28 @@
require "test/unit"
class TestGraphemeBreaksFromFile < Test::Unit::TestCase
-end
-
-class TestGraphemeBreaksFromFile::BreakTest
- attr_reader :clusters, :string, :comment, :line_number
+ class BreakTest
+ attr_reader :clusters, :string, :comment, :line_number
- def initialize(line_number, data, comment)
- @line_number = line_number
- @comment = comment
- @clusters = data.sub(/\A\s*÷\s*/, '')
- .sub(/\s*÷\s*\z/, '')
- .split(/\s*÷\s*/)
- .map do |cl|
- cl.split(/\s*×\s*/)
- .map do |ch|
- c = ch.to_i(16)
- # eliminate cases with surrogates
- raise ArgumentError if 0xD800 <= c and c <= 0xDFFF
- c.chr('UTF-8')
- end.join
- end
- @string = @clusters.join
+ def initialize(line_number, data, comment)
+ @line_number = line_number
+ @comment = comment
+ @clusters = data.sub(/\A\s*÷\s*/, '')
+ .sub(/\s*÷\s*\z/, '')
+ .split(/\s*÷\s*/)
+ .map do |cl|
+ cl.split(/\s*×\s*/)
+ .map do |ch|
+ c = ch.to_i(16)
+ # eliminate cases with surrogates
+ raise ArgumentError if 0xD800 <= c and c <= 0xDFFF
+ c.chr('UTF-8')
+ end.join
+ end
+ @string = @clusters.join
+ end
end
-end
-class TestGraphemeBreaksFromFile < Test::Unit::TestCase
UNICODE_VERSION = RbConfig::CONFIG['UNICODE_VERSION']
path = File.expand_path("../../../enc/unicode/data/#{UNICODE_VERSION}", __dir__)
UNICODE_DATA_PATH = File.directory?("#{path}/ucd/auxiliary") ? "#{path}/ucd/auxiliary" : path
@@ -43,53 +40,53 @@ class TestGraphemeBreaksFromFile < Test::Unit::TestCase
skip "Unicode data file GraphemeBreakTest not available in #{UNICODE_DATA_PATH}."
end
end
-end
-TestGraphemeBreaksFromFile.file_available? and class TestGraphemeBreaksFromFile
- def read_data
- tests = []
- IO.foreach(GRAPHEME_BREAK_TEST_FILE, encoding: Encoding::UTF_8) do |line|
- if $. == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt")
- raise "File Version Mismatch"
+ if file_available?
+ def read_data
+ tests = []
+ IO.foreach(GRAPHEME_BREAK_TEST_FILE, encoding: Encoding::UTF_8) do |line|
+ if $. == 1 and not line.start_with?("# GraphemeBreakTest-#{UNICODE_VERSION}.txt")
+ raise "File Version Mismatch"
+ end
+ next if /\A#/.match? line
+ tests << BreakTest.new($., *line.chomp.split('#')) rescue 'whatever'
end
- next if /\A#/.match? line
- tests << BreakTest.new($., *line.chomp.split('#')) rescue 'whatever'
+ tests
end
- tests
- end
- def all_tests
- @@tests ||= read_data
- rescue Errno::ENOENT
- @@tests ||= []
- end
+ def all_tests
+ @@tests ||= read_data
+ rescue Errno::ENOENT
+ @@tests ||= []
+ end
- def test_each_grapheme_cluster
- all_tests.each do |test|
- expected = test.clusters
- actual = test.string.each_grapheme_cluster.to_a
- assert_equal expected, actual,
- "line #{test.line_number}, expected '#{expected}', " +
- "but got '#{actual}', comment: #{test.comment}"
+ def test_each_grapheme_cluster
+ all_tests.each do |test|
+ expected = test.clusters
+ actual = test.string.each_grapheme_cluster.to_a
+ assert_equal expected, actual,
+ "line #{test.line_number}, expected '#{expected}', " +
+ "but got '#{actual}', comment: #{test.comment}"
+ end
end
- end
- def test_backslash_X
- all_tests.each do |test|
- clusters = test.clusters.dup
- string = test.string.dup
- removals = 0
- while string.sub!(/\A\X/, '')
- removals += 1
- clusters.shift
- expected = clusters.join
+ def test_backslash_X
+ all_tests.each do |test|
+ clusters = test.clusters.dup
+ string = test.string.dup
+ removals = 0
+ while string.sub!(/\A\X/, '')
+ removals += 1
+ clusters.shift
+ expected = clusters.join
+ assert_equal expected, string,
+ "line #{test.line_number}, removals: #{removals}, expected '#{expected}', " +
+ "but got '#{string}', comment: #{test.comment}"
+ end
assert_equal expected, string,
- "line #{test.line_number}, removals: #{removals}, expected '#{expected}', " +
+ "line #{test.line_number}, after last removal, expected '#{expected}', " +
"but got '#{string}', comment: #{test.comment}"
end
- assert_equal expected, string,
- "line #{test.line_number}, after last removal, expected '#{expected}', " +
- "but got '#{string}', comment: #{test.comment}"
end
end
end
diff --git a/test/ruby/test_inlinecache.rb b/test/ruby/test_inlinecache.rb
index 6c2d86aefd..d48d95d74e 100644
--- a/test/ruby/test_inlinecache.rb
+++ b/test/ruby/test_inlinecache.rb
@@ -3,7 +3,7 @@
require 'test/unit'
-class TestMethod < Test::Unit::TestCase
+class TestMethodInlineCache < Test::Unit::TestCase
def test_alias
m0 = Module.new do
def foo; :M0 end