Permalink
Browse files

Add support for Fixtures

  • Loading branch information...
vmg committed Sep 15, 2011
1 parent 385e6f6 commit 81ec1e8e19179137cbd2313b1c25feb56fba4dd4
Showing with 129 additions and 19 deletions.
  1. +9 −0 clay.c
  2. +6 −0 clay.h
  3. +7 −4 clay.py
  4. +42 −0 clay_fixtures.c
  5. +64 −0 clay_fs.c
  6. +1 −15 clay_sandbox.c
View
9 clay.c
@@ -11,6 +11,9 @@
#include "clay.h"
+static void fs_rm(const char *_source);
+static void fs_copy(const char *_source, const char *dest);
+
struct clay_error {
const char *test;
int test_number;
@@ -37,6 +40,7 @@ static struct {
void (*local_cleanup)(void *);
void *local_cleanup_payload;
+ int fixtures_sandboxed;
jmp_buf trampoline;
int trampoline_enabled;
@@ -85,6 +89,11 @@ clay_run_test(
if (cleanup->ptr != NULL)
cleanup->ptr();
+#ifdef CLAY_FIXTURE_PATH
+ if (_clay.fixtures_sandboxed)
+ cl_fixture_cleanup();
+#endif
+
_clay.test_count++;
/* remove any local-set cleanup methods */
View
6 clay.h
@@ -13,6 +13,12 @@ void clay__assert(
void cl_set_cleanup(void (*cleanup)(void *), void *opaque);
+#ifdef CLAY_FIXTURE_PATH
+const char *cl_fixture(const char *fixture_name);
+const char *cl_fixture_s(const char *fixture_name);
+void cl_fixture_cleanup(void);
+#endif
+
/**
* Assertion macros with explicit error message
*/
View
11 clay.py
@@ -91,7 +91,7 @@ def __init__(self, folder_name, output_folder = None, clay_path = None, print_mo
self.output = os.path.join(output_folder, "clay_main.c")
self.output_header = os.path.join(output_folder, "clay.h")
- self.modules = ["clay.c", "clay_sandbox.c"]
+ self.modules = ["clay.c", "clay_sandbox.c", "clay_fixtures.c", "clay_fs.c"]
print("Loading test suites...")
@@ -217,10 +217,13 @@ def _process_test_file(self, test_name, contents):
print(" %s (%d tests)" % (clean_name, len(callbacks)))
CLAY_FILES = {
-"clay.c" : r"""eJy9WEtv2zgQPsu/gnWRWHIUN9mj3WRvPRW7wHYLFEgCg5bomFuZckUqT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MNQqJiqTKkk17t+XpCQ/ZKlqe/BJ1JKzM7s7ZMgzkWIGhNyvZt/Iev5lTR4ICUIb5ALP4kHIBcvLFOFWmzTnL9ebuyD4KXkKLKe/CKFaozLj4IoLA0yKlBsuRRJc2bW2kQ1VEGc8x6Q6kluW1i4qJVUrlqJmihd1LgfUG1nmKaEvUpnow14D0WgIy5GKshj72Diuf6PqP44SqBayoD9KdOCQZ64LvtbF8uv66fOcfJqtH4JjDTZ5xnemVDg+LcbHiKBbl6sbQfSfMI32Jnys326HaNuYBcEkjgOIYeZbbDsBW8qU1PDGzQZwV+SccQO+fbBFrekr2vOT/TAtw7bUhhR2SGRsASoB19jodHZ+J4K7jzBNrAEWy9WcELdaLR/9arQoBfMCGM1zyKgdZ3oDIwgPORN4H50Ru5PDxLe9vPNdgcxgCtmJACO9hgEFFckw/bv+ui2/sn11xFyDkAaMKrGLt5nV/QbZ9/+YE3O4Cw1qGp0zX3hSXRIuMKhpNHCphPzL61RLOr1hVTCBx6fVqvsytGBV13thdfl7TOPoU0C/9YaqOZjuwHFsxF5hB8+0gQMV+UNtTLuepqCFVMw5yqa0j+TkjSrBxWu7CK+iwzR9VlmjfZWrm3E96n45aqZ/yfpcQSAtlfsYR4I7ZKWz2M3o2ID16/4bphd7Mw=="""
}
+
if __name__ == '__main__':
main()
View
@@ -0,0 +1,42 @@
+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;
+}
+
+#ifdef CLAY_FIXTURE_PATH
+const char *cl_fixture(const char *fixture_name)
+{
+ return fixture_path(CLAY_FIXTURE_PATH, fixture_name);
+}
+
+const char *cl_fixture_s(const char *fixture_name)
+{
+ fs_copy(cl_fixture(fixture_name), _clay_path);
+ _clay.fixtures_sandboxed = 1;
+
+ return fixture_path(_clay_path, fixture_name);
+}
+
+void cl_fixture_cleanup(void)
+{
+ fs_rm(fixture_path(_clay_path, "*"));
+ _clay.fixtures_sandboxed = 0;
+}
+#endif
View
@@ -0,0 +1,64 @@
+static int
+shell_out(char * const argv[])
+{
+ int status;
+ pid_t pid;
+
+ pid = fork();
+
+ if (pid < 0) {
+ fprintf(stderr,
+ "System error: `fork()` call failed.\n");
+ exit(-1);
+ }
+
+ if (pid == 0) {
+ execv(argv[0], argv);
+ }
+
+ waitpid(pid, &status, 0);
+ return WEXITSTATUS(status);
+}
+
+static void
+fs_copy(const char *_source, const char *dest)
+{
+ char *argv[5];
+ char *source;
+ size_t source_len;
+
+ source = strdup(_source);
+ source_len = strlen(source);
+
+ if (source[source_len - 1] == '/')
+ source[source_len - 1] = 0;
+
+ argv[0] = "/bin/cp";
+ argv[1] = "-R";
+ argv[2] = source;
+ argv[3] = (char *)dest;
+ argv[4] = NULL;
+
+ cl_must_pass_(
+ shell_out(argv),
+ "Failed to copy test fixtures to sandbox"
+ );
+
+ free(source);
+}
+
+static void
+fs_rm(const char *source)
+{
+ char *argv[3];
+
+ argv[0] = "/bin/rm";
+ argv[1] = "-rf";
+ argv[2] = (char *)source;
+ argv[3] = NULL;
+
+ cl_must_pass_(
+ shell_out(argv),
+ "Failed to cleanup the sandbox"
+ );
+}
View
@@ -57,26 +57,12 @@ find_tmp_path(char *buffer, size_t length)
return 0;
}
-static int clean_folder(const char *path)
-{
- const char os_cmd[] =
-#ifdef _WIN32
- "rd /s /q \"%s\"";
-#else
- "rm -rf \"%s\"";
-#endif
-
- char command[4096];
- snprintf(command, sizeof(command), os_cmd, path);
- return system(command);
-}
-
static void clay_unsandbox(void)
{
if (_clay_path[0] == '\0')
return;
- clean_folder(_clay_path);
+ fs_rm(_clay_path);
}
static int clay_sandbox(void)

0 comments on commit 81ec1e8

Please sign in to comment.