geoip2_c 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ubuntu.yml +33 -0
- data/.github/workflows/windows.yml +52 -0
- data/README.md +3 -9
- data/docker-compose.yml +7 -0
- data/dockerfiles/Dockerfile-ruby2.7 +8 -0
- data/ext/geoip2/extconf.rb +11 -4
- data/ext/geoip2/geoip2.c +58 -15
- data/ext/geoip2/libmaxminddb/t/libtap/.gitignore +13 -0
- data/ext/geoip2/libmaxminddb/t/libtap/.travis.yml +13 -0
- data/ext/geoip2/libmaxminddb/t/libtap/COPYING +165 -0
- data/ext/geoip2/libmaxminddb/t/libtap/INSTALL +41 -0
- data/ext/geoip2/libmaxminddb/t/libtap/Makefile +72 -0
- data/ext/geoip2/libmaxminddb/t/libtap/Makefile.win +37 -0
- data/ext/geoip2/libmaxminddb/t/libtap/README.md +268 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.c +20 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmp_mem.expected +28 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.c +16 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/cmpok.expected +37 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diag.c +10 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diag.expected +2 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.c +14 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/diesok.expected +6 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/is.c +24 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/is.expected +58 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/like.c +10 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/like.expected +4 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/simple.c +31 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/simple.expected +32 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/skip.c +23 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/skip.expected +9 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.c +13 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/synopsis.expected +9 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/test.c +28 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/todo.c +17 -0
- data/ext/geoip2/libmaxminddb/t/libtap/t/todo.expected +11 -0
- data/ext/geoip2/libmaxminddb/t/libtap/tap.c +354 -0
- data/ext/geoip2/libmaxminddb/t/libtap/tap.h +115 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitattributes +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitconfig +2 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.gitignore +2 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.perltidyallrc +11 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/.tidyallrc +7 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/LICENSE +4 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/MaxMind-DB-spec.md +558 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/README.md +4 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/README.md +7 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/libmaxminddb/libmaxminddb-offset-integer-overflow.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/cyclic-data-structure.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-bytes-length.mmdb +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-data-record-offset.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-map-key-length.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/invalid-string-length.mmdb +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/metadata-is-an-uint128.mmdb +1 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/bad-data/maxminddb-golang/unexpected-bytes.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/perltidyrc +12 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Anonymous-IP-Test.json +32 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-City-Test.json +12616 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Connection-Type-Test.json +102 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Country-Test.json +10975 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-DensityIncome-Test.json +14 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Domain-Test.json +452 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Enterprise-Test.json +666 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-ISP-Test.json +12585 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoIP2-Precision-Enterprise-Test.json +1035 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/GeoLite2-ASN-Test.json +37 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/source-data/README +13 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Anonymous-IP-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Broken-Double-Format.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test-Invalid-Node-Count.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-City-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Connection-Type-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Country-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-DensityIncome-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Domain-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Enterprise-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-ISP-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoIP2-Precision-Enterprise-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/GeoLite2-ASN-Test.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-no-ipv4-search-tree.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-string-value-entries.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-pointers-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-broken-search-tree-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-decoder.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-28.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv4-32.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-28.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-ipv6-32.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-metadata-pointers.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-24.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-28.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-mixed-32.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/MaxMind-DB-test-nested.mmdb +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/README.md +26 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/maps-with-pointers.raw +0 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/test-data/write-test-data.pl +614 -0
- data/ext/geoip2/libmaxminddb/t/maxmind-db/tidyall.ini +5 -0
- data/geoip2_c.gemspec +2 -3
- data/lib/geoip2/database.rb +4 -0
- data/lib/geoip2/version.rb +1 -1
- metadata +108 -18
- data/.travis.yml +0 -30
- data/Appraisals +0 -7
- data/gemfiles/ruby_2.1.gemfile +0 -7
- data/gemfiles/ruby_2.2.gemfile +0 -7
@@ -0,0 +1,28 @@
|
|
1
|
+
#include "tap.h"
|
2
|
+
#include <stdio.h>
|
3
|
+
#include <dirent.h>
|
4
|
+
#include <stdlib.h>
|
5
|
+
#include <string.h>
|
6
|
+
|
7
|
+
int main () {
|
8
|
+
DIR *dp = opendir("t");
|
9
|
+
if (!dp) {
|
10
|
+
perror("opendir");
|
11
|
+
exit(1);
|
12
|
+
}
|
13
|
+
struct dirent *ep;
|
14
|
+
while ((ep = readdir(dp))) {
|
15
|
+
char *name = ep->d_name;
|
16
|
+
if (strchr(name, '.') || !strcmp(name, "test"))
|
17
|
+
continue;
|
18
|
+
char command[1024];
|
19
|
+
snprintf(command, 1024, "./t/%s >t/%s.got 2>&1", name, name);
|
20
|
+
system(command);
|
21
|
+
snprintf(command, 1024, "diff -up t/%s.expected t/%s.got", name, name);
|
22
|
+
int retval = system(command);
|
23
|
+
ok(!(retval >> 8), name);
|
24
|
+
}
|
25
|
+
closedir(dp);
|
26
|
+
done_testing();
|
27
|
+
}
|
28
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
1..6
|
2
|
+
not ok 1 - foo # TODO
|
3
|
+
# Failed (TODO) test 'foo'
|
4
|
+
# at t/todo.c line 6.
|
5
|
+
ok 2 - bar # TODO
|
6
|
+
ok 3 - baz # TODO
|
7
|
+
not ok 4 - quux # TODO im not ready
|
8
|
+
# Failed (TODO) test 'quux'
|
9
|
+
# at t/todo.c line 11.
|
10
|
+
ok 5 - thud # TODO im not ready
|
11
|
+
ok 6 - wombat # TODO im not ready
|
@@ -0,0 +1,354 @@
|
|
1
|
+
/*
|
2
|
+
libtap - Write tests in C
|
3
|
+
Copyright 2012 Jake Gelbman <gelbman@gmail.com>
|
4
|
+
This file is licensed under the LGPL
|
5
|
+
*/
|
6
|
+
|
7
|
+
#define _DEFAULT_SOURCE 1
|
8
|
+
|
9
|
+
#include <stdio.h>
|
10
|
+
#include <stdlib.h>
|
11
|
+
#include <stdarg.h>
|
12
|
+
#include <string.h>
|
13
|
+
#include "tap.h"
|
14
|
+
|
15
|
+
static int expected_tests = NO_PLAN;
|
16
|
+
static int failed_tests;
|
17
|
+
static int current_test;
|
18
|
+
static char *todo_mesg;
|
19
|
+
|
20
|
+
static char *
|
21
|
+
vstrdupf (const char *fmt, va_list args) {
|
22
|
+
char *str;
|
23
|
+
int size;
|
24
|
+
va_list args2;
|
25
|
+
va_copy(args2, args);
|
26
|
+
if (!fmt)
|
27
|
+
fmt = "";
|
28
|
+
size = vsnprintf(NULL, 0, fmt, args2) + 2;
|
29
|
+
str = malloc(size);
|
30
|
+
if (!str) {
|
31
|
+
perror("malloc error");
|
32
|
+
exit(1);
|
33
|
+
}
|
34
|
+
vsprintf(str, fmt, args);
|
35
|
+
va_end(args2);
|
36
|
+
return str;
|
37
|
+
}
|
38
|
+
|
39
|
+
void
|
40
|
+
tap_plan (int tests, const char *fmt, ...) {
|
41
|
+
expected_tests = tests;
|
42
|
+
if (tests == SKIP_ALL) {
|
43
|
+
char *why;
|
44
|
+
va_list args;
|
45
|
+
va_start(args, fmt);
|
46
|
+
why = vstrdupf(fmt, args);
|
47
|
+
va_end(args);
|
48
|
+
printf("1..0 ");
|
49
|
+
diag("SKIP %s\n", why);
|
50
|
+
exit(0);
|
51
|
+
}
|
52
|
+
if (tests != NO_PLAN) {
|
53
|
+
printf("1..%d\n", tests);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
|
57
|
+
int
|
58
|
+
vok_at_loc (const char *file, int line, int test, const char *fmt,
|
59
|
+
va_list args)
|
60
|
+
{
|
61
|
+
char *name = vstrdupf(fmt, args);
|
62
|
+
if (!test) {
|
63
|
+
printf("not ");
|
64
|
+
}
|
65
|
+
printf("ok %d", ++current_test);
|
66
|
+
if (*name)
|
67
|
+
printf(" - %s", name);
|
68
|
+
if (todo_mesg) {
|
69
|
+
printf(" # TODO");
|
70
|
+
if (*todo_mesg)
|
71
|
+
printf(" %s", todo_mesg);
|
72
|
+
}
|
73
|
+
printf("\n");
|
74
|
+
if (!test) {
|
75
|
+
printf("# Failed ");
|
76
|
+
if (todo_mesg)
|
77
|
+
printf("(TODO) ");
|
78
|
+
printf("test ");
|
79
|
+
if (*name)
|
80
|
+
printf("'%s'\n# ", name);
|
81
|
+
printf("at %s line %d.\n", file, line);
|
82
|
+
if (!todo_mesg)
|
83
|
+
failed_tests++;
|
84
|
+
}
|
85
|
+
free(name);
|
86
|
+
return test;
|
87
|
+
}
|
88
|
+
|
89
|
+
int
|
90
|
+
ok_at_loc (const char *file, int line, int test, const char *fmt, ...) {
|
91
|
+
va_list args;
|
92
|
+
va_start(args, fmt);
|
93
|
+
vok_at_loc(file, line, test, fmt, args);
|
94
|
+
va_end(args);
|
95
|
+
return test;
|
96
|
+
}
|
97
|
+
|
98
|
+
static int
|
99
|
+
mystrcmp (const char *a, const char *b) {
|
100
|
+
return a == b ? 0 : !a ? -1 : !b ? 1 : strcmp(a, b);
|
101
|
+
}
|
102
|
+
|
103
|
+
#define eq(a, b) (!mystrcmp(a, b))
|
104
|
+
#define ne(a, b) (mystrcmp(a, b))
|
105
|
+
|
106
|
+
int
|
107
|
+
is_at_loc (const char *file, int line, const char *got, const char *expected,
|
108
|
+
const char *fmt, ...)
|
109
|
+
{
|
110
|
+
int test = eq(got, expected);
|
111
|
+
va_list args;
|
112
|
+
va_start(args, fmt);
|
113
|
+
vok_at_loc(file, line, test, fmt, args);
|
114
|
+
va_end(args);
|
115
|
+
if (!test) {
|
116
|
+
diag(" got: '%s'", got);
|
117
|
+
diag(" expected: '%s'", expected);
|
118
|
+
}
|
119
|
+
return test;
|
120
|
+
}
|
121
|
+
|
122
|
+
int
|
123
|
+
isnt_at_loc (const char *file, int line, const char *got, const char *expected,
|
124
|
+
const char *fmt, ...)
|
125
|
+
{
|
126
|
+
int test = ne(got, expected);
|
127
|
+
va_list args;
|
128
|
+
va_start(args, fmt);
|
129
|
+
vok_at_loc(file, line, test, fmt, args);
|
130
|
+
va_end(args);
|
131
|
+
if (!test) {
|
132
|
+
diag(" got: '%s'", got);
|
133
|
+
diag(" expected: anything else");
|
134
|
+
}
|
135
|
+
return test;
|
136
|
+
}
|
137
|
+
|
138
|
+
int
|
139
|
+
cmp_ok_at_loc (const char *file, int line, int a, const char *op, int b,
|
140
|
+
const char *fmt, ...)
|
141
|
+
{
|
142
|
+
int test = eq(op, "||") ? a || b
|
143
|
+
: eq(op, "&&") ? a && b
|
144
|
+
: eq(op, "|") ? a | b
|
145
|
+
: eq(op, "^") ? a ^ b
|
146
|
+
: eq(op, "&") ? a & b
|
147
|
+
: eq(op, "==") ? a == b
|
148
|
+
: eq(op, "!=") ? a != b
|
149
|
+
: eq(op, "<") ? a < b
|
150
|
+
: eq(op, ">") ? a > b
|
151
|
+
: eq(op, "<=") ? a <= b
|
152
|
+
: eq(op, ">=") ? a >= b
|
153
|
+
: eq(op, "<<") ? a << b
|
154
|
+
: eq(op, ">>") ? a >> b
|
155
|
+
: eq(op, "+") ? a + b
|
156
|
+
: eq(op, "-") ? a - b
|
157
|
+
: eq(op, "*") ? a * b
|
158
|
+
: eq(op, "/") ? a / b
|
159
|
+
: eq(op, "%") ? a % b
|
160
|
+
: diag("unrecognized operator '%s'", op);
|
161
|
+
va_list args;
|
162
|
+
va_start(args, fmt);
|
163
|
+
vok_at_loc(file, line, test, fmt, args);
|
164
|
+
va_end(args);
|
165
|
+
if (!test) {
|
166
|
+
diag(" %d", a);
|
167
|
+
diag(" %s", op);
|
168
|
+
diag(" %d", b);
|
169
|
+
}
|
170
|
+
return test;
|
171
|
+
}
|
172
|
+
|
173
|
+
static int
|
174
|
+
find_mem_diff (const char *a, const char *b, size_t n, size_t *offset) {
|
175
|
+
size_t i;
|
176
|
+
if (a == b)
|
177
|
+
return 0;
|
178
|
+
if (!a || !b)
|
179
|
+
return 2;
|
180
|
+
for (i = 0; i < n; i++) {
|
181
|
+
if (a[i] != b[i]) {
|
182
|
+
*offset = i;
|
183
|
+
return 1;
|
184
|
+
}
|
185
|
+
}
|
186
|
+
return 0;
|
187
|
+
}
|
188
|
+
|
189
|
+
int
|
190
|
+
cmp_mem_at_loc (const char *file, int line, const void *got,
|
191
|
+
const void *expected, size_t n, const char *fmt, ...)
|
192
|
+
{
|
193
|
+
size_t offset;
|
194
|
+
int diff = find_mem_diff(got, expected, n, &offset);
|
195
|
+
va_list args;
|
196
|
+
va_start(args, fmt);
|
197
|
+
vok_at_loc(file, line, !diff, fmt, args);
|
198
|
+
va_end(args);
|
199
|
+
if (diff == 1) {
|
200
|
+
diag(" Difference starts at offset %d", offset);
|
201
|
+
diag(" got: 0x%02x", ((unsigned char *)got)[offset]);
|
202
|
+
diag(" expected: 0x%02x", ((unsigned char *)expected)[offset]);
|
203
|
+
}
|
204
|
+
else if (diff == 2) {
|
205
|
+
diag(" got: %s", got ? "not NULL" : "NULL");
|
206
|
+
diag(" expected: %s", expected ? "not NULL" : "NULL");
|
207
|
+
}
|
208
|
+
return !diff;
|
209
|
+
}
|
210
|
+
|
211
|
+
int
|
212
|
+
diag (const char *fmt, ...) {
|
213
|
+
va_list args;
|
214
|
+
char *mesg, *line;
|
215
|
+
int i;
|
216
|
+
va_start(args, fmt);
|
217
|
+
if (!fmt)
|
218
|
+
return 0;
|
219
|
+
mesg = vstrdupf(fmt, args);
|
220
|
+
line = mesg;
|
221
|
+
for (i = 0; *line; i++) {
|
222
|
+
char c = mesg[i];
|
223
|
+
if (!c || c == '\n') {
|
224
|
+
mesg[i] = '\0';
|
225
|
+
printf("# %s\n", line);
|
226
|
+
if (!c)
|
227
|
+
break;
|
228
|
+
mesg[i] = c;
|
229
|
+
line = mesg + i + 1;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
free(mesg);
|
233
|
+
va_end(args);
|
234
|
+
return 0;
|
235
|
+
}
|
236
|
+
|
237
|
+
int
|
238
|
+
exit_status () {
|
239
|
+
int retval = 0;
|
240
|
+
if (expected_tests == NO_PLAN) {
|
241
|
+
printf("1..%d\n", current_test);
|
242
|
+
}
|
243
|
+
else if (current_test != expected_tests) {
|
244
|
+
diag("Looks like you planned %d test%s but ran %d.",
|
245
|
+
expected_tests, expected_tests > 1 ? "s" : "", current_test);
|
246
|
+
retval = 2;
|
247
|
+
}
|
248
|
+
if (failed_tests) {
|
249
|
+
diag("Looks like you failed %d test%s of %d run.",
|
250
|
+
failed_tests, failed_tests > 1 ? "s" : "", current_test);
|
251
|
+
retval = 1;
|
252
|
+
}
|
253
|
+
return retval;
|
254
|
+
}
|
255
|
+
|
256
|
+
int
|
257
|
+
bail_out (int ignore, const char *fmt, ...) {
|
258
|
+
va_list args;
|
259
|
+
va_start(args, fmt);
|
260
|
+
printf("Bail out! ");
|
261
|
+
vprintf(fmt, args);
|
262
|
+
printf("\n");
|
263
|
+
va_end(args);
|
264
|
+
exit(255);
|
265
|
+
return 0;
|
266
|
+
}
|
267
|
+
|
268
|
+
void
|
269
|
+
tap_skip (int n, const char *fmt, ...) {
|
270
|
+
char *why;
|
271
|
+
va_list args;
|
272
|
+
va_start(args, fmt);
|
273
|
+
why = vstrdupf(fmt, args);
|
274
|
+
va_end(args);
|
275
|
+
while (n --> 0) {
|
276
|
+
printf("ok %d ", ++current_test);
|
277
|
+
diag("skip %s\n", why);
|
278
|
+
}
|
279
|
+
free(why);
|
280
|
+
}
|
281
|
+
|
282
|
+
void
|
283
|
+
tap_todo (int ignore, const char *fmt, ...) {
|
284
|
+
va_list args;
|
285
|
+
va_start(args, fmt);
|
286
|
+
todo_mesg = vstrdupf(fmt, args);
|
287
|
+
va_end(args);
|
288
|
+
}
|
289
|
+
|
290
|
+
void
|
291
|
+
tap_end_todo () {
|
292
|
+
free(todo_mesg);
|
293
|
+
todo_mesg = NULL;
|
294
|
+
}
|
295
|
+
|
296
|
+
#ifndef _WIN32
|
297
|
+
#include <sys/mman.h>
|
298
|
+
#include <sys/param.h>
|
299
|
+
#include <regex.h>
|
300
|
+
|
301
|
+
#if defined __APPLE__ || defined BSD
|
302
|
+
#define MAP_ANONYMOUS MAP_ANON
|
303
|
+
#endif
|
304
|
+
|
305
|
+
/* Create a shared memory int to keep track of whether a piece of code executed
|
306
|
+
dies. to be used in the dies_ok and lives_ok macros. */
|
307
|
+
int
|
308
|
+
tap_test_died (int status) {
|
309
|
+
static int *test_died = NULL;
|
310
|
+
int prev;
|
311
|
+
if (!test_died) {
|
312
|
+
test_died = mmap(0, sizeof (int), PROT_READ | PROT_WRITE,
|
313
|
+
MAP_SHARED | MAP_ANONYMOUS, -1, 0);
|
314
|
+
*test_died = 0;
|
315
|
+
}
|
316
|
+
prev = *test_died;
|
317
|
+
*test_died = status;
|
318
|
+
return prev;
|
319
|
+
}
|
320
|
+
|
321
|
+
int
|
322
|
+
like_at_loc (int for_match, const char *file, int line, const char *got,
|
323
|
+
const char *expected, const char *fmt, ...)
|
324
|
+
{
|
325
|
+
int test;
|
326
|
+
regex_t re;
|
327
|
+
va_list args;
|
328
|
+
int err = regcomp(&re, expected, REG_EXTENDED);
|
329
|
+
if (err) {
|
330
|
+
char errbuf[256];
|
331
|
+
regerror(err, &re, errbuf, sizeof errbuf);
|
332
|
+
fprintf(stderr, "Unable to compile regex '%s': %s at %s line %d\n",
|
333
|
+
expected, errbuf, file, line);
|
334
|
+
exit(255);
|
335
|
+
}
|
336
|
+
err = regexec(&re, got, 0, NULL, 0);
|
337
|
+
regfree(&re);
|
338
|
+
test = for_match ? !err : err;
|
339
|
+
va_start(args, fmt);
|
340
|
+
vok_at_loc(file, line, test, fmt, args);
|
341
|
+
va_end(args);
|
342
|
+
if (!test) {
|
343
|
+
if (for_match) {
|
344
|
+
diag(" '%s'", got);
|
345
|
+
diag(" doesn't match: '%s'", expected);
|
346
|
+
}
|
347
|
+
else {
|
348
|
+
diag(" '%s'", got);
|
349
|
+
diag(" matches: '%s'", expected);
|
350
|
+
}
|
351
|
+
}
|
352
|
+
return test;
|
353
|
+
}
|
354
|
+
#endif
|
@@ -0,0 +1,115 @@
|
|
1
|
+
/*
|
2
|
+
libtap - Write tests in C
|
3
|
+
Copyright 2012 Jake Gelbman <gelbman@gmail.com>
|
4
|
+
This file is licensed under the LGPL
|
5
|
+
*/
|
6
|
+
|
7
|
+
#ifndef __TAP_H__
|
8
|
+
#define __TAP_H__
|
9
|
+
|
10
|
+
#ifdef __cplusplus
|
11
|
+
extern "C" {
|
12
|
+
#endif
|
13
|
+
|
14
|
+
#ifndef va_copy
|
15
|
+
#ifdef __va_copy
|
16
|
+
#define va_copy __va_copy
|
17
|
+
#else
|
18
|
+
#define va_copy(d, s) ((d) = (s))
|
19
|
+
#endif
|
20
|
+
#endif
|
21
|
+
|
22
|
+
#include <stdio.h>
|
23
|
+
#include <stdlib.h>
|
24
|
+
#include <stdarg.h>
|
25
|
+
|
26
|
+
int vok_at_loc (const char *file, int line, int test, const char *fmt,
|
27
|
+
va_list args);
|
28
|
+
int ok_at_loc (const char *file, int line, int test, const char *fmt,
|
29
|
+
...);
|
30
|
+
int is_at_loc (const char *file, int line, const char *got,
|
31
|
+
const char *expected, const char *fmt, ...);
|
32
|
+
int isnt_at_loc (const char *file, int line, const char *got,
|
33
|
+
const char *expected, const char *fmt, ...);
|
34
|
+
int cmp_ok_at_loc (const char *file, int line, int a, const char *op,
|
35
|
+
int b, const char *fmt, ...);
|
36
|
+
int cmp_mem_at_loc (const char *file, int line, const void *got,
|
37
|
+
const void *expected, size_t n, const char *fmt, ...);
|
38
|
+
int bail_out (int ignore, const char *fmt, ...);
|
39
|
+
void tap_plan (int tests, const char *fmt, ...);
|
40
|
+
int diag (const char *fmt, ...);
|
41
|
+
int exit_status (void);
|
42
|
+
void tap_skip (int n, const char *fmt, ...);
|
43
|
+
void tap_todo (int ignore, const char *fmt, ...);
|
44
|
+
void tap_end_todo (void);
|
45
|
+
|
46
|
+
#define NO_PLAN -1
|
47
|
+
#define SKIP_ALL -2
|
48
|
+
#define ok(...) ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
|
49
|
+
#define is(...) is_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
|
50
|
+
#define isnt(...) isnt_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
|
51
|
+
#define cmp_ok(...) cmp_ok_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
|
52
|
+
#define cmp_mem(...) cmp_mem_at_loc(__FILE__, __LINE__, __VA_ARGS__, NULL)
|
53
|
+
#define plan(...) tap_plan(__VA_ARGS__, NULL)
|
54
|
+
#define done_testing() return exit_status()
|
55
|
+
#define BAIL_OUT(...) bail_out(0, "" __VA_ARGS__, NULL)
|
56
|
+
#define pass(...) ok(1, "" __VA_ARGS__)
|
57
|
+
#define fail(...) ok(0, "" __VA_ARGS__)
|
58
|
+
|
59
|
+
#define skip(test, ...) do {if (test) {tap_skip(__VA_ARGS__, NULL); break;}
|
60
|
+
#define end_skip } while (0)
|
61
|
+
|
62
|
+
#define todo(...) tap_todo(0, "" __VA_ARGS__, NULL)
|
63
|
+
#define end_todo tap_end_todo()
|
64
|
+
|
65
|
+
#define dies_ok(...) dies_ok_common(1, __VA_ARGS__)
|
66
|
+
#define lives_ok(...) dies_ok_common(0, __VA_ARGS__)
|
67
|
+
|
68
|
+
#ifdef _WIN32
|
69
|
+
#define like(...) tap_skip(1, "like is not implemented on Windows")
|
70
|
+
#define unlike tap_skip(1, "unlike is not implemented on Windows")
|
71
|
+
#define dies_ok_common(...) \
|
72
|
+
tap_skip(1, "Death detection is not supported on Windows")
|
73
|
+
#else
|
74
|
+
#define like(...) like_at_loc(1, __FILE__, __LINE__, __VA_ARGS__, NULL)
|
75
|
+
#define unlike(...) like_at_loc(0, __FILE__, __LINE__, __VA_ARGS__, NULL)
|
76
|
+
int like_at_loc (int for_match, const char *file, int line,
|
77
|
+
const char *got, const char *expected,
|
78
|
+
const char *fmt, ...);
|
79
|
+
#include <unistd.h>
|
80
|
+
#include <sys/types.h>
|
81
|
+
#include <sys/wait.h>
|
82
|
+
int tap_test_died (int status);
|
83
|
+
#define dies_ok_common(for_death, code, ...) \
|
84
|
+
do { \
|
85
|
+
int cpid; \
|
86
|
+
int it_died; \
|
87
|
+
tap_test_died(1); \
|
88
|
+
cpid = fork(); \
|
89
|
+
switch (cpid) { \
|
90
|
+
case -1: \
|
91
|
+
perror("fork error"); \
|
92
|
+
exit(1); \
|
93
|
+
case 0: \
|
94
|
+
close(1); \
|
95
|
+
close(2); \
|
96
|
+
code \
|
97
|
+
tap_test_died(0); \
|
98
|
+
exit(0); \
|
99
|
+
} \
|
100
|
+
if (waitpid(cpid, NULL, 0) < 0) { \
|
101
|
+
perror("waitpid error"); \
|
102
|
+
exit(1); \
|
103
|
+
} \
|
104
|
+
it_died = tap_test_died(0); \
|
105
|
+
if (!it_died) \
|
106
|
+
{code} \
|
107
|
+
ok(for_death ? it_died : !it_died, "" __VA_ARGS__); \
|
108
|
+
} while (0)
|
109
|
+
#endif
|
110
|
+
|
111
|
+
#ifdef __cplusplus
|
112
|
+
}
|
113
|
+
#endif
|
114
|
+
|
115
|
+
#endif
|
@@ -0,0 +1 @@
|
|
1
|
+
*.mmdb diff=mmdb
|
@@ -0,0 +1,4 @@
|
|
1
|
+
This work is licensed under the Creative Commons Attribution-ShareAlike 3.0
|
2
|
+
Unported License. To view a copy of this license, visit
|
3
|
+
http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative
|
4
|
+
Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
|