support testing

self-hosting
Mohammed Alyousef 4 years ago
parent 2117893b87
commit ef166277ea

@ -5,4 +5,5 @@
- Add support for find_package components.
- Add options.
- Support aliases.
- Support interface libs (header-only libs).
- Support interface libs (header-only libs).
- Support testing.

@ -91,6 +91,11 @@ alias = "" # optional
features = [] # optional
defines = [] # optional
link-libs = [] # optional
[[test]] # optional
name = "test1" # required
command = "cmkr" # required
arguments = [] # optional
```
The cmkr executable can be run from the command-line:
@ -129,4 +134,3 @@ Header only library.
## Roadmap
- Support more cmake fields.
- Support conditional cmake args somehow!
- Support ctest.

@ -30,6 +30,12 @@ struct Bin {
std::string alias;
};
struct Test {
std::string name;
std::string cmd;
std::vector<std::string> args;
};
struct CMake {
std::string cmake_version = "3.14";
std::string bin_dir = "bin";
@ -46,6 +52,7 @@ struct CMake {
std::vector<Package> packages;
std::map<std::string, std::map<std::string, std::string>> contents;
std::vector<Bin> binaries;
std::vector<Test> tests;
CMake(const std::string &path, bool build);
};

@ -39,4 +39,9 @@ include-dirs = ["include"]
# features = []
# defines = []
# link-libs = []
# [[test]]]
# name = "test1"
# command = "%s"
# arguments = []
)lit";

@ -152,6 +152,19 @@ CMake::CMake(const std::string &path, bool build) {
binaries.push_back(b);
}
}
if (toml.contains("test")) {
const auto &ts = toml::find(toml, "test").as_array();
for (const auto &t : ts) {
Test test;
test.name = toml::find(t, "name").as_string();
test.cmd = toml::find(t, "type").as_string();
if (t.contains("arguments")) {
test.args = detail::to_string_vec(toml::find(t, "arguments").as_array());
}
tests.push_back(test);
}
}
}
}
} // namespace cmkr::cmake

@ -46,7 +46,8 @@ int generate_project(const char *str) {
fs::create_directory("include");
const auto dir_name = fs::current_path().stem().string();
std::string mainbuf;
const auto tomlbuf = detail::format(cmake_toml, dir_name.c_str(), dir_name.c_str(), str);
const auto tomlbuf =
detail::format(cmake_toml, dir_name.c_str(), dir_name.c_str(), str, dir_name.c_str());
if (!strcmp(str, "exe")) {
mainbuf = detail::format(hello_world, "main");
} else if (!strcmp(str, "static") || !strcmp(str, "shared") || !strcmp(str, "lib")) {
@ -247,6 +248,20 @@ int generate_cmake(const char *path) {
}
}
if (!cmake.tests.empty()) {
ss << "include(CTest)\n"
<< "enable_testing()\n\n";
for (const auto &test : cmake.tests) {
ss << "add_test(NAME " << test.name << " COMMAND " << test.cmd;
if (!test.args.empty()) {
for (const auto &arg : test.args) {
ss << " " << arg;
}
}
ss << ")\n\n";
}
}
ss << "\n\n";
// printf("%s\n", ss.str().c_str());

Loading…
Cancel
Save