@@ -29,7 +29,7 @@ def setup
2929 def test_self_build
3030 File . open File . join ( @ext , "CMakeLists.txt" ) , "w" do |cmakelists |
3131 cmakelists . write <<-EO_CMAKE
32- cmake_minimum_required(VERSION 3.5 )
32+ cmake_minimum_required(VERSION 3.26 )
3333project(self_build NONE)
3434install (FILES test.txt DESTINATION bin)
3535 EO_CMAKE
@@ -39,46 +39,107 @@ def test_self_build
3939
4040 output = [ ]
4141
42- Gem ::Ext ::CmakeBuilder . build nil , @dest_path , output , [ ] , nil , @ext
42+ builder = Gem ::Ext ::CmakeBuilder . new
43+ builder . build nil , @dest_path , output , [ ] , @dest_path , @ext
4344
4445 output = output . join "\n "
4546
46- assert_match ( /^cmake \. -DCMAKE_INSTALL_PREFIX\\ =#{ Regexp . escape @dest_path } / , output )
47+ assert_match ( /^current directory: #{ Regexp . escape @ext } / , output )
48+ assert_match ( /cmake.*-DCMAKE_RUNTIME_OUTPUT_DIRECTORY\\ =#{ Regexp . escape @dest_path } / , output )
49+ assert_match ( /cmake.*-DCMAKE_LIBRARY_OUTPUT_DIRECTORY\\ =#{ Regexp . escape @dest_path } / , output )
50+ assert_match ( /#{ Regexp . escape @ext } / , output )
51+ end
52+
53+ def test_self_build_presets
54+ File . open File . join ( @ext , "CMakeLists.txt" ) , "w" do |cmakelists |
55+ cmakelists . write <<-EO_CMAKE
56+ cmake_minimum_required(VERSION 3.26)
57+ project(self_build NONE)
58+ install (FILES test.txt DESTINATION bin)
59+ EO_CMAKE
60+ end
61+
62+ File . open File . join ( @ext , "CMakePresets.json" ) , "w" do |presets |
63+ presets . write <<-EO_CMAKE
64+ {
65+ "version": 6,
66+ "configurePresets": [
67+ {
68+ "name": "debug",
69+ "displayName": "Debug",
70+ "generator": "Ninja",
71+ "binaryDir": "build/debug",
72+ "cacheVariables": {
73+ "CMAKE_BUILD_TYPE": "Debug"
74+ }
75+ },
76+ {
77+ "name": "release",
78+ "displayName": "Release",
79+ "generator": "Ninja",
80+ "binaryDir": "build/release",
81+ "cacheVariables": {
82+ "CMAKE_BUILD_TYPE": "Release"
83+ }
84+ }
85+ ]
86+ }
87+ EO_CMAKE
88+ end
89+
90+ FileUtils . touch File . join ( @ext , "test.txt" )
91+
92+ output = [ ]
93+
94+ builder = Gem ::Ext ::CmakeBuilder . new
95+ builder . build nil , @dest_path , output , [ ] , @dest_path , @ext
96+
97+ output = output . join "\n "
98+
99+ assert_match ( /The gem author provided a list of presets that can be used to build the gem./ , output )
100+ assert_match ( /Available configure presets/ , output )
101+ assert_match ( /\" debug\" - Debug/ , output )
102+ assert_match ( /\" release\" - Release/ , output )
103+ assert_match ( /^current directory: #{ Regexp . escape @ext } / , output )
104+ assert_match ( /cmake.*-DCMAKE_RUNTIME_OUTPUT_DIRECTORY\\ =#{ Regexp . escape @dest_path } / , output )
105+ assert_match ( /cmake.*-DCMAKE_LIBRARY_OUTPUT_DIRECTORY\\ =#{ Regexp . escape @dest_path } / , output )
47106 assert_match ( /#{ Regexp . escape @ext } / , output )
48- assert_contains_make_command "" , output
49- assert_contains_make_command "install" , output
50- assert_match ( /test\. txt/ , output )
51107 end
52108
53109 def test_self_build_fail
54110 output = [ ]
55111
112+ builder = Gem ::Ext ::CmakeBuilder . new
56113 error = assert_raise Gem ::InstallError do
57- Gem :: Ext :: CmakeBuilder . build nil , @dest_path , output , [ ] , nil , @ext
114+ builder . build nil , @dest_path , output , [ ] , @dest_path , @ext
58115 end
59116
60- output = output . join " \n "
117+ assert_match "cmake_configure failed" , error . message
61118
62119 shell_error_msg = /(CMake Error: .*)/
63-
64- assert_match "cmake failed" , error . message
65-
66- assert_match ( /^cmake . -DCMAKE_INSTALL_PREFIX\\ =#{ Regexp . escape @dest_path } / , output )
120+ output = output . join "\n "
67121 assert_match ( /#{ shell_error_msg } / , output )
122+ assert_match ( /CMake Error: The source directory .* does not appear to contain CMakeLists.txt./ , output )
68123 end
69124
70125 def test_self_build_has_makefile
71- File . open File . join ( @ext , "Makefile" ) , "w" do |makefile |
72- makefile . puts "all:\n \t @echo ok\n install:\n \t @echo ok"
126+ File . open File . join ( @ext , "CMakeLists.txt" ) , "w" do |cmakelists |
127+ cmakelists . write <<-EO_CMAKE
128+ cmake_minimum_required(VERSION 3.26)
129+ project(self_build NONE)
130+ install (FILES test.txt DESTINATION bin)
131+ EO_CMAKE
73132 end
74133
75134 output = [ ]
76135
77- Gem ::Ext ::CmakeBuilder . build nil , @dest_path , output , [ ] , nil , @ext
136+ builder = Gem ::Ext ::CmakeBuilder . new
137+ builder . build nil , @dest_path , output , [ ] , @dest_path , @ext
78138
79139 output = output . join "\n "
80140
81- assert_contains_make_command "" , output
82- assert_contains_make_command "install" , output
141+ # The default generator will create a Makefile in the build directory
142+ makefile = File . join ( @ext , "build" , "Makefile" )
143+ assert ( File . exist? ( makefile ) )
83144 end
84145end
0 commit comments