Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Created June 26, 2022 03:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save louisswarren/a9847e3815cb7d2c5ef8ae77bc1c99c4 to your computer and use it in GitHub Desktop.
Save louisswarren/a9847e3815cb7d2c5ef8ae77bc1c99c4 to your computer and use it in GitHub Desktop.
Simple testing in C
int
check(const char *s, int p)
{
static int passes = 0;
static int failures = 0;
const char *fail = "\x1B[31mFAIL\x1B[0m";
const char *pass = "\x1B[34mPASS\x1B[0m";
if (s) {
fprintf(stderr, "[%s] %s\n", p ? pass : fail, s);
passes += p;
failures += !p;
return 0;
}
fprintf(stderr, "#%s: %d of %d\n", pass, passes, passes + failures);
if (failures == 0)
return 0;
fprintf(stderr, "#%s: %d of %d\n", fail, failures, passes + failures);
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment