diff --git a/test/integration/lib.rb b/test/integration/lib.rb index 824b0eb..5323f1c 100644 --- a/test/integration/lib.rb +++ b/test/integration/lib.rb @@ -37,6 +37,8 @@ class Project @build_dir = build_dir end + attr :src_dir, :build_dir + def create_file(target_path, text) target_path = File.join(@src_dir, target_path) File.write target_path, text @@ -47,9 +49,9 @@ class Project raise "#{source_path} doesn't exist" if !File.file?(source_path) # 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[: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 create_file target_path, src_text % args @@ -147,6 +149,11 @@ class IntegrationTest < Test::Unit::TestCase assert_block(msg) { res.status.success? } 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 def make_project(template_dir = nil) diff --git a/test/integration/templates/no-deps/lists.in.cmake b/test/integration/templates/no-deps/lists.in.cmake new file mode 100644 index 0000000..ae4e136 --- /dev/null +++ b/test/integration/templates/no-deps/lists.in.cmake @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +project(no-deps) + +include("%{cpm_path}") + +add_executable(no-deps main.c) diff --git a/test/integration/templates/no-deps/main.c b/test/integration/templates/no-deps/main.c new file mode 100644 index 0000000..d7f6d64 --- /dev/null +++ b/test/integration/templates/no-deps/main.c @@ -0,0 +1,6 @@ +#include + +int main() { + puts("Hello"); + return 0; +} diff --git a/test/integration/test_basics.rb b/test/integration/test_basics.rb new file mode 100644 index 0000000..c6e941d --- /dev/null +++ b/test/integration/test_basics.rb @@ -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 diff --git a/test/integration/test_simple.rb b/test/integration/test_simple.rb index 55374ed..80ca7ef 100644 --- a/test/integration/test_simple.rb +++ b/test/integration/test_simple.rb @@ -3,7 +3,7 @@ require_relative './lib' class Simple < IntegrationTest P_ADDER = 'testpack-adder' - def test_basics + def test_add_remove_packages prj = make_project 'using-adder' prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-adder#cad1cd4b4cdf957c5b59e30bc9a1dd200dbfc716")'