test/run-test.c: Support negative assertions
Sometimes, we might want to make negative assertions (tests where expected and actual output are expected/known to be different). A test can be marked negative by prefixing it with an exclamation mark ('!'): $ ./run-test !test-negative Running test-negative... ok Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
e66e2d4277
commit
9cba56ac0a
@ -151,7 +151,7 @@ usage (void)
|
|||||||
|
|
||||||
/* Run test with a specific name. */
|
/* Run test with a specific name. */
|
||||||
static int
|
static int
|
||||||
run_test (const char *name)
|
run_test (const char *name, int expect_failure)
|
||||||
{
|
{
|
||||||
char filename[BUFSIZ];
|
char filename[BUFSIZ];
|
||||||
char *arg1[3], *arg2[3];
|
char *arg1[3], *arg2[3];
|
||||||
@ -210,6 +210,9 @@ run_test (const char *name)
|
|||||||
if (child_wait (&pin2, NULL, pid2) != 0)
|
if (child_wait (&pin2, NULL, pid2) != 0)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
|
|
||||||
|
if (expect_failure)
|
||||||
|
ret = 1 - ret;
|
||||||
|
|
||||||
if (ret == 1)
|
if (ret == 1)
|
||||||
printf (" ok\n");
|
printf (" ok\n");
|
||||||
else
|
else
|
||||||
@ -233,8 +236,16 @@ main (int argc, char **argv)
|
|||||||
|
|
||||||
for (i = 1; i < argc; i++)
|
for (i = 1; i < argc; i++)
|
||||||
{
|
{
|
||||||
if (!run_test (argv[i]))
|
if (*argv[i] == '!')
|
||||||
return 1;
|
{
|
||||||
|
if (!run_test (argv[i] + 1, 1))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!run_test (argv[i], 0))
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user