Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 71686dd

Browse files
author
Edward Thomson
committed
clar: support hierarchical test resource data
Support hierarchical test resource data, such that you can have `tests/resources/foo/bar` and move the `bar` directory in as a fixture. Calling `cl_fixture_sandbox` on a path that is not directly beneath the test resources directory succeeds, placing that directory into the test fixture. (For example, `cl_fixture_sandbox("foo/bar")` will sandbox the `foo/bar` directory as `bar`). Add support for cleaning up directories created this way, by only cleaning up the basename (in this example, `bar`) from the fixture directory.
1 parent e774fa6 commit 71686dd

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

tests/clar/fixtures.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,19 @@ fixture_path(const char *base, const char *fixture_name)
2020
return _path;
2121
}
2222

23+
static const char *
24+
fixture_basename(const char *fixture_name)
25+
{
26+
const char *p;
27+
28+
for (p = fixture_name; *p; p++) {
29+
if (p[0] == '/' && p[1] && p[1] != '/')
30+
fixture_name = p+1;
31+
}
32+
33+
return fixture_name;
34+
}
35+
2336
#ifdef CLAR_FIXTURE_PATH
2437
const char *cl_fixture(const char *fixture_name)
2538
{
@@ -33,6 +46,6 @@ void cl_fixture_sandbox(const char *fixture_name)
3346

3447
void cl_fixture_cleanup(const char *fixture_name)
3548
{
36-
fs_rm(fixture_path(_clar_path, fixture_name));
49+
fs_rm(fixture_path(_clar_path, fixture_basename(fixture_name)));
3750
}
3851
#endif

0 commit comments

Comments
 (0)