Use GIT_INLINE macro instead of keyword inline.
[libgit2.git] / tests / test_lib.c
blob06a1c29eb70dd0b5f43cb58052641dfc6e8dd2fa
1 /*
2 * This file is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License, version 2,
4 * as published by the Free Software Foundation.
6 * In addition to the permissions in the GNU General Public License,
7 * the authors give you unlimited permission to link the compiled
8 * version of this file into combinations with other programs,
9 * and to distribute those combinations without any restriction
10 * coming from the use of this file. (The General Public License
11 * restrictions do apply in other respects; for example, they cover
12 * modification of the file, and distribution when not linked into
13 * a combined executable.)
15 * This file is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; see the file COPYING. If not, write to
22 * the Free Software Foundation, 51 Franklin Street, Fifth Floor,
23 * Boston, MA 02110-1301, USA.
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <string.h>
30 #include "test_lib.h"
32 struct test_info
34 struct test_info *next;
35 const char *test_name;
36 const char *file_name;
37 int line_no;
40 static int first_test = 1;
41 static struct test_info *current_test;
43 static void show_test_result(const char *status)
45 fprintf(stderr, "* %-6s %5d: %s\n",
46 status,
47 current_test->line_no,
48 current_test->test_name);
51 void test_die(const char *fmt, ...)
53 va_list p;
55 if (current_test)
56 show_test_result("FAILED");
58 va_start(p, fmt);
59 vfprintf(stderr, fmt, p);
60 va_end(p);
61 fputc('\n', stderr);
62 fflush(stderr);
63 exit(128);
66 void test_begin(
67 const char *test_name,
68 const char *file_name,
69 int line_no)
71 struct test_info *i = malloc(sizeof(*i));
72 if (!i)
73 test_die("cannot malloc memory");
75 i->test_name = test_name;
76 i->file_name = file_name;
77 i->line_no = line_no;
78 current_test = i;
80 if (first_test) {
81 const char *name = strrchr(i->file_name, '/');
82 if (name)
83 name = name + 1;
84 else
85 name = i->file_name;
86 fprintf(stderr, "*** %s ***\n", name);
87 first_test = 0;
91 void test_end(void)
93 if (!current_test)
94 test_die("BEGIN_TEST() not used before END_TEST");
96 show_test_result("ok");
97 free(current_test);
98 current_test = NULL;