I have been doing testing manually for my project, but I'd like to expand my knowledge a bit and implement "better" testing for my project(s).
The easiest scenario (where I should probably start to get my feet wet) is my `md2mdoc` program which takes a markdown file and writes `mdoc(1)`.
I have a few C macros (see below) which I use for unit testing's as in: "mu_assert(5 == 2, ...)" but this situation is a bit different where I could use a simple shell script to call my program and then just `diff(1)` the files--and my unit testing macros are not currently geared up to support.
My initial plan was to build several files for different testing (parsing) aspects like:
01_bold.md
01_bold.mdoc (which is a file that lists what my program should output)
Then I can just use a shell script to loop through the .md files and diff the .out and .mdoc files to locate problems.
pseudocode:
But my question is:
1. Should I attempt to do this in C?
1a. This would allow me to build a testing target in my makefile.
2. Does testing have to do anything like produce a "test output file" for input/digestion into other testing frameworks to be "proper"?
2a. Is test output automated in some way or used for a reason?
3. I know there are some built-in headers/libs for testing but I suspect these are not present in all systems.
3a. Should I research these frameworks (or are they mostly OS dependent and just implement an independent method)?
3b. I am assuming this is for issues related to #2a but I am guessing (I would be interested in learning more about this aspect if it is).
4. How would you test this -- is my method for a simple shell script "not professional" enough?
Thank you for any tips and suggestions.
REF: minimal unit testing macros
REF: project page
github.com
The easiest scenario (where I should probably start to get my feet wet) is my `md2mdoc` program which takes a markdown file and writes `mdoc(1)`.
I have a few C macros (see below) which I use for unit testing's as in: "mu_assert(5 == 2, ...)" but this situation is a bit different where I could use a simple shell script to call my program and then just `diff(1)` the files--and my unit testing macros are not currently geared up to support.
My initial plan was to build several files for different testing (parsing) aspects like:
01_bold.md
Code:
*bold text* other text
Code:
.Sy bold text
other text
Then I can just use a shell script to loop through the .md files and diff the .out and .mdoc files to locate problems.
pseudocode:
Code:
for (all *.md in ./test)
call md2mdoc *.md -o ...
call diff *.mdoc *.out
But my question is:
1. Should I attempt to do this in C?
1a. This would allow me to build a testing target in my makefile.
2. Does testing have to do anything like produce a "test output file" for input/digestion into other testing frameworks to be "proper"?
2a. Is test output automated in some way or used for a reason?
3. I know there are some built-in headers/libs for testing but I suspect these are not present in all systems.
3a. Should I research these frameworks (or are they mostly OS dependent and just implement an independent method)?
3b. I am assuming this is for issues related to #2a but I am guessing (I would be interested in learning more about this aspect if it is).
4. How would you test this -- is my method for a simple shell script "not professional" enough?
Thank you for any tips and suggestions.
REF: minimal unit testing macros
C:
#include <string.h>
#include <sys/time.h>
extern int tests_run;
#define mu_assert(X) if(!(X)){ errorlocation(__FILE__, __LINE__); } return "PASS";
#define errorlocation(zFile, iLine) \
do { \
char *message; \
asprintf(&message, "*ERROR* : %s [line: %d]", zFile, iLine); \
return message; \
} while (0)
#define mu_run_test(label, errmsg, test) \
do { \
char *message; \
char *ret = test(); \
++tests_run; \
asprintf(&message, "[%d] %s : %s", tests_run, ret, label); \
if(memcmp("*ERROR*", ret, 7) == 0) \
asprintf(&message, "[%d] %s : %s - \"%s\"", tests_run, ret, label, errmsg);\
printf("%s\n", message); \
free(message); \
} while (0)
REF: project page
GitHub - JohnKaul/md2mdoc: A program to convert simple markdown style documents to mdoc for manpages.
A program to convert simple markdown style documents to mdoc for manpages. - JohnKaul/md2mdoc