]> git.proxmox.com Git - libgit2.git/blob - tests/clar/fixtures.h
New upstream version 0.28.1+dfsg.1
[libgit2.git] / tests / clar / fixtures.h
1 static const char *
2 fixture_path(const char *base, const char *fixture_name)
3 {
4 static char _path[4096];
5 size_t root_len;
6
7 root_len = strlen(base);
8 strncpy(_path, base, sizeof(_path));
9
10 if (_path[root_len - 1] != '/')
11 _path[root_len++] = '/';
12
13 if (fixture_name[0] == '/')
14 fixture_name++;
15
16 strncpy(_path + root_len,
17 fixture_name,
18 sizeof(_path) - root_len);
19
20 return _path;
21 }
22
23 #ifdef CLAR_FIXTURE_PATH
24 const char *cl_fixture(const char *fixture_name)
25 {
26 return fixture_path(CLAR_FIXTURE_PATH, fixture_name);
27 }
28
29 void cl_fixture_sandbox(const char *fixture_name)
30 {
31 fs_copy(cl_fixture(fixture_name), _clar_path);
32 }
33
34 const char *cl_fixture_basename(const char *fixture_name)
35 {
36 const char *p;
37
38 for (p = fixture_name; *p; p++) {
39 if (p[0] == '/' && p[1] && p[1] != '/')
40 fixture_name = p+1;
41 }
42
43 return fixture_name;
44 }
45
46 void cl_fixture_cleanup(const char *fixture_name)
47 {
48 fs_rm(fixture_path(_clar_path, cl_fixture_basename(fixture_name)));
49 }
50 #endif