diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2019-10-25 18:37:26 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2019-10-25 18:37:26 -0300 |
commit | f6b8e76789e428ac264a393fbd60d77499b9abfd (patch) | |
tree | 00071db51e3ceb86e2fbce81c55ee136b5ae7ff8 /src/doctest.h | |
parent | 9d4e28d4265a6a293b18a68ec4d51a4b086b20fa (diff) |
Diffstat (limited to 'src/doctest.h')
-rw-r--r-- | src/doctest.h | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/doctest.h b/src/doctest.h new file mode 100644 index 0000000..7c5403b --- /dev/null +++ b/src/doctest.h @@ -0,0 +1,66 @@ +/** + * Doc/testing Utilities + * Help I can't document my documentation tool with my documentation tool. + * + * Basics: All to-be-documented functions must be defined with DOCF/DOCF_END. + * Additionally, one needs to put #ifdef DOCS/else/endif around their code and docs: + * + * DOCF(void, foo, void) { + * #ifdef DOCS + * docs go here + * #else + * code goes here + * #endif + * DOCF_END; + * } + * + * D("...") is used for doc lines, DT("...") for doctest lines. + * + * Internal (static) functions cannot currently be documented, but support for them is planned. + * + * You must also put your main within #ifndef DOCS/#endif, if you don't wish to document it: + * + * #ifndef DOCS + * int main(int argc, char *argv[]) { + * } + * #endif + * + * // or (preferred) + * + * DOCF(int, main, int argc, char *argv[]) { + * #ifdef DOCS + * docs go here + * #else + * code goes here + * #endif + * DOCF_END; + * } + */ + +#ifdef DOCTEST +#define DOCS +#endif + +#ifdef DOCS + +/* docs enabled */ +struct docs; + +extern void docs_for( struct docs *doc, char *sig, char *name, char *params ); +extern void docs_line( struct docs *doc, char *s ); +extern void docs_testline( struct docs *doc, int lineno, char *file, char *s); + +#define DOCF(sig, name, ...) extern void name##_mkdocs ( struct docs *doc ) { docs_for( doc , #sig , #name , #__VA_ARGS__ ); do +#define DOCF_END }while(0) +#define D(s) docs_line(doc, s) +/* enabled unconditionally as doctests are part of and embedded into docs */ +#define DT(s) docs_testline(doc, __LINE__, __FILE__, s) + +#else + +/* docs not enabled */ +#define DOCF(sig, name, ...) sig name ( __VA_ARGS__ ) +/* for the sake of semicolon */ +#define DOCF_END do{}while(0) + +#endif |