notcurses/tests/main.cpp

77 lines
2.0 KiB
C++
Raw Normal View History

#define DOCTEST_CONFIG_IMPLEMENT
2019-11-17 10:04:41 +00:00
#include <clocale>
2019-12-27 22:43:24 +00:00
#include <cstring>
#include <cstdlib>
2019-11-17 10:04:41 +00:00
#include <iostream>
2019-12-27 22:43:24 +00:00
#include <limits.h>
2019-11-17 10:04:41 +00:00
#include "main.h"
2019-12-28 01:01:46 +00:00
static char datadir[PATH_MAX + 1] = "/usr/share/notcurses"; // FIXME
2019-12-27 22:43:24 +00:00
char* find_data(const char* datum){
char* path = (char*)malloc(strlen(datadir) + 1 + strlen(datum) + 1);
strcpy(path, datadir);
strcat(path, "/");
strcat(path, datum);
return path;
}
static void
handle_opts(const char** argv){
bool inarg = false;
while(*argv){
if(inarg){
2019-12-28 01:01:46 +00:00
strncpy(datadir, *argv, sizeof(datadir) - 1);
2019-12-27 22:43:24 +00:00
inarg = false;
}else if(strcmp(*argv, "-p") == 0){
inarg = true;
}
++argv;
}
}
// from https://github.com/onqtam/doctest/blob/master/doc/markdown/commandline.md
class dt_removed {
std::vector<const char*> vec;
public:
dt_removed(const char** argv_in) {
for(; *argv_in; ++argv_in)
if(strncmp(*argv_in, "--dt-", strlen("--dt-")) != 0)
vec.push_back(*argv_in);
vec.push_back(NULL);
}
int argc() { return static_cast<int>(vec.size()) - 1; }
const char** argv() { return &vec[0]; } // Note: non-const char **:
};
int main(int argc, const char **argv){
2019-11-17 10:04:41 +00:00
if(!setlocale(LC_ALL, "")){
std::cerr << "Coudln't set locale based on user preferences!" << std::endl;
return EXIT_FAILURE;
}
doctest::Context context;
// defaults
context.setOption("order-by", "name"); // sort the test cases by their name
context.applyCommandLine(argc, argv);
// overrides
context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
2019-12-27 22:43:24 +00:00
dt_removed args(argv);
handle_opts(argv);
int res = context.run(); // run
if(context.shouldExit()){ // important - query flags (and --exit) rely on the user doing this
return res; // propagate the result of the tests
}
int client_stuff_return_code = 0;
// your program - if the testing framework is integrated in your production code
return res + client_stuff_return_code; // the result from doctest is propagated here as well
2019-11-17 10:04:41 +00:00
}