2016-03-12 18:26:14 +00:00
|
|
|
#include <ostd/platform.hh>
|
|
|
|
#include <ostd/io.hh>
|
|
|
|
#include <ostd/string.hh>
|
2017-02-25 13:56:51 +00:00
|
|
|
#include <ostd/unordered_map.hh>
|
2016-03-12 18:26:14 +00:00
|
|
|
#include <ostd/filesystem.hh>
|
2016-03-13 01:28:39 +00:00
|
|
|
#include <ostd/environ.hh>
|
2016-03-12 18:26:14 +00:00
|
|
|
|
|
|
|
using namespace ostd;
|
|
|
|
|
|
|
|
#ifndef OSTD_PLATFORM_WIN32
|
2017-02-25 13:56:51 +00:00
|
|
|
constexpr auto COLOR_RED = "\033[91m";
|
|
|
|
constexpr auto COLOR_GREEN = "\033[92m";
|
|
|
|
constexpr auto COLOR_BLUE = "\033[94m";
|
|
|
|
constexpr auto COLOR_BOLD = "\033[1m";
|
|
|
|
constexpr auto COLOR_END = "\033[0m";
|
2016-03-12 18:26:14 +00:00
|
|
|
#else
|
2017-02-25 13:56:51 +00:00
|
|
|
constexpr auto COLOR_RED = "";
|
|
|
|
constexpr auto COLOR_GREEN = "";
|
|
|
|
constexpr auto COLOR_BLUE = "";
|
|
|
|
constexpr auto COLOR_BOLD = "";
|
|
|
|
constexpr auto COLOR_END = "";
|
2016-03-12 18:26:14 +00:00
|
|
|
#endif
|
|
|
|
|
2016-03-13 01:28:39 +00:00
|
|
|
int main() {
|
|
|
|
/* configurable section */
|
|
|
|
|
2016-07-08 18:48:11 +00:00
|
|
|
auto compiler = env_get("CXX").value_or("c++");
|
2017-01-29 20:22:40 +00:00
|
|
|
auto cxxflags = "-std=c++1z -I. -Wall -Wextra -Wshadow -Wold-style-cast "
|
2016-03-15 22:28:43 +00:00
|
|
|
"-Wno-missing-braces"; /* clang false positive */
|
2016-07-08 18:48:11 +00:00
|
|
|
auto testdir = env_get("TESTDIR").value_or("tests");
|
2016-03-13 01:28:39 +00:00
|
|
|
auto srcext = ".cc";
|
|
|
|
|
2016-07-08 18:48:11 +00:00
|
|
|
auto userflags = env_get("CXXFLAGS").value_or("");
|
2016-03-13 01:28:39 +00:00
|
|
|
|
|
|
|
/* do not change past this point */
|
|
|
|
|
2016-03-12 18:26:14 +00:00
|
|
|
int nsuccess = 0, nfailed = 0;
|
2017-02-25 13:56:51 +00:00
|
|
|
string_range modname = nullptr;
|
2016-03-12 18:26:14 +00:00
|
|
|
|
2017-02-25 13:56:51 +00:00
|
|
|
auto print_result = [&](string_range fmsg = nullptr) {
|
2016-03-12 18:38:32 +00:00
|
|
|
write(modname, "...\t");
|
2016-03-12 18:26:14 +00:00
|
|
|
if (!fmsg.empty()) {
|
2017-02-25 13:56:51 +00:00
|
|
|
writeln(COLOR_RED, COLOR_BOLD, '(', fmsg, ')', COLOR_END);
|
2016-03-12 18:26:14 +00:00
|
|
|
++nfailed;
|
|
|
|
} else {
|
2017-02-25 13:56:51 +00:00
|
|
|
writeln(COLOR_GREEN, COLOR_BOLD, "(success)", COLOR_END);
|
2016-03-12 18:26:14 +00:00
|
|
|
++nsuccess;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-02-25 13:56:51 +00:00
|
|
|
directory_stream ds{testdir};
|
2017-01-23 23:35:07 +00:00
|
|
|
for (auto v: iter(ds)) {
|
2017-02-25 13:56:51 +00:00
|
|
|
if ((v.type() != file_type::REGULAR) || (v.extension() != srcext))
|
2016-03-12 18:26:14 +00:00
|
|
|
continue;
|
|
|
|
|
2016-03-13 01:28:39 +00:00
|
|
|
modname = v.stem();
|
|
|
|
|
2017-02-25 13:56:51 +00:00
|
|
|
std::string exepath = testdir;
|
|
|
|
exepath += PATH_SEPARATOR;
|
2016-03-13 01:28:39 +00:00
|
|
|
exepath += modname;
|
2016-07-08 23:48:29 +00:00
|
|
|
#ifdef OSTD_PLATFORM_WIN32
|
|
|
|
exepath += ".exe";
|
|
|
|
#endif
|
2016-03-13 01:28:39 +00:00
|
|
|
|
2017-02-25 13:56:51 +00:00
|
|
|
auto cxxcmd = appender<std::string>();
|
|
|
|
format(cxxcmd, "%s %s%s%s -o %s %s", compiler, testdir, PATH_SEPARATOR,
|
2016-03-13 01:28:39 +00:00
|
|
|
v.filename(), exepath, cxxflags);
|
2016-03-12 18:38:32 +00:00
|
|
|
if (!userflags.empty()) {
|
2016-03-15 22:28:43 +00:00
|
|
|
cxxcmd.get() += ' ';
|
2016-03-13 01:28:39 +00:00
|
|
|
cxxcmd.get() += userflags;
|
2016-03-12 18:38:32 +00:00
|
|
|
}
|
2016-03-13 01:28:39 +00:00
|
|
|
int ret = system(cxxcmd.get().data());
|
2016-03-12 18:26:14 +00:00
|
|
|
if (ret) {
|
2016-03-13 01:28:39 +00:00
|
|
|
print_result("compile errror");
|
2016-03-12 18:26:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = system(exepath.data());
|
|
|
|
if (ret) {
|
2016-03-13 01:28:39 +00:00
|
|
|
print_result("runtime error");
|
2016-03-12 18:26:14 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
remove(exepath.data());
|
2016-03-13 01:28:39 +00:00
|
|
|
print_result();
|
2016-03-12 18:26:14 +00:00
|
|
|
}
|
|
|
|
|
2017-02-25 13:56:51 +00:00
|
|
|
writeln("\n", COLOR_BLUE, COLOR_BOLD, "testing done:", COLOR_END);
|
|
|
|
writeln(COLOR_GREEN, "SUCCESS: ", nsuccess, COLOR_END);
|
|
|
|
writeln(COLOR_RED, "FAILURE: ", nfailed, COLOR_END);
|
2016-03-12 18:26:14 +00:00
|
|
|
}
|