Skip to content

Commit

Permalink
tmp
Browse files Browse the repository at this point in the history
  • Loading branch information
exbotanical committed Jan 23, 2025
1 parent 871b5f4 commit f3fdcc1
Show file tree
Hide file tree
Showing 31 changed files with 890 additions and 587 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ TESTDIR := t
SRC := $(shell find $(SRCDIR) -name "*.c")
TESTS := $(shell find $(TESTDIR) -name "*.c")
SRC_NOMAIN := $(filter-out $(SRCDIR)/main.c, $(SRC))
TEST_DEPS := $(wildcard $(DEPSDIR)/tap.c/*.c)
DEPS := $(filter-out $(wildcard $(DEPSDIR)/tap.c/*), $(wildcard $(DEPSDIR)/*/*.c))
TEST_DEPS := $(wildcard $(DEPSDIR)/libtap/*.c)
DEPS := $(filter-out $(wildcard $(DEPSDIR)/libtap/*), $(wildcard $(DEPSDIR)/*/*.c))
UNIT_TESTS := $(wildcard $(TESTDIR)/unit/*.c)

INCLUDES := -I$(DEPSDIR) -I$(INCDIR)
Expand Down
1 change: 1 addition & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
- [ ] Make all APIs consistent (e.g. return new string or always accept the dest as input)
- [ ] Document all behaviors and usage patterns; complete manpage
- [ ] Perf improvements
- [ ] Update Makefile template w/manpage and install updates


We make tradeoffs between runtime op/main loop work and startup work (loading the crontabs).
12 changes: 3 additions & 9 deletions clib.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,7 @@
"repo": "exbotanical/chronic",
"license": "MIT",
"description": "A cron daemon for modern UNIX systems",
"keywords": [
"cron",
"daemon",
"scheduler",
"job",
"task runner"
],
"keywords": ["cron", "daemon", "scheduler", "job", "task runner"],
"install": "echo TODO",
"uninstall": "echo TODO",
"dependencies": {
Expand All @@ -20,7 +14,7 @@
"clibs/commander": "1.3.2"
},
"development": {
"thlorenz/tap.c": "*",
"exbotanical/libtap": "*",
"entr": "5.4"
}
}
}
16 changes: 16 additions & 0 deletions deps/libtap/clib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "libtap",
"version": "0.0.9",
"author": "Matthew Zito",
"repo": "exbotanical/libtap",
"license": "MIT",
"description": "An implementation of TAP testing",
"keywords": ["test anything protocol", "testing", "unit test"],
"src": ["include/libtap.h", "src/tap.c"],
"development": {
"exbotanical/print-assert": "0.0.1"
},
"dependencies": {
"strdup": "0.1.5"
}
}
106 changes: 106 additions & 0 deletions deps/libtap/libtap.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#ifndef LIBTAP_H
#define LIBTAP_H

#include <stdarg.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/wait.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

// TODO: parser for gh actions, etc
unsigned int __tap_ok(unsigned int ok, const char* fn_name, const char* file, const unsigned int line, const char* fmt, ...);
void __tap_skip(unsigned int num_skips, const char* msg);
int __tap_write_shared_mem(int status);

#define __tap_lives_or_dies(wants_death, code, ...) \
do { \
/* set shared memory to 1 */ \
__tap_write_shared_mem(1); \
\
pid_t pid = fork(); \
switch (pid) { \
case -1: { \
perror("fork"); \
exit(EXIT_FAILURE); \
} \
case 0: { \
close(STDOUT_FILENO); \
close(STDERR_FILENO); \
/* execute test code, then set shared memory to zero */ \
code __tap_write_shared_mem(0); \
exit(EXIT_SUCCESS); \
} \
} \
\
if (waitpid(pid, NULL, 0) < 0) { \
perror("waitpid"); \
exit(EXIT_FAILURE); \
} \
/* grab prev value (and reset) - if 0, code succeeded */ \
int test_died = __tap_write_shared_mem(0); \
if (!test_died) { \
code \
} \
__tap_ok(wants_death ? test_died : !test_died, __func__, __FILE__, __LINE__, __VA_ARGS__); \
} while (0)

/* Begin public APIs */

void todo_start(const char* fmt, ...);
void todo_end(void);
void diag(const char* fmt, ...);
void plan(unsigned int num_tests);
unsigned int exit_status(void);
unsigned int bail_out(const char* fmt, ...);

#define done_testing() return exit_status()
// clang-format off
#define ok(test, ...) __tap_ok(test ? 1 : 0, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define eq_num(a, b, ...) __tap_ok(a == b ? 1 : 0, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define neq_num(a, b, ...) __tap_ok(a != b ? 1 : 0, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define eq_str(a, b, ...) __tap_ok(strcmp(a, b) == 0 ? 1 : 0, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define neq_str(a, b, ...) __tap_ok(strcmp(a, b) == 0 ? 0 : 1, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define eq_null(a, ...) __tap_ok(a == NULL, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define neq_null(a, ...) __tap_ok(a != NULL, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define lives(...) __tap_lives_or_dies(0, __VA_ARGS__)
#define dies(...) __tap_lives_or_dies(1, __VA_ARGS__)
#define pass(...) ok(1, __VA_ARGS__)
#define fail(...) ok(0, __VA_ARGS__)

#define skip_start(cond, num_skips, msg) do { if (cond) { __tap_skip(num_skips, msg); break; }
#define skip_end() } while (0)
#define skip(test, msg) __tap_skip(1, msg);

#ifdef TAP_WANT_PCRE

unsigned int
__tap_match (
const char* string,
const char* pattern,
bool want_match,
const char* fn_name,
const char* file,
const unsigned int line,
const char* fmt,
...
);

#define match_str(string, pattern, ...) __tap_match(string, pattern, true, __func__, __FILE__, __LINE__, __VA_ARGS__)
#define nomatch_str(string, pattern, ...) __tap_match(string, pattern, false, __func__, __FILE__, __LINE__, __VA_ARGS__)

#endif /* TAP_WANT_PCRE */

// clang-format on
#ifdef __cplusplus
}
#endif

#endif /* LIBTAP_H */
Loading

0 comments on commit f3fdcc1

Please sign in to comment.