Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some temporary directory handling changes #94

Merged
merged 4 commits into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -199,8 +199,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 @@ -304,6 +306,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 @@ -331,6 +335,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 @@ -604,7 +610,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 @@ -636,7 +642,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
Loading