From: Joel Rosdahl Date: Sun, 25 Jul 2010 09:02:57 +0000 (+0200) Subject: testfw: Add some utility functions X-Git-Tag: v3.1~133 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c1dcc3fc5336dc75a0097bb7db0a5123aff74d14;p=thirdparty%2Fccache.git testfw: Add some utility functions --- diff --git a/Makefile.in b/Makefile.in index b31f0275a..5452b6d9d 100644 --- a/Makefile.in +++ b/Makefile.in @@ -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) diff --git a/test/framework.c b/test/framework.c index 88c9ba48c..a5328afb2 100644 --- a/test/framework.c +++ b/test/framework.c @@ -17,7 +17,7 @@ */ #include "ccache.h" -#include "framework.h" +#include "test/framework.h" #include #include #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); - } -} diff --git a/test/framework.h b/test/framework.h index 9e8357b2c..568570554 100644 --- a/test/framework.h +++ b/test/framework.h @@ -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 diff --git a/test/main.c b/test/main.c index ff2ad9315..1d39bfcae 100644 --- a/test/main.c +++ b/test/main.c @@ -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 #include diff --git a/test/test_argument_processing.c b/test/test_argument_processing.c index bd5cefd2e..a5efe13f5 100644 --- a/test/test_argument_processing.c +++ b/test/test_argument_processing.c @@ -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); diff --git a/test/test_util.c b/test/test_util.c index 020b6dfc4..b8d24beeb 100644 --- a/test/test_util.c +++ b/test/test_util.c @@ -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 index 000000000..1cef0359a --- /dev/null +++ b/test/util.c @@ -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 +#include +#include +#include +#include +#include + +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 index 000000000..d4afb115a --- /dev/null +++ b/test/util.h @@ -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