From c74a739cafd39c0a1928dd4824f0a043f00d76be Mon Sep 17 00:00:00 2001 From: Borislav Stanimirov Date: Wed, 19 May 2021 20:48:29 +0300 Subject: [PATCH] Some experimental code to setup tests --- test/integration/.gitignore | 1 + test/integration/runner.rb | 53 ++++++++++++++++++++++++++++++-- test/integration/tests/simple.rb | 4 ++- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 test/integration/.gitignore diff --git a/test/integration/.gitignore b/test/integration/.gitignore new file mode 100644 index 0000000..3fec32c --- /dev/null +++ b/test/integration/.gitignore @@ -0,0 +1 @@ +tmp/ diff --git a/test/integration/runner.rb b/test/integration/runner.rb index 31acf86..d0ecabd 100644 --- a/test/integration/runner.rb +++ b/test/integration/runner.rb @@ -1,3 +1,52 @@ -Dir['tests/*.rb'].sort.each do |f| - require('./' + f) +require 'fileutils' + +CPMPath = File.expand_path('../../cmake/CPM.cmake') +raise "Cannot file 'CPM.cmake' at '#{CPMPath}'" if !File.file?(CPMPath) + +CommonHeader = <<~CMAKE + cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + include("#{CPMPath}") + set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin") +CMAKE + +TestDir = File.expand_path("./tmp/#{Time.now.strftime('%Y_%m_%d-%H_%M_%S')}") +raise "Test directory '#{TestDir}' already exists" if File.exist?(TestDir) + +class Project + def initialize(name) + @name = name + @dir = File.join(TestDir, name) + + @lists = CommonHeader + "project(#{name})\n" + + FileUtils.mkdir_p(File.join(TestDir, name)) + end + + def set_body(body) + @lists += "\n" + body + "\n" + end + + def configure() + File.write(File.join(@dir, 'CMakeLists.txt'), @lists) + end +end + +@cur_file = '' +@tests = {} +def add_test(name, func) + raise "#{@cur_file}: Test #{name} is already defined from another file" if @tests[name] + @tests[name] = func +end + +Dir['tests/*.rb'].sort.each do |file| + @cur_file = file + load './' + file +end + +# sort alphabetically +sorted_tests = @tests.to_a.sort {|a, b| a[0] <=> b[0] } + +sorted_tests.each do |name, func| + proj = Project.new(name) + func.(proj) end diff --git a/test/integration/tests/simple.rb b/test/integration/tests/simple.rb index cb222f8..929de5b 100644 --- a/test/integration/tests/simple.rb +++ b/test/integration/tests/simple.rb @@ -1,7 +1,9 @@ -add_test('basic') { |prj| +add_test 'basic', ->(prj) { prj.set_body <<~CMAKE CPMAddPackage("gh:cpm-cmake/testpack-adder") add_executable(using-adder using-adder.cpp) target_link_libraries(using-adder PRIVATE adder) CMAKE + + prj.configure }