1require_relative 'base'
2require 'tempfile'
3
4class TestMkmf
5  class TestHaveMacro < TestMkmf
6    MACRO_NAME = "RUBY_MKMFTEST_FOOBAR"
7
8    def test_have_macro_opt
9      assert_equal(true, have_macro(MACRO_NAME, nil, "-D#{MACRO_NAME}"), MKMFLOG)
10    end
11
12    def test_have_macro_header
13      Tempfile.open(%w"test_mkmf .h", ".") do |tmp|
14        tmp.puts("#undef #{MACRO_NAME}")
15        tmp.puts("#define #{MACRO_NAME} 1")
16        tmp.close
17        base = File.basename(tmp.path)
18        assert_equal(true, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
19      end
20    end
21
22    def test_not_have_macro_opt
23      assert_equal(false, have_macro(MACRO_NAME, nil, "-U#{MACRO_NAME}"), MKMFLOG)
24    end
25
26    def test_not_have_macro_header
27      Tempfile.open(%w"test_mkmf .h", ".") do |tmp|
28        tmp.puts("#undef #{MACRO_NAME}")
29        tmp.close
30        base = File.basename(tmp.path)
31        assert_equal(false, have_macro(MACRO_NAME, base, "-I."), MKMFLOG)
32      end
33    end
34  end
35end
36