diff --git a/test/integration/lib.rb b/test/integration/lib.rb index ee1cc524..53467ab3 100644 --- a/test/integration/lib.rb +++ b/test/integration/lib.rb @@ -173,7 +173,6 @@ def startup tr("-", "_"). downcase ) - @@proj_count = 0 end end @@ -181,20 +180,20 @@ def cur_test_dir @@test_dir end - def make_project(template_dir = nil) + def make_project(name: nil, from_template: nil) test_name = local_name test_name = test_name[5..] if test_name.start_with?('test_') - @@proj_count += 1 - base = File.join(cur_test_dir, test_name + '-' + @@proj_count.to_s) + base = File.join(cur_test_dir, test_name) + base += "-#{name}" if name src_dir = base + '-src' FileUtils.mkdir_p src_dir - if template_dir - template_dir = File.join(TestLib::TEMPLATES_DIR, template_dir) - raise "#{template_dir} is not a directory" if !File.directory?(template_dir) - FileUtils.copy_entry template_dir, src_dir + if from_template + from_template = File.join(TestLib::TEMPLATES_DIR, from_template) + raise "#{from_template} is not a directory" if !File.directory?(from_template) + FileUtils.copy_entry from_template, src_dir end Project.new src_dir, base + '-bin' diff --git a/test/integration/reference.md b/test/integration/reference.md index fd81450e..24089667 100644 --- a/test/integration/reference.md +++ b/test/integration/reference.md @@ -60,6 +60,7 @@ The class which must be a parent of all integration test case classes. It itself ### Utils * `cur_test_dir` - the directory of the current test case. A subdirectory of `TestLib::TMP_DIR` -* `make_project(template_dir = nil)` - create a project from a test method. Will create a the project's source and binary directories as subdirectories of `cur_test_dir`. - * Optionally work with a template directory, in which case it will copy the contents of the template directory (one from `templates`) in the project's source directory. +* `make_project(name: nil, from_template: nil)` - create a project from a test method. Will create a the project's source and binary directories as subdirectories of `cur_test_dir`. + * Optionally provide a name which will be concatenated to the project directory. This allows creating mulitple projects in a test + * Optionally work with a template, in which case it will copy the contents of the template directory (one from `templates`) in the project's source directory. diff --git a/test/integration/test_basics.rb b/test/integration/test_basics.rb index 8083123c..5cb6ccfd 100644 --- a/test/integration/test_basics.rb +++ b/test/integration/test_basics.rb @@ -5,7 +5,7 @@ class Basics < IntegrationTest # Test cpm caches with no cpm-related env vars def test_cpm_default - prj = make_project 'no-deps' + prj = make_project from_template: 'no-deps' prj.create_lists_from_default_template assert_success prj.configure @@ -38,7 +38,7 @@ def test_cpm_default def test_env_cpm_source_cache ENV['CPM_SOURCE_CACHE'] = cur_test_dir - prj = make_project 'no-deps' + prj = make_project from_template: 'no-deps' prj.create_lists_from_default_template assert_success prj.configure diff --git a/test/integration/test_fetchcontent_compatibility.rb b/test/integration/test_fetchcontent_compatibility.rb index 9cc5d7d2..29d1ef80 100644 --- a/test/integration/test_fetchcontent_compatibility.rb +++ b/test/integration/test_fetchcontent_compatibility.rb @@ -9,8 +9,8 @@ def setup end def test_add_dependency_cpm_and_fetchcontent - prj = make_project 'using-adder' - + prj = make_project from_template: 'using-adder' + prj.create_lists_from_default_template package: <<~PACK CPMAddPackage( NAME testpack-adder diff --git a/test/integration/test_parallelism.rb b/test/integration/test_parallelism.rb index c29bf5a5..fd43480a 100644 --- a/test/integration/test_parallelism.rb +++ b/test/integration/test_parallelism.rb @@ -7,18 +7,15 @@ def setup end def test_populate_cache_in_parallel - - [*1..4] - .map{ |i| - prj = make_project 'using-fibadder' - prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")' - prj - } - .map{ |prj| Thread.new do - assert_success prj.configure + 4.times.map { |i| + prj = make_project name: i.to_s, from_template: 'using-fibadder' + prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.0.0")' + prj + }.map { |prj| + Thread.new do + assert_success prj.configure assert_success prj.build - end } - .map { |t| t.join } - + end + }.map(&:join) end end diff --git a/test/integration/test_remove_source_dir.rb b/test/integration/test_remove_source_dir.rb index 852c12de..925e64b0 100644 --- a/test/integration/test_remove_source_dir.rb +++ b/test/integration/test_remove_source_dir.rb @@ -2,8 +2,8 @@ class RemoveSourceDir < IntegrationTest def test_remove_source_dir - prj = make_project 'using-adder' - + prj = make_project from_template: 'using-adder' + prj.create_lists_from_default_template package: <<~PACK CPMAddPackage( NAME testpack-adder diff --git a/test/integration/test_simple.rb b/test/integration/test_simple.rb index ff175bf2..a63eb6d4 100644 --- a/test/integration/test_simple.rb +++ b/test/integration/test_simple.rb @@ -4,7 +4,7 @@ class Simple < IntegrationTest ADDER_PACKAGE_NAME = 'testpack-adder' def test_update_single_package - prj = make_project 'using-adder' + prj = make_project from_template: 'using-adder' adder_cache0 = nil adder_ver_file = nil diff --git a/test/integration/test_source_cache.rb b/test/integration/test_source_cache.rb index fd8f92d3..ce2eb1d7 100644 --- a/test/integration/test_source_cache.rb +++ b/test/integration/test_source_cache.rb @@ -9,7 +9,7 @@ def setup end def test_add_remove_dependency - prj = make_project 'using-fibadder' + prj = make_project from_template: 'using-fibadder' ################################### # create @@ -45,7 +45,7 @@ def test_add_remove_dependency end def test_second_project - prj = make_project 'using-fibadder' + prj = make_project from_template: 'using-fibadder' prj.create_lists_from_default_template package: 'CPMAddPackage("gh:cpm-cmake/testpack-fibadder@1.1.0")' assert_success prj.configure