mirror of
https://github.com/dankamongmen/notcurses
synced 2025-03-09 09:09:03 -04:00
[tester] define loglevel so we can log in internal headers
This commit is contained in:
parent
59f01abf38
commit
f2cca37c59
@ -8,7 +8,7 @@ notcurses-tester - Notcurses unit testing
|
||||
|
||||
# SYNOPSIS
|
||||
|
||||
**notcurses-tester** [**-p datadir**] [**-l**]
|
||||
**notcurses-tester** [**-p datadir**] [**-lN**]
|
||||
|
||||
# DESCRIPTION
|
||||
|
||||
@ -20,7 +20,8 @@ if these are in an irregular location, supply **-p**.
|
||||
|
||||
**-p** ***path***: Look in the specified ***path*** for data files.
|
||||
|
||||
**-l**: Enable all possible diagnostics/logging.
|
||||
**-lN**: Enable diagnostics/logging at level ***N***. ***N*** must be
|
||||
between -1 and 7.
|
||||
|
||||
# NOTES
|
||||
|
||||
|
@ -5,10 +5,16 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void nclog(const char* fmt, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
// logging
|
||||
extern int loglevel;
|
||||
extern ncloglevel_e loglevel;
|
||||
|
||||
static inline void
|
||||
nclog(const char* fmt, ...){
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vfprintf(stderr, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
#define logpanic(fmt, ...) do{ \
|
||||
if(loglevel >= NCLOGLEVEL_PANIC){ \
|
||||
|
@ -3203,13 +3203,6 @@ void ncplane_center_abs(const ncplane* n, int* RESTRICT y, int* RESTRICT x){
|
||||
}
|
||||
}
|
||||
|
||||
void nclog(const char* fmt, ...){
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vfprintf(stderr, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
int ncplane_putwstr_stained(ncplane* n, const wchar_t* gclustarr){
|
||||
mbstate_t ps = {0};
|
||||
const wchar_t** wset = &gclustarr;
|
||||
|
@ -9,15 +9,16 @@
|
||||
#include <sys/stat.h>
|
||||
|
||||
const char* datadir = notcurses_data_dir();
|
||||
// NCLOGLEVEL_INFO for initial testing framework creation. we then switch to
|
||||
// command line-specified loglevel, _SILENT if none specified.
|
||||
ncloglevel_e cliloglevel = NCLOGLEVEL_INFO;
|
||||
|
||||
// we define loglevel for any use of logging in internal header files.
|
||||
// note that this has no bearing on the library's true inner loglevel!
|
||||
ncloglevel_e loglevel;
|
||||
|
||||
auto testing_notcurses() -> struct notcurses* {
|
||||
notcurses_options nopts{};
|
||||
// get loglevel from command line. enabling it by default leads to
|
||||
// more confusion than useful information, so leave it off by default.
|
||||
nopts.loglevel = cliloglevel;
|
||||
nopts.loglevel = loglevel;
|
||||
nopts.flags = NCOPTION_SUPPRESS_BANNERS
|
||||
| NCOPTION_NO_ALTERNATE_SCREEN
|
||||
| NCOPTION_DRAIN_INPUT;
|
||||
@ -48,7 +49,7 @@ static void
|
||||
handle_opts(const char** argv){
|
||||
// now that we've spun up one testing framework, switch to _SILENT unless
|
||||
// something else has been provided on the command line.
|
||||
cliloglevel = NCLOGLEVEL_SILENT;
|
||||
loglevel = NCLOGLEVEL_SILENT;
|
||||
bool inarg = false;
|
||||
while(*argv){
|
||||
if(inarg){
|
||||
@ -57,10 +58,34 @@ handle_opts(const char** argv){
|
||||
}else if(strcmp(*argv, "-p") == 0){
|
||||
inarg = true;
|
||||
}else if(strncmp(*argv, "-l", 2) == 0){ // just require -l
|
||||
cliloglevel = NCLOGLEVEL_TRACE;
|
||||
char* eol;
|
||||
long ll = strtol(*argv + 2, &eol, 0);
|
||||
if(ll < NCLOGLEVEL_SILENT || ll > NCLOGLEVEL_TRACE){
|
||||
std::cerr << "illegal loglevel: " << *argv + 2 << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if(*eol){
|
||||
std::cerr << "illegal loglevel: " << *argv + 2 << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
std::cout << "got loglevel " << ll << std::endl;
|
||||
loglevel = static_cast<ncloglevel_e>(ll);
|
||||
}
|
||||
++argv;
|
||||
}
|
||||
auto nc = testing_notcurses();
|
||||
if(!nc){
|
||||
std::cerr << "Couldn't create notcurses testing framework" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
unsigned dimy, dimx;
|
||||
notcurses_stddim_yx(nc, &dimy, &dimx);
|
||||
std::cout << "Detected cell geometry: " << dimx << 'x' << dimy << std::endl;
|
||||
notcurses_stop(nc);
|
||||
if(dimx < 50 || dimy < 24){ // minimum assumed geometry
|
||||
std::cerr << "Terminal was too small for tests (minimum 50x24)" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
// check that the (provided or default) data directory exists, and has at
|
||||
@ -143,19 +168,6 @@ auto lang_and_term() -> void {
|
||||
}
|
||||
std::cout << "Running with TERM=" << term << std::endl;
|
||||
#endif
|
||||
auto nc = testing_notcurses();
|
||||
if(!nc){
|
||||
std::cerr << "Couldn't create notcurses testing framework" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
unsigned dimy, dimx;
|
||||
notcurses_stddim_yx(nc, &dimy, &dimx);
|
||||
std::cout << "Detected cell geometry: " << dimx << 'x' << dimy << std::endl;
|
||||
notcurses_stop(nc);
|
||||
if(dimx < 50 || dimy < 24){ // minimum assumed geometry
|
||||
std::cerr << "Terminal was too small for tests (minimum 50x24)" << std::endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
auto main(int argc, const char **argv) -> int {
|
||||
|
Loading…
x
Reference in New Issue
Block a user