Initial attempt at adding tests

toml-checker
Duncan Ogilvie 4 years ago
parent 598c9b9ba8
commit 326647011b

@ -6,6 +6,7 @@ jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-2016, windows-2019, macos-10.15, ubuntu-16.04, ubuntu-18.04, ubuntu-20.04]
env:
@ -17,3 +18,7 @@ jobs:
run: |
cmake -S. -Bbuild -DCMAKE_BUILD_TYPE=${{ env.BUILD_TYPE }}
cmake --build build --config ${{ env.BUILD_TYPE }} --parallel
- name: Test
run: |
cd build/tests
ctest -C ${{ env.BUILD_TYPE }}

@ -46,6 +46,16 @@ endif()
add_subdirectory(third_party)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})
# tests
set(CMKR_CMAKE_FOLDER ${CMAKE_FOLDER})
if(CMAKE_FOLDER)
set(CMAKE_FOLDER "${CMAKE_FOLDER}/tests")
else()
set(CMAKE_FOLDER tests)
endif()
add_subdirectory(tests)
set(CMAKE_FOLDER ${CMKR_CMAKE_FOLDER})
# Target cmkrlib
set(cmkrlib_SOURCES

@ -11,7 +11,7 @@ name = "cmkr"
version = "0.1.3"
description = "CMakeLists generator from TOML"
languages = ["CXX"]
subdirs = ["third_party"]
subdirs = ["third_party", "tests"]
[target.cmkrlib]
type = "static"

@ -22,9 +22,8 @@ int run(int argc, char **argv) {
}
std::stringstream ss;
if (!fs::exists("CMakeLists.txt"))
if (gen::generate_cmake(fs::current_path().string().c_str()))
throw std::runtime_error("CMake generation failure!");
if (gen::generate_cmake(fs::current_path().string().c_str()))
throw std::runtime_error("CMake generation failure!");
ss << "cmake -S. -B" << cmake.build_dir << " ";

@ -204,8 +204,10 @@ CMake::CMake(const std::string &path, bool build) {
for (const auto &t : ts) {
Test test;
test.name = toml::find(t, "name").as_string();
test.cmd = toml::find(t, "type").as_string();
get_optional(t, "arguments", test.args);
get_optional(t, "configurations", test.configurations);
get_optional(t, "working-directory", test.working_directory);
test.command = toml::find(t, "command").as_string();
get_optional(t, "arguments", test.arguments);
tests.push_back(test);
}
}

@ -72,8 +72,10 @@ struct Target {
struct Test {
std::string name;
std::string cmd;
std::vector<std::string> args;
std::vector<std::string> configurations;
std::string working_directory;
std::string command;
std::vector<std::string> arguments;
};
struct Install {

@ -611,12 +611,14 @@ int generate_cmake(const char *path, bool root) {
}
if (!cmake.tests.empty()) {
cmd("include")("CTest");
cmd("enable_testing")().endl();
for (const auto &test : cmake.tests) {
auto name = std::make_pair("NAME", test.name);
auto command = std::make_pair("COMMAND", test.cmd);
cmd("add_test")(name, command, test.args).endl();
auto configurations = std::make_pair("CONFIGURATIONS", test.configurations);
auto working_directory = std::make_pair("WORKING_DIRECTORY", test.working_directory);
auto command = std::make_pair("COMMAND", test.command);
auto arguments = std::make_pair("", test.arguments);
cmd("add_test")(name, configurations, working_directory, command, arguments).endl();
}
}

@ -0,0 +1,19 @@
# This file was generated automatically by cmkr.
# Create a configure-time dependency on cmake.toml to improve IDE support
if(CMKR_ROOT_PROJECT)
configure_file(cmake.toml cmake.toml COPYONLY)
endif()
enable_testing()
add_test(
NAME
basic
WORKING_DIRECTORY
"${CMAKE_CURRENT_LIST_DIR}/basic"
COMMAND
$<TARGET_FILE:cmkr>
build
)

@ -0,0 +1,41 @@
# This file was generated automatically by cmkr.
cmake_minimum_required(VERSION 3.5)
# Regenerate CMakeLists.txt automatically in the root project
set(CMKR_ROOT_PROJECT OFF)
if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
set(CMKR_ROOT_PROJECT ON)
# Bootstrap cmkr
include(cmkr.cmake OPTIONAL RESULT_VARIABLE CMKR_INCLUDE_RESULT)
if(CMKR_INCLUDE_RESULT)
cmkr()
endif()
# Enable folder support
set_property(GLOBAL PROPERTY USE_FOLDERS ON)
endif()
# Create a configure-time dependency on cmake.toml to improve IDE support
if(CMKR_ROOT_PROJECT)
configure_file(cmake.toml cmake.toml COPYONLY)
endif()
project(basic)
# Target basic
set(basic_SOURCES
"src/basic.cpp"
cmake.toml
)
add_executable(basic ${basic_SOURCES})
get_directory_property(CMKR_VS_STARTUP_PROJECT DIRECTORY ${PROJECT_SOURCE_DIR} DEFINITION VS_STARTUP_PROJECT)
if(NOT CMKR_VS_STARTUP_PROJECT)
set_property(DIRECTORY ${PROJECT_SOURCE_DIR} PROPERTY VS_STARTUP_PROJECT basic)
endif()
source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR} FILES ${basic_SOURCES})

@ -0,0 +1,9 @@
[cmake]
version = "3.5"
[project]
name = "basic"
[target.basic]
type = "executable"
sources = ["src/basic.cpp"]

@ -0,0 +1,5 @@
#include <cstdio>
int main() {
puts("Hello from cmkr!");
}

@ -0,0 +1,5 @@
[[test]]
name = "basic"
command = "$<TARGET_FILE:cmkr>"
working-directory = "${CMAKE_CURRENT_LIST_DIR}/basic"
arguments = ["build"]
Loading…
Cancel
Save