mirror of
				https://git.proxmox.com/git/libgit2
				synced 2025-11-03 23:45:05 +00:00 
			
		
		
		
	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.
		
	
			
		
			
				
	
	
		
			52 lines
		
	
	
		
			964 B
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			52 lines
		
	
	
		
			964 B
		
	
	
	
		
			C
		
	
	
	
	
	
static const char *
 | 
						|
fixture_path(const char *base, const char *fixture_name)
 | 
						|
{
 | 
						|
	static char _path[4096];
 | 
						|
	size_t root_len;
 | 
						|
 | 
						|
	root_len = strlen(base);
 | 
						|
	strncpy(_path, base, sizeof(_path));
 | 
						|
 | 
						|
	if (_path[root_len - 1] != '/')
 | 
						|
		_path[root_len++] = '/';
 | 
						|
 | 
						|
	if (fixture_name[0] == '/')
 | 
						|
		fixture_name++;
 | 
						|
 | 
						|
	strncpy(_path + root_len,
 | 
						|
		fixture_name,
 | 
						|
		sizeof(_path) - root_len);
 | 
						|
 | 
						|
	return _path;
 | 
						|
}
 | 
						|
 | 
						|
static const char *
 | 
						|
fixture_basename(const char *fixture_name)
 | 
						|
{
 | 
						|
	const char *p;
 | 
						|
 | 
						|
	for (p = fixture_name; *p; p++) {
 | 
						|
		if (p[0] == '/' && p[1] && p[1] != '/')
 | 
						|
			fixture_name = p+1;
 | 
						|
	}
 | 
						|
 | 
						|
	return fixture_name;
 | 
						|
}
 | 
						|
 | 
						|
#ifdef CLAR_FIXTURE_PATH
 | 
						|
const char *cl_fixture(const char *fixture_name)
 | 
						|
{
 | 
						|
	return fixture_path(CLAR_FIXTURE_PATH, fixture_name);
 | 
						|
}
 | 
						|
 | 
						|
void cl_fixture_sandbox(const char *fixture_name)
 | 
						|
{
 | 
						|
	fs_copy(cl_fixture(fixture_name), _clar_path);
 | 
						|
}
 | 
						|
 | 
						|
void cl_fixture_cleanup(const char *fixture_name)
 | 
						|
{
 | 
						|
	fs_rm(fixture_path(_clar_path, fixture_basename(fixture_name)));
 | 
						|
}
 | 
						|
#endif
 |