2016-03-12 18:26:14 +00:00
|
|
|
#include <ostd/platform.hh>
|
|
|
|
#include <ostd/io.hh>
|
|
|
|
#include <ostd/string.hh>
|
|
|
|
#include <ostd/map.hh>
|
|
|
|
#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
|
2016-03-13 01:28:39 +00:00
|
|
|
constexpr auto ColorRed = "\033[91m";
|
|
|
|
constexpr auto ColorGreen = "\033[92m";
|
|
|
|
constexpr auto ColorBlue = "\033[94m";
|
|
|
|
constexpr auto ColorBold = "\033[1m";
|
|
|
|
constexpr auto ColorEnd = "\033[0m";
|
2016-03-12 18:26:14 +00:00
|
|
|
#else
|
2016-03-13 01:28:39 +00:00
|
|
|
constexpr auto ColorRed = "";
|
|
|
|
constexpr auto ColorGreen = "";
|
|
|
|
constexpr auto ColorBlue = "";
|
|
|
|
constexpr auto ColorBold = "";
|
|
|
|
constexpr auto ColorEnd = "";
|
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;
|
2016-03-13 01:28:39 +00:00
|
|
|
ConstCharRange modname = nullptr;
|
2016-03-12 18:26:14 +00:00
|
|
|
|
2016-03-13 01:28:39 +00:00
|
|
|
auto print_result = [&](ConstCharRange fmsg = nullptr) {
|
2016-03-12 18:38:32 +00:00
|
|
|
write(modname, "...\t");
|
2016-03-12 18:26:14 +00:00
|
|
|
if (!fmsg.empty()) {
|
2016-03-15 22:28:43 +00:00
|
|
|
writeln(ColorRed, ColorBold, '(', fmsg, ')', ColorEnd);
|
2016-03-12 18:26:14 +00:00
|
|
|
++nfailed;
|
|
|
|
} else {
|
2016-03-13 01:28:39 +00:00
|
|
|
writeln(ColorGreen, ColorBold, "(success)", ColorEnd);
|
2016-03-12 18:26:14 +00:00
|
|
|
++nsuccess;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
DirectoryStream ds(testdir);
|
2017-01-23 23:35:07 +00:00
|
|
|
for (auto v: iter(ds)) {
|
2016-03-13 01:28:39 +00:00
|
|
|
if ((v.type() != FileType::regular) || (v.extension() != srcext))
|
2016-03-12 18:26:14 +00:00
|
|
|
continue;
|
|
|
|
|
2016-03-13 01:28:39 +00:00
|
|
|
modname = v.stem();
|
|
|
|
|
2016-03-12 18:26:14 +00:00
|
|
|
String exepath = testdir;
|
|
|
|
exepath += PathSeparator;
|
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
|
|
|
|
|
|
|
auto cxxcmd = appender<String>();
|
|
|
|
format(cxxcmd, "%s %s%s%s -o %s %s", compiler, testdir, PathSeparator,
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-03-13 01:28:39 +00:00
|
|
|
writeln("\n", ColorBlue, ColorBold, "testing done:", ColorEnd);
|
|
|
|
writeln(ColorGreen, "SUCCESS: ", nsuccess, ColorEnd);
|
|
|
|
writeln(ColorRed, "FAILURE: ", nfailed, ColorEnd);
|
2016-03-12 18:26:14 +00:00
|
|
|
}
|