mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-22 12:17:36 -05:00
Added test for CPM-specific CMakeCache values
This commit is contained in:
@@ -37,6 +37,8 @@ class Project
|
|||||||
@build_dir = build_dir
|
@build_dir = build_dir
|
||||||
end
|
end
|
||||||
|
|
||||||
|
attr :src_dir, :build_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)
|
||||||
File.write target_path, text
|
File.write target_path, text
|
||||||
@@ -47,9 +49,9 @@ class Project
|
|||||||
raise "#{source_path} doesn't exist" if !File.file?(source_path)
|
raise "#{source_path} doesn't exist" if !File.file?(source_path)
|
||||||
|
|
||||||
# tweak args
|
# tweak args
|
||||||
args[:cpm_path] = TestLib::CPM_PATH
|
args[:cpm_path] = TestLib::CPM_PATH if !args[:cpm_path]
|
||||||
args[:packages] = [args[:package]] if args[:package] # if args contain package, create the array
|
args[:packages] = [args[:package]] if args[:package] # if args contain package, create the array
|
||||||
args[:packages] = args[:packages].join("\n") # join all packages
|
args[:packages] = args[:packages].join("\n") if args[:packages] # join all packages if any
|
||||||
|
|
||||||
src_text = File.read source_path
|
src_text = File.read source_path
|
||||||
create_file target_path, src_text % args
|
create_file target_path, src_text % args
|
||||||
@@ -147,6 +149,11 @@ class IntegrationTest < Test::Unit::TestCase
|
|||||||
assert_block(msg) { res.status.success? }
|
assert_block(msg) { res.status.success? }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_same_path(a, b)
|
||||||
|
msg = build_message(nil, "<?> expected but was\n<?>", a, b)
|
||||||
|
assert_block(msg) { File.identical? a, b }
|
||||||
|
end
|
||||||
|
|
||||||
# utils
|
# utils
|
||||||
|
|
||||||
def make_project(template_dir = nil)
|
def make_project(template_dir = nil)
|
||||||
|
|||||||
7
test/integration/templates/no-deps/lists.in.cmake
Normal file
7
test/integration/templates/no-deps/lists.in.cmake
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.14 FATAL_ERROR)
|
||||||
|
|
||||||
|
project(no-deps)
|
||||||
|
|
||||||
|
include("%{cpm_path}")
|
||||||
|
|
||||||
|
add_executable(no-deps main.c)
|
||||||
6
test/integration/templates/no-deps/main.c
Normal file
6
test/integration/templates/no-deps/main.c
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
puts("Hello");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
42
test/integration/test_basics.rb
Normal file
42
test/integration/test_basics.rb
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
require_relative './lib'
|
||||||
|
|
||||||
|
class Basics < IntegrationTest
|
||||||
|
# test cpm coherency 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
|
||||||
|
|
||||||
|
@cache = prj.read_cache
|
||||||
|
|
||||||
|
assert_empty @cache.packages
|
||||||
|
|
||||||
|
assert_same_path TestLib::CPM_PATH, check_and_get('CPM_FILE')
|
||||||
|
assert_same_path File.dirname(TestLib::CPM_PATH), check_and_get('CPM_DIRECTORY')
|
||||||
|
|
||||||
|
assert_equal 'OFF', check_and_get('CPM_DRY_RUN')
|
||||||
|
assert_equal 'CPM:', check_and_get('CPM_INDENT')
|
||||||
|
assert_equal '1.0.0-development-version', check_and_get('CPM_VERSION')
|
||||||
|
|
||||||
|
assert_equal 'OFF', check_and_get('CPM_SOURCE_CACHE', 'PATH')
|
||||||
|
assert_equal 'OFF', check_and_get('CPM_DOWNLOAD_ALL', 'BOOL')
|
||||||
|
assert_equal 'OFF', check_and_get('CPM_LOCAL_PACKAGES_ONLY', 'BOOL')
|
||||||
|
assert_equal 'OFF', check_and_get('CPM_USE_LOCAL_PACKAGES', 'BOOL')
|
||||||
|
assert_equal 'OFF', check_and_get('CPM_USE_NAMED_CACHE_DIRECTORIES', '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_same_path File.join(prj.build_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')
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_and_get(key, type = 'INTERNAL')
|
||||||
|
e = @cache.entries[key]
|
||||||
|
assert_not_nil e, key
|
||||||
|
assert_equal type, e.type, key
|
||||||
|
e.val
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -3,7 +3,7 @@ require_relative './lib'
|
|||||||
class Simple < IntegrationTest
|
class Simple < IntegrationTest
|
||||||
P_ADDER = 'testpack-adder'
|
P_ADDER = 'testpack-adder'
|
||||||
|
|
||||||
def test_basics
|
def test_add_remove_packages
|
||||||
prj = make_project 'using-adder'
|
prj = make_project 'using-adder'
|
||||||
|
|
||||||
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")'
|
prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")'
|
||||||
|
|||||||
Reference in New Issue
Block a user