]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
testfw: Add some utility functions
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 25 Jul 2010 09:02:57 +0000 (11:02 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 1 Aug 2010 15:20:03 +0000 (17:20 +0200)
Makefile.in
test/framework.c
test/framework.h
test/main.c
test/test_argument_processing.c
test/test_util.c
test/util.c [new file with mode: 0644]
test/util.h [new file with mode: 0644]

index b31f0275a3c095a082035db11c6a913e9b17df5e..5452b6d9dd39d319e41485813d0da939c2a663db 100644 (file)
@@ -33,7 +33,7 @@ zlib_sources = \
 zlib_objs = $(zlib_sources:.c=.o)
 
 test_suites = @test_suites@
-test_sources = test/main.c test/framework.c $(test_suites)
+test_sources = test/main.c test/framework.c test/util.c $(test_suites)
 test_objs = $(test_sources:.c=.o)
 
 all_sources = $(ccache_sources) $(test_sources)
index 88c9ba48cb8fb99e39ae1f2efe1380cbf2ad3731..a5328afb2078412b4e997959d98abab9f5eda789 100644 (file)
@@ -17,7 +17,7 @@
  */
 
 #include "ccache.h"
-#include "framework.h"
+#include "test/framework.h"
 #include <errno.h>
 #include <stdio.h>
 #if defined(HAVE_TERMIOS_H)
@@ -307,14 +307,3 @@ void cct_create_fresh_dir(const char *path)
                abort();
        }
 }
-
-void cct_create_file(const char *path, const char *content)
-{
-       FILE *f = fopen(path, "w");
-       if (!f || fputs(content, f) < 0) {
-               fprintf(stderr, "cct_create_file: %s: %s", path, strerror(errno));
-       }
-       if (f) {
-               fclose(f);
-       }
-}
index 9e8357b2c06c822b61aada5fef127ce539536dc4..5685705544853a526eb6f75da729c824f20aa9f0 100644 (file)
@@ -143,6 +143,5 @@ int cct_check_args_eq(const char *file, int line, const char *expression,
 void cct_chdir(const char *path);
 void cct_wipe(const char *path);
 void cct_create_fresh_dir(const char *path);
-void cct_create_file(const char *path, const char *content);
 
 #endif
index ff2ad93159c5946ef3a10bdc5649c7dccfe438bd..1d39bfcae35660043b83f0b997973a8a45c20dde 100644 (file)
@@ -17,7 +17,7 @@
  * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include "framework.h"
+#include "test/framework.h"
 #include "getopt_long.h"
 #include <stdlib.h>
 #include <stdio.h>
index bd5cefd2e7082cbb0f6c29ae590b58f9c1d2ded9..a5efe13f5d3d18e87cac3b41d25cb0bc88c21aa3 100644 (file)
@@ -21,7 +21,8 @@
  */
 
 #include "ccache.h"
-#include "framework.h"
+#include "test/framework.h"
+#include "test/util.h"
 
 TEST_SUITE(argument_processing)
 
@@ -46,7 +47,7 @@ TEST(dependency_flags_should_only_be_sent_to_the_preprocessor)
 #undef CMD
        struct args *exp_cc = args_init_from_string("cc -c");
        struct args *act_cpp = NULL, *act_cc = NULL;
-       cct_create_file("foo.c", "");
+       create_file("foo.c", "");
 
        CHECK(cc_process_args(orig, &act_cpp, &act_cc));
        CHECK_ARGS_EQ_FREE12(exp_cpp, act_cpp);
index 020b6dfc4c676aa16735922530fe33ae1f37c54d..b8d24beebf56d081d0ace81e01c1ab4ee263f96e 100644 (file)
@@ -21,7 +21,7 @@
  */
 
 #include "ccache.h"
-#include "framework.h"
+#include "test/framework.h"
 
 TEST_SUITE(util)
 
diff --git a/test/util.c b/test/util.c
new file mode 100644 (file)
index 0000000..1cef035
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2010 Joel Rosdahl
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc., 51
+ * Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+int
+path_exists(const char *path)
+{
+       struct stat st;
+       return lstat(path, &st) == 0;
+}
+
+int
+is_symlink(const char *path)
+{
+       struct stat st;
+       return lstat(path, &st) == 0 && S_ISLNK(st.st_mode);
+}
+
+void
+create_file(const char *path, const char *content)
+{
+       FILE *f = fopen(path, "w");
+       if (!f || fputs(content, f) < 0) {
+               fprintf(stderr, "create_file: %s: %s\n", path, strerror(errno));
+       }
+       if (f) {
+               fclose(f);
+       }
+}
diff --git a/test/util.h b/test/util.h
new file mode 100644 (file)
index 0000000..d4afb11
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef TEST_UTIL_H
+#define TEST_UTIL_H
+
+int path_exists(const char *path);
+int is_symlink(const char *path);
+void create_file(const char *path, const char *content);
+
+#endif