tests: move t0009-prio-queue.sh to the new unit testing framework
t/t0009-prio-queue.sh along with t/helper/test-prio-queue.c unit tests Git's implementation of a priority queue. Migrate the test over to the new unit testing framework to simplify debugging and reduce test run-time. Refactor the required logic and add a new test case in addition to porting over the original ones in shell. Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
186b115d30
commit
808b77e5d4
@ -1,51 +0,0 @@
|
||||
#include "test-tool.h"
|
||||
#include "prio-queue.h"
|
||||
|
||||
static int intcmp(const void *va, const void *vb, void *data UNUSED)
|
||||
{
|
||||
const int *a = va, *b = vb;
|
||||
return *a - *b;
|
||||
}
|
||||
|
||||
static void show(int *v)
|
||||
{
|
||||
if (!v)
|
||||
printf("NULL\n");
|
||||
else
|
||||
printf("%d\n", *v);
|
||||
free(v);
|
||||
}
|
||||
|
||||
int cmd__prio_queue(int argc UNUSED, const char **argv)
|
||||
{
|
||||
struct prio_queue pq = { intcmp };
|
||||
|
||||
while (*++argv) {
|
||||
if (!strcmp(*argv, "get")) {
|
||||
void *peek = prio_queue_peek(&pq);
|
||||
void *get = prio_queue_get(&pq);
|
||||
if (peek != get)
|
||||
BUG("peek and get results do not match");
|
||||
show(get);
|
||||
} else if (!strcmp(*argv, "dump")) {
|
||||
void *peek;
|
||||
void *get;
|
||||
while ((peek = prio_queue_peek(&pq))) {
|
||||
get = prio_queue_get(&pq);
|
||||
if (peek != get)
|
||||
BUG("peek and get results do not match");
|
||||
show(get);
|
||||
}
|
||||
} else if (!strcmp(*argv, "stack")) {
|
||||
pq.compare = NULL;
|
||||
} else {
|
||||
int *v = xmalloc(sizeof(*v));
|
||||
*v = atoi(*argv);
|
||||
prio_queue_put(&pq, v);
|
||||
}
|
||||
}
|
||||
|
||||
clear_prio_queue(&pq);
|
||||
|
||||
return 0;
|
||||
}
|
@ -56,7 +56,6 @@ static struct test_cmd cmds[] = {
|
||||
{ "path-utils", cmd__path_utils },
|
||||
{ "pcre2-config", cmd__pcre2_config },
|
||||
{ "pkt-line", cmd__pkt_line },
|
||||
{ "prio-queue", cmd__prio_queue },
|
||||
{ "proc-receive", cmd__proc_receive },
|
||||
{ "progress", cmd__progress },
|
||||
{ "reach", cmd__reach },
|
||||
|
@ -49,7 +49,6 @@ int cmd__partial_clone(int argc, const char **argv);
|
||||
int cmd__path_utils(int argc, const char **argv);
|
||||
int cmd__pcre2_config(int argc, const char **argv);
|
||||
int cmd__pkt_line(int argc, const char **argv);
|
||||
int cmd__prio_queue(int argc, const char **argv);
|
||||
int cmd__proc_receive(int argc, const char **argv);
|
||||
int cmd__progress(int argc, const char **argv);
|
||||
int cmd__reach(int argc, const char **argv);
|
||||
|
Reference in New Issue
Block a user