From 79b9a8120e07c533fe8689001558336898617db6 Mon Sep 17 00:00:00 2001 From: nick black Date: Wed, 2 Dec 2020 14:00:30 -0500 Subject: [PATCH] notcurses-tester: check validity of datadir on start #1168 --- tests/main.cpp | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/main.cpp b/tests/main.cpp index 2544c5a7b..84762f712 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -42,6 +43,25 @@ handle_opts(const char** argv){ } } +// check that the (provided or default) data directory exists, and has at +// least one of our necessary files. otherwise, print a warning + return error. +static int +check_data_dir(){ + auto p = find_data("changes.jpg"); + if(!p){ + std::cerr << "Coudln't find testing data! Supply directory with -p." << std::endl; + return -1; + } + struct stat s; + if(stat(p, &s)){ + std::cerr << "Couldn't open " << p << ". Supply directory with -p." << std::endl; + free(p); + return -1; + } + free(p); + return 0; +} + // reset the terminal in the event of early exit (notcurses_init() presumably // ran, but we don't have the notcurses struct to destroy, so just do it raw). static void @@ -108,6 +128,9 @@ auto main(int argc, const char **argv) -> int { context.setOption("no-breaks", true); // don't break in the debugger when assertions fail dt_removed args(argv); handle_opts(argv); + if(check_data_dir()){ + return EXIT_FAILURE; + } 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