From cef108e86ebc409449794cd77dd69f407924931b Mon Sep 17 00:00:00 2001 From: Borislav Stanimirov Date: Wed, 12 Jan 2022 17:12:01 +0200 Subject: [PATCH] WiP for source cache test --- test/integration/lib.rb | 18 ++++- .../templates/using-fibadder/lists.in.cmake | 13 ++++ .../using-fibadder/using-fibadder.cpp | 8 +++ test/integration/test_basics.rb | 17 ++++- test/integration/test_source_cache.rb | 67 +++++++++++++++++++ 5 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 test/integration/templates/using-fibadder/lists.in.cmake create mode 100644 test/integration/templates/using-fibadder/using-fibadder.cpp create mode 100644 test/integration/test_source_cache.rb diff --git a/test/integration/lib.rb b/test/integration/lib.rb index 1337ba5..2fad5f6 100644 --- a/test/integration/lib.rb +++ b/test/integration/lib.rb @@ -158,12 +158,28 @@ class IntegrationTest < Test::Unit::TestCase end # utils + class << self + def startup + @@test_dir = File.join(TestLib::TMP_DIR, self.name. + # to-underscore conversion from Rails + gsub(/::/, '/'). + gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2'). + gsub(/([a-z\d])([A-Z])/,'\1_\2'). + tr("-", "_"). + downcase + ) + end + end + + def cur_test_dir + @@test_dir + end def make_project(template_dir = nil) test_name = local_name test_name = test_name[5..] if test_name.start_with?('test_') - base = File.join(TestLib::TMP_DIR, self.class.name.downcase, test_name) + base = File.join(cur_test_dir, test_name) src_dir = base + '-src' FileUtils.mkdir_p src_dir diff --git a/test/integration/templates/using-fibadder/lists.in.cmake b/test/integration/templates/using-fibadder/lists.in.cmake new file mode 100644 index 0000000..5b4e679 --- /dev/null +++ b/test/integration/templates/using-fibadder/lists.in.cmake @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +project(using-fibadder) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) + +include("%{cpm_path}") + +%{packages} + +add_executable(using-fibadder using-fibadder.cpp) + +target_link_libraries(using-fibadder fibadder) diff --git a/test/integration/templates/using-fibadder/using-fibadder.cpp b/test/integration/templates/using-fibadder/using-fibadder.cpp new file mode 100644 index 0000000..3e01478 --- /dev/null +++ b/test/integration/templates/using-fibadder/using-fibadder.cpp @@ -0,0 +1,8 @@ +#include +#include + +int main() { + int sum = fibadder::fibadd(6, 7); + std::printf("%d\n", sum); + return 0; +} diff --git a/test/integration/test_basics.rb b/test/integration/test_basics.rb index f3db6e9..35518e0 100644 --- a/test/integration/test_basics.rb +++ b/test/integration/test_basics.rb @@ -7,9 +7,7 @@ class Basics < IntegrationTest def test_cpm_default prj = make_project 'no-deps' prj.create_lists_with({}) - - cfg_result = prj.configure - assert_success cfg_result + assert_success prj.configure @cache = prj.read_cache @@ -36,6 +34,19 @@ class Basics < IntegrationTest assert_same_path File.join(prj.bin_dir, 'CPM_modules'), check_and_get('CPM_MODULE_PATH') end + # Test when env CPM_SOURCE_CACHE is set + def test_env_cpm_source_cache + ENV['CPM_SOURCE_CACHE'] = cur_test_dir + + prj = make_project 'no-deps' + prj.create_lists_with({}) + assert_success prj.configure + + @cache = prj.read_cache + + assert_equal cur_test_dir, check_and_get('CPM_SOURCE_CACHE', 'PATH') + end + def check_and_get(key, type = 'INTERNAL') e = @cache.entries[key] assert_not_nil e, key diff --git a/test/integration/test_source_cache.rb b/test/integration/test_source_cache.rb new file mode 100644 index 0000000..a6da52a --- /dev/null +++ b/test/integration/test_source_cache.rb @@ -0,0 +1,67 @@ +require_relative './lib' + +# Tests with source cache + +class SourceCache < IntegrationTest + def setup + super + @cache_dir = File.join(cur_test_dir, 'cpmcache') + ENV['CPM_SOURCE_CACHE'] = @cache_dir + end + + def test_add_remove_dependency + @prj = make_project 'using-fibadder' + + create_with_fibadder + end + + def test_second_project + # @prj = make_project 'using-fibadder' + + # create_with_newer_fibadder + end + + def dir_subdirs(dir) + Dir["#{dir}/*/"] + end + + def check_package_cache(name, ver, dir_sha1) + package = @cache.packages[name] + assert_not_nil package, name + assert_equal ver, package.ver + assert package.src_dir.start_with?(@cache_dir), "#{package.src_dir} must be in #{@cache_dir}" + assert_equal dir_sha1, File.basename(package.src_dir) + end + + def create_with_fibadder + @prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")' + assert_success @prj.configure + + @cache = @prj.read_cache + + # fibadder - adder + # \ fibonacci - Format + assert_equal 4, @cache.packages.size + + check_package_cache 'testpack-fibadder', '1.0.0', '6a17d24c95c44a169ff8ba173f52876a2ba3d137' + check_package_cache 'testpack-adder', '1.0.0', '1a4c153849d8e0cf9a3a245e5f6ab6e4722d8995' + check_package_cache 'testpack-fibonacci', '2.0', '332c789cb09b8c2f92342dfb874c82bec643daf6' + check_package_cache 'Format.cmake', '1.0', 'c5897bd28c5032d45f7f669c8fb470790d2ae156' + end + + def create_with_newer_fibadder + @prj.create_lists_with package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.1.0")' + assert_success @prj.configure + + @cache = @prj.read_cache + + # fibadder - adder + # \ fibonacci - Format + assert_equal 4, @cache.packages.size + + check_package_cache 'testpack-fibadder', '1.1.0', '6a17d24c95c44a169ff8ba173f52876a2ba3d137' + check_package_cache 'testpack-adder', '1.0.1', '1a4c153849d8e0cf9a3a245e5f6ab6e4722d8995' + check_package_cache 'testpack-fibonacci', '2.0', '332c789cb09b8c2f92342dfb874c82bec643daf6' + check_package_cache 'Format.cmake', '1.0', 'c5897bd28c5032d45f7f669c8fb470790d2ae156' + end +end