mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-22 04:07:49 -05:00
test_update_single_package
This commit is contained in:
@@ -32,12 +32,12 @@ puts "Running CPM.cmake integration tests"
|
|||||||
puts "Temp directory: '#{TestLib::TMP_DIR}'"
|
puts "Temp directory: '#{TestLib::TMP_DIR}'"
|
||||||
|
|
||||||
class Project
|
class Project
|
||||||
def initialize(src_dir, build_dir)
|
def initialize(src_dir, bin_dir)
|
||||||
@src_dir = src_dir
|
@src_dir = src_dir
|
||||||
@build_dir = build_dir
|
@bin_dir = bin_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
attr :src_dir, :build_dir
|
attr :src_dir, :bin_dir
|
||||||
|
|
||||||
def create_file(target_path, text)
|
def create_file(target_path, text)
|
||||||
target_path = File.join(@src_dir, target_path)
|
target_path = File.join(@src_dir, target_path)
|
||||||
@@ -64,7 +64,10 @@ class Project
|
|||||||
|
|
||||||
CommandResult = Struct.new :out, :err, :status
|
CommandResult = Struct.new :out, :err, :status
|
||||||
def configure(extra_args = '')
|
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
|
end
|
||||||
|
|
||||||
class CMakeCache
|
class CMakeCache
|
||||||
@@ -132,7 +135,7 @@ class Project
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
def read_cache
|
def read_cache
|
||||||
CMakeCache.from_dir @build_dir
|
CMakeCache.from_dir @bin_dir
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -171,6 +174,6 @@ class IntegrationTest < Test::Unit::TestCase
|
|||||||
FileUtils.copy_entry template_dir, src_dir
|
FileUtils.copy_entry template_dir, src_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
Project.new src_dir, base + '-build'
|
Project.new src_dir, base + '-bin'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
|||||||
|
|
||||||
project(using-adder)
|
project(using-adder)
|
||||||
|
|
||||||
|
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
|
||||||
|
|
||||||
include("%{cpm_path}")
|
include("%{cpm_path}")
|
||||||
|
|
||||||
%{packages}
|
%{packages}
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
require_relative './lib'
|
require_relative './lib'
|
||||||
|
|
||||||
|
# Tests of cpm caches and vars when no packages are used
|
||||||
|
|
||||||
class Basics < IntegrationTest
|
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
|
def test_cpm_default
|
||||||
prj = make_project 'no-deps'
|
prj = make_project 'no-deps'
|
||||||
prj.create_lists_with({})
|
prj.create_lists_with({})
|
||||||
|
|
||||||
cfg_result = prj.configure
|
cfg_result = prj.configure
|
||||||
assert_success cfg_result
|
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_DONT_CREATE_PACKAGE_LOCK', 'BOOL')
|
||||||
assert_equal 'OFF', check_and_get('CPM_INCLUDE_ALL_IN_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_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
|
end
|
||||||
|
|
||||||
def check_and_get(key, type = 'INTERNAL')
|
def check_and_get(key, type = 'INTERNAL')
|
||||||
|
|||||||
@@ -1,41 +1,89 @@
|
|||||||
require_relative './lib'
|
require_relative './lib'
|
||||||
|
|
||||||
class Simple < IntegrationTest
|
class Simple < IntegrationTest
|
||||||
P_ADDER = 'testpack-adder'
|
ADDER_PACKAGE_NAME = 'testpack-adder'
|
||||||
|
|
||||||
def test_add_remove_packages
|
def test_update_single_package
|
||||||
prj = make_project 'using-adder'
|
@prj = make_project 'using-adder'
|
||||||
|
|
||||||
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")'
|
create_with_commit_sha
|
||||||
assert_success prj.configure
|
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
|
assert_equal 1, cache.packages.size
|
||||||
|
|
||||||
adder = cache.packages[P_ADDER]
|
adder_cache = cache.packages[ADDER_PACKAGE_NAME]
|
||||||
assert_not_nil adder
|
assert_not_nil adder_cache
|
||||||
assert_equal '0', adder.ver
|
assert_equal '0', adder_cache.ver
|
||||||
assert File.directory? adder.src_dir
|
assert File.directory? adder_cache.src_dir
|
||||||
assert File.directory? adder.bin_dir
|
assert File.directory? adder_cache.bin_dir
|
||||||
|
|
||||||
adder_ver_file = File.join(adder.src_dir, 'version')
|
@adder_ver_file = File.join(adder_cache.src_dir, 'version')
|
||||||
assert File.file? adder_ver_file
|
assert File.file? @adder_ver_file
|
||||||
assert_equal 'initial', File.read(adder_ver_file).strip
|
assert_equal 'initial', File.read(@adder_ver_file).strip
|
||||||
|
|
||||||
# reconfigure with new version
|
# calculated adder values
|
||||||
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder@1.0.0")'
|
assert_equal 'ON', cache['ADDER_BUILD_EXAMPLES']
|
||||||
assert_success prj.configure
|
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
|
assert_equal 1, cache.packages.size
|
||||||
|
|
||||||
adder = cache.packages[P_ADDER]
|
adder_cache = cache.packages[ADDER_PACKAGE_NAME]
|
||||||
assert_not_nil adder
|
assert_not_nil adder_cache
|
||||||
assert_equal '1.0.0', adder.ver
|
assert_equal '1.0.0', adder_cache.ver
|
||||||
|
|
||||||
# dir shouldn't have changed
|
# dirs shouldn't have changed
|
||||||
assert_equal File.dirname(adder_ver_file), adder.src_dir
|
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/<Config>
|
||||||
|
# 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
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user