mirror of
https://github.com/cpm-cmake/CPM.cmake.git
synced 2025-11-19 07:37:42 -05:00
WiP for source cache test
This commit is contained in:
@@ -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
|
||||
|
||||
13
test/integration/templates/using-fibadder/lists.in.cmake
Normal file
13
test/integration/templates/using-fibadder/lists.in.cmake
Normal file
@@ -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)
|
||||
@@ -0,0 +1,8 @@
|
||||
#include <fibadder/fibadder.hpp>
|
||||
#include <cstdio>
|
||||
|
||||
int main() {
|
||||
int sum = fibadder::fibadd(6, 7);
|
||||
std::printf("%d\n", sum);
|
||||
return 0;
|
||||
}
|
||||
@@ -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
|
||||
|
||||
67
test/integration/test_source_cache.rb
Normal file
67
test/integration/test_source_cache.rb
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user