diff --git a/test/integration/lib.rb b/test/integration/lib.rb index 5323f1c..1337ba5 100644 --- a/test/integration/lib.rb +++ b/test/integration/lib.rb @@ -32,12 +32,12 @@ puts "Running CPM.cmake integration tests" puts "Temp directory: '#{TestLib::TMP_DIR}'" class Project - def initialize(src_dir, build_dir) + def initialize(src_dir, bin_dir) @src_dir = src_dir - @build_dir = build_dir + @bin_dir = bin_dir end - attr :src_dir, :build_dir + attr :src_dir, :bin_dir def create_file(target_path, text) target_path = File.join(@src_dir, target_path) @@ -64,7 +64,10 @@ class Project CommandResult = Struct.new :out, :err, :status def configure(extra_args = '') - CommandResult.new *Open3.capture3("cmake -S #{@src_dir} -B #{@build_dir} #{extra_args}") + CommandResult.new *Open3.capture3("cmake -S #{@src_dir} -B #{@bin_dir} #{extra_args}") + end + def build(extra_args = '') + CommandResult.new *Open3.capture3("cmake --build #{@bin_dir} #{extra_args}") end class CMakeCache @@ -132,7 +135,7 @@ class Project end end def read_cache - CMakeCache.from_dir @build_dir + CMakeCache.from_dir @bin_dir end end @@ -171,6 +174,6 @@ class IntegrationTest < Test::Unit::TestCase FileUtils.copy_entry template_dir, src_dir end - Project.new src_dir, base + '-build' + Project.new src_dir, base + '-bin' end end diff --git a/test/integration/templates/using-adder/lists.in.cmake b/test/integration/templates/using-adder/lists.in.cmake index 4d0d428..d4eee53 100644 --- a/test/integration/templates/using-adder/lists.in.cmake +++ b/test/integration/templates/using-adder/lists.in.cmake @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) project(using-adder) +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + include("%{cpm_path}") %{packages} diff --git a/test/integration/test_basics.rb b/test/integration/test_basics.rb index c6e941d..f3db6e9 100644 --- a/test/integration/test_basics.rb +++ b/test/integration/test_basics.rb @@ -1,10 +1,13 @@ require_relative './lib' +# Tests of cpm caches and vars when no packages are used + class Basics < IntegrationTest - # test cpm coherency with no cpm-related env vars + # Test cpm caches with no cpm-related env vars def test_cpm_default prj = make_project 'no-deps' prj.create_lists_with({}) + cfg_result = prj.configure assert_success cfg_result @@ -27,10 +30,10 @@ class Basics < IntegrationTest assert_equal 'OFF', check_and_get('CPM_DONT_CREATE_PACKAGE_LOCK', 'BOOL') assert_equal 'OFF', check_and_get('CPM_INCLUDE_ALL_IN_PACKAGE_LOCK', 'BOOL') - assert_same_path File.join(prj.build_dir, 'cpm-package-lock.cmake'), check_and_get('CPM_PACKAGE_LOCK_FILE') + assert_same_path File.join(prj.bin_dir, 'cpm-package-lock.cmake'), check_and_get('CPM_PACKAGE_LOCK_FILE') assert_equal 'OFF', check_and_get('CPM_DONT_UPDATE_MODULE_PATH', 'BOOL') - assert_same_path File.join(prj.build_dir, 'CPM_modules'), check_and_get('CPM_MODULE_PATH') + assert_same_path File.join(prj.bin_dir, 'CPM_modules'), check_and_get('CPM_MODULE_PATH') end def check_and_get(key, type = 'INTERNAL') diff --git a/test/integration/test_simple.rb b/test/integration/test_simple.rb index 80ca7ef..cc203cc 100644 --- a/test/integration/test_simple.rb +++ b/test/integration/test_simple.rb @@ -1,41 +1,89 @@ require_relative './lib' class Simple < IntegrationTest - P_ADDER = 'testpack-adder' + ADDER_PACKAGE_NAME = 'testpack-adder' - def test_add_remove_packages - prj = make_project 'using-adder' + def test_update_single_package + @prj = make_project 'using-adder' - prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")' - assert_success prj.configure + create_with_commit_sha + update_to_version_1 + update_with_option_off_and_build + end - cache = prj.read_cache + def create_with_commit_sha + @prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")' + assert_success @prj.configure + + cache = @prj.read_cache assert_equal 1, cache.packages.size - adder = cache.packages[P_ADDER] - assert_not_nil adder - assert_equal '0', adder.ver - assert File.directory? adder.src_dir - assert File.directory? adder.bin_dir + adder_cache = cache.packages[ADDER_PACKAGE_NAME] + assert_not_nil adder_cache + assert_equal '0', adder_cache.ver + assert File.directory? adder_cache.src_dir + assert File.directory? adder_cache.bin_dir - adder_ver_file = File.join(adder.src_dir, 'version') - assert File.file? adder_ver_file - assert_equal 'initial', File.read(adder_ver_file).strip + @adder_ver_file = File.join(adder_cache.src_dir, 'version') + assert File.file? @adder_ver_file + assert_equal 'initial', File.read(@adder_ver_file).strip - # reconfigure with new version - prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.0")' - assert_success prj.configure + # calculated adder values + assert_equal 'ON', cache['ADDER_BUILD_EXAMPLES'] + assert_equal 'ON', cache['ADDER_BUILD_TESTS'] + assert_equal adder_cache.src_dir, cache['adder_SOURCE_DIR'] + assert_equal adder_cache.bin_dir, cache['adder_BINARY_DIR'] - cache = prj.read_cache + # store for future comparisons + @adder_cache0 = adder_cache + end + + def update_to_version_1 + @prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.0")' + assert_success @prj.configure + + cache = @prj.read_cache assert_equal 1, cache.packages.size - adder = cache.packages[P_ADDER] - assert_not_nil adder - assert_equal '1.0.0', adder.ver + adder_cache = cache.packages[ADDER_PACKAGE_NAME] + assert_not_nil adder_cache + assert_equal '1.0.0', adder_cache.ver - # dir shouldn't have changed - assert_equal File.dirname(adder_ver_file), adder.src_dir + # dirs shouldn't have changed + assert_equal @adder_cache0.src_dir, adder_cache.src_dir + assert_equal @adder_cache0.bin_dir, adder_cache.bin_dir - assert_equal '1.0.0', File.read(adder_ver_file).strip + assert_equal '1.0.0', File.read(@adder_ver_file).strip + end + + def update_with_option_off_and_build + @prj.create_lists_with package: <<~PACK + CPMAddPackage( + NAME testpack-adder + GITHUB_REPOSITORY cpm-cmake/testpack-adder + VERSION 1.0.0 + OPTIONS "ADDER_BUILD_TESTS OFF" + ) + PACK + assert_success @prj.configure + assert_success @prj.build + + exe_dir = File.join(@prj.bin_dir, 'bin') + assert File.directory? exe_dir + + exes = Dir[exe_dir + '/**/*'].filter { + # on multi-configuration generators (like Visual Studio) the executables will be in bin/ + # also filter-out other articacts like .pdb or .dsym + !File.directory?(_1) && File.stat(_1).executable? + }.map { + # remove .exe extension if any (there will be one on Windows) + File.basename(_1, '.exe') + }.sort + + # we should end up with two executables + # * simple - the simple example from adder + # * using-adder - for this project + # ...and notably no test for adder, which must be disabled from the option override from above + assert_equal ['simple', 'using-adder'], exes end end