mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 17:19:03 -04:00
unittests: support -p argument #218
This commit is contained in:
parent
ce2a390b52
commit
f024cee3a1
@ -236,7 +236,7 @@ target_compile_definitions(notcurses-tester
|
||||
enable_testing()
|
||||
add_test(
|
||||
NAME notcurses-tester
|
||||
COMMAND notcurses-tester
|
||||
COMMAND notcurses-tester -p ../data
|
||||
)
|
||||
|
||||
# pkg-config support
|
||||
|
@ -34,7 +34,7 @@ TEST_CASE("Multimedia") {
|
||||
int averr;
|
||||
int dimy, dimx;
|
||||
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
||||
auto ncv = ncplane_visual_open(ncp_, "../data/dsscaw-purp.png", &averr);
|
||||
auto ncv = ncplane_visual_open(ncp_, find_data("dsscaw-purp.png"), &averr);
|
||||
REQUIRE(ncv);
|
||||
REQUIRE(0 == averr);
|
||||
auto frame = ncvisual_decode(ncv, &averr);
|
||||
@ -55,7 +55,7 @@ TEST_CASE("Multimedia") {
|
||||
int averr;
|
||||
int dimy, dimx;
|
||||
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
||||
auto ncv = ncplane_visual_open(ncp_, "../data/fm6.mkv", &averr);
|
||||
auto ncv = ncplane_visual_open(ncp_, find_data("fm6.mkv"), &averr);
|
||||
REQUIRE(ncv);
|
||||
CHECK(0 == averr);
|
||||
auto frame = ncvisual_decode(ncv, &averr);
|
||||
@ -72,7 +72,7 @@ TEST_CASE("Multimedia") {
|
||||
int averr;
|
||||
int dimy, dimx;
|
||||
ncplane_dim_yx(ncp_, &dimy, &dimx);
|
||||
auto ncv = ncvisual_open_plane(nc_, "../data/fm6.mkv", &averr, 0, 0, NCSCALE_STRETCH);
|
||||
auto ncv = ncvisual_open_plane(nc_, find_data("fm6.mkv"), &averr, 0, 0, NCSCALE_STRETCH);
|
||||
REQUIRE(ncv);
|
||||
CHECK(0 == averr);
|
||||
auto frame = ncvisual_decode(ncv, &averr);
|
||||
|
@ -1,9 +1,51 @@
|
||||
#define DOCTEST_CONFIG_IMPLEMENT
|
||||
#include <clocale>
|
||||
#include <cstring>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
#include <limits.h>
|
||||
#include "main.h"
|
||||
|
||||
int main(int argc, char **argv){
|
||||
static char datadir[PATH_MAX] = "/usr/share/notcurses"; // FIXME
|
||||
|
||||
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){
|
||||
strncpy(datadir, *argv, sizeof(datadir));
|
||||
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){
|
||||
if(!setlocale(LC_ALL, "")){
|
||||
std::cerr << "Coudln't set locale based on user preferences!" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
@ -11,8 +53,6 @@ int main(int argc, char **argv){
|
||||
doctest::Context context;
|
||||
|
||||
// defaults
|
||||
context.addFilter("test-case-exclude", "*math*"); // exclude test cases with "math" in their name
|
||||
context.setOption("abort-after", 5); // stop test execution after 5 failed assertions
|
||||
context.setOption("order-by", "name"); // sort the test cases by their name
|
||||
|
||||
context.applyCommandLine(argc, argv);
|
||||
@ -20,6 +60,9 @@ int main(int argc, char **argv){
|
||||
// overrides
|
||||
context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
|
||||
|
||||
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
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "doctest.h"
|
||||
#include <notcurses.h>
|
||||
#include <curses.h>
|
||||
|
||||
char* find_data(const char* datum);
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user