mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-24 07:03:45 +00:00
Change test_main to run a single test case out of the suite
By passing the name of the test function on the command line we execute exactly that one test, and then exit successfully if the test did not fail. This permits multiple functions in the same .c file, so they could be called from a shell script or debugged independently externally. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
parent
b923f2f97d
commit
b81dd80e8c
@ -29,11 +29,36 @@
|
|||||||
#define BEGIN_TEST(name) extern void testfunc__##name(void);
|
#define BEGIN_TEST(name) extern void testfunc__##name(void);
|
||||||
#include TEST_TOC
|
#include TEST_TOC
|
||||||
|
|
||||||
|
struct test_def {
|
||||||
|
const char *name;
|
||||||
|
void (*fun)(void);
|
||||||
|
};
|
||||||
|
struct test_def all_tests[] = {
|
||||||
|
# undef BEGIN_TEST
|
||||||
|
# define BEGIN_TEST(name) {#name, testfunc__##name},
|
||||||
|
# include TEST_TOC
|
||||||
|
{NULL, NULL}
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
#undef BEGIN_TEST
|
struct test_def *t;
|
||||||
#define BEGIN_TEST(name) testfunc__##name();
|
|
||||||
#include TEST_TOC
|
|
||||||
|
|
||||||
return 0;
|
if (argc == 1) {
|
||||||
|
for (t = all_tests; t->name; t++)
|
||||||
|
t->fun();
|
||||||
|
return 0;
|
||||||
|
} else if (argc == 2) {
|
||||||
|
for (t = all_tests; t->name; t++) {
|
||||||
|
if (!strcmp(t->name, argv[1])) {
|
||||||
|
t->fun();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fprintf(stderr, "error: No test '%s' in %s\n", argv[1], argv[0]);
|
||||||
|
return 1;
|
||||||
|
} else {
|
||||||
|
fprintf(stderr, "usage: %s [test_name]\n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user