* 2022-01-18 [ci skip]
[ruby-80x24.org.git] / test / mkmf / test_signedness.rb
blob589dcb56e8e1858d684e10b5c8df0c00e21aab5b
1 # frozen_string_literal: false
2 require_relative 'base'
4 class TestMkmf
5   class TestSignedness < TestMkmf
6     def test_typeof_builtin
7       bug4144 = '[ruby-dev:42731]'
8       [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
9         %w[short int long].each do |type|
10           assert_equal(expect.to_i, mkmf {check_signedness(signed+type)}, mkmflog(bug4144))
11         end
12       end
13     end
15     def test_typeof_typedef
16       [["", "-1"], ["signed ", "-1"], ["unsigned ", "+1"]].each do |signed, expect|
17         %w[short int long].each do |type|
18           open("confdefs.h", "w") {|f|
19             f.puts "typedef #{signed}#{type} test1_t;"
20           }
21           $defs.clear
22           assert_equal(expect.to_i, mkmf {check_signedness("test1_t", "confdefs.h")}, MKMFLOG)
23           assert_include($defs, "-DSIGNEDNESS_OF_TEST1_T=#{expect}")
24         end
25       end
26     ensure
27       File.unlink("confdefs.h")
28     end
29   end
30 end