Move tons of stuff into oldstuff/

This commit is contained in:
2020-06-04 09:54:59 -04:00
parent 49038bb8ef
commit aa1345b6ed
213 changed files with 0 additions and 12 deletions

View File

@@ -0,0 +1,38 @@
#undef DNDEBUG
#ifndef _minunit_h
#define _minunit_h
#include <stdio.h>
#include <dbg.h>
#include <stdlib.h>
#define mu_suite_start() char *message = NULL
#define mu_assert(test, message) if (!(test)) {\
log_err(message); return message;\
}\
assertions_made++;
#define mu_run_test(test) debug("\n-----%s", " " #test); \
message = test(); tests_run++; if (message) return message;
#define RUN_TESTS(name) int main(int argc, char *argv[]) {\
argc = argc; \
argv = argv; \
debug("----- RUNNING: %s", argv[0]);\
printf("----\nRUNNING: %s\n", argv[0]);\
char *result = name();\
if (result != 0) {\
printf("FAILED: %s\n", result);\
}\
else {\
printf("ALL TESTS PASSED\n");\
}\
printf("Tests run: %d\n", tests_run);\
printf("Assertions made: %d\n", assertions_made);\
exit(result != 0);\
}
int tests_run;
int assertions_made;
#endif

View File

@@ -0,0 +1,107 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <unistd.h>
#include <fnmatch.h>
#include <dbg.h>
int test_selector(const struct dirent *ep)
{
return fnmatch("*_tests", ep->d_name, 0) == 0;
}
int run_tests_file(char *filename)
{
if(access(filename, R_OK | X_OK) == 0) {
return system(filename);
}
return -1;
}
int main(int argc, char *argv[])
{
int entcount = 0;
int rc = 0;
int i = 0;
int ntests = 0;
char *testsdir = NULL;
char *valgrind = getenv("VALGRIND");
struct dirent **namelist = NULL;
struct dirent *ep = NULL;
if(argc > 1) {
testsdir = argv[1];
}
if(!testsdir) {
testsdir = getenv("TESTS");
}
if(!testsdir) {
testsdir = "./tests";
}
entcount = scandir((const char *)testsdir, &namelist, test_selector, alphasort);
check(entcount > -1, "Failed to scan tests dir");
for(i = 0; i < entcount; i++) {
ep = namelist[i];
check(ep, "Dirent is missing.");
char filename[256];
rc = sprintf(filename, "%s/%s", testsdir, ep->d_name);
check(rc > -1, "Failed to build filename.");
debug("Found filename '%s'", filename);
free(ep);
if(valgrind) {
char command[1024];
rc = sprintf(command, "%s %s", valgrind, filename);
check(rc > -1, "Failed to build command with valgrind.");
rc = run_tests_file(command);
} else {
rc = run_tests_file(filename);
}
if(rc > 0) {
debug("Skipping '%s'", filename);
continue;
}
ntests++;
if(rc == 0) {
printf("%s PASS\n", filename);
continue;
}
printf("ERROR in test %s", filename);
if(access("tests/tests.log", R_OK) == 0) {
printf(": here's tests/tests.log\n");
printf("------\n");
rc = system("tail tests/tests.log");
} else {
printf("\n");
}
goto error;
}
printf("------\n");
printf("Total of %d test file%s run.\n", ntests, ntests > 1 ? "s" : "");
if(namelist) {
free(namelist);
}
return 0;
error:
if(namelist) {
free(namelist);
}
return rc != 0 ? rc : 1;
}

View File

@@ -0,0 +1,8 @@
#include <stdio.h>
#include "your_library.h"
int main()
{
printf("WEASELS: %d\n", howmanyweasels());
return 0;
}