Skip to content

Commit

Permalink
Merge pull request #94 from clar-test/ethomson/tempdirs
Browse files Browse the repository at this point in the history
Some temporary directory handling changes
  • Loading branch information
ethomson authored Jan 22, 2025
2 parents 1e421ff + a17a427 commit fac823c
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 62 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
generator: MSYS Makefiles
- os: windows-latest
generator: MinGW Makefiles
fail-fast: false

runs-on: ${{ matrix.platform.os }}

Expand Down
14 changes: 10 additions & 4 deletions clar.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,10 @@ static void clar_print_onabortv(const char *msg, va_list argp);
static void clar_print_onabort(const char *msg, ...);

/* From clar_sandbox.c */
static void clar_unsandbox(void);
static void clar_sandbox(void);
static void clar_tempdir_init(void);
static void clar_tempdir_shutdown(void);
static int clar_sandbox_create(const char *suite_name, const char *test_name);
static int clar_sandbox_cleanup(void);

/* From summary.h */
static struct clar_summary *clar_summary_init(const char *filename);
Expand Down Expand Up @@ -308,6 +310,8 @@ clar_run_test(

CL_TRACE(CL_TRACE__TEST__BEGIN);

clar_sandbox_create(suite->name, test->name);

_clar.last_report->start = time(NULL);
clar_time_now(&start);

Expand Down Expand Up @@ -337,6 +341,8 @@ clar_run_test(
if (cleanup->ptr != NULL)
cleanup->ptr();

clar_sandbox_cleanup();

CL_TRACE(CL_TRACE__TEST__END);

_clar.tests_ran++;
Expand Down Expand Up @@ -610,7 +616,7 @@ clar_test_init(int argc, char **argv)
if (_clar.write_summary)
_clar.summary = clar_summary_init(_clar.summary_filename);

clar_sandbox();
clar_tempdir_init();
}

int
Expand Down Expand Up @@ -642,7 +648,7 @@ clar_test_shutdown(void)
_clar.total_errors
);

clar_unsandbox();
clar_tempdir_shutdown();

if (_clar.write_summary && clar_summary_shutdown(_clar.summary) < 0)
clar_abort("Failed to write the summary file '%s: %s.\n",
Expand Down
10 changes: 10 additions & 0 deletions clar.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
#define __CLAR_TEST_H__

#include <stdlib.h>
#include <limits.h>

#if defined(_WIN32) && defined(CLAR_WIN32_LONGPATHS)
# define CLAR_MAX_PATH 4096
#elif defined(_WIN32)
# define CLAR_MAX_PATH MAX_PATH
#else
# define CLAR_MAX_PATH PATH_MAX
#endif

#ifndef CLAR_SELFTEST
# define CLAR_CURRENT_FILE __FILE__
Expand Down Expand Up @@ -40,6 +49,7 @@ void clar_test_shutdown(void);
int clar_test(int argc, char *argv[]);

const char *clar_sandbox_path(void);
const char *clar_tempdir_path(void);

void cl_set_cleanup(void (*cleanup)(void *), void *opaque);
void cl_fs_cleanup(void);
Expand Down
6 changes: 3 additions & 3 deletions clar/fixtures.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
static const char *
fixture_path(const char *base, const char *fixture_name)
{
static char _path[4096];
static char _path[CLAR_MAX_PATH];
size_t root_len;

root_len = strlen(base);
Expand All @@ -28,7 +28,7 @@ const char *cl_fixture(const char *fixture_name)

void cl_fixture_sandbox(const char *fixture_name)
{
fs_copy(cl_fixture(fixture_name), _clar_path);
fs_copy(cl_fixture(fixture_name), clar_sandbox_path());
}

const char *cl_fixture_basename(const char *fixture_name)
Expand All @@ -45,6 +45,6 @@ const char *cl_fixture_basename(const char *fixture_name)

void cl_fixture_cleanup(const char *fixture_name)
{
fs_rm(fixture_path(_clar_path, cl_fixture_basename(fixture_name)));
fs_rm(fixture_path(clar_sandbox_path(), cl_fixture_basename(fixture_name)));
}
#endif
12 changes: 3 additions & 9 deletions clar/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,6 @@

#ifdef _WIN32

#ifdef CLAR_WIN32_LONGPATHS
# define CLAR_MAX_PATH 4096
#else
# define CLAR_MAX_PATH MAX_PATH
#endif

#define RM_RETRY_COUNT 5
#define RM_RETRY_DELAY 10

Expand Down Expand Up @@ -296,7 +290,7 @@ void
cl_fs_cleanup(void)
{
#ifdef CLAR_FIXTURE_PATH
fs_rm(fixture_path(_clar_path, "*"));
fs_rm(fixture_path(clar_tempdir_path(), "*"));
#else
((void)fs_copy); /* unused */
#endif
Expand Down Expand Up @@ -518,7 +512,7 @@ fs_rm(const char *path)
void
cl_fs_cleanup(void)
{
clar_unsandbox();
clar_sandbox();
clar_tempdir_shutdown();
clar_tempdir_init();
}
#endif
Loading

0 comments on commit fac823c

Please sign in to comment.