diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2010-07-25 11:02:57 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2010-08-01 17:20:03 +0200 |
commit | c1dcc3fc5336dc75a0097bb7db0a5123aff74d14 (patch) | |
tree | 36c90ae06bf5cf6a25e3e65335c8f4984b1ca768 /test | |
parent | 15edf50279c44bc2df28158a6a61f4f029101bc2 (diff) | |
download | ccache-c1dcc3fc5336dc75a0097bb7db0a5123aff74d14.tar.gz |
testfw: Add some utility functions
Diffstat (limited to 'test')
-rw-r--r-- | test/framework.c | 13 | ||||
-rw-r--r-- | test/framework.h | 1 | ||||
-rw-r--r-- | test/main.c | 2 | ||||
-rw-r--r-- | test/test_argument_processing.c | 5 | ||||
-rw-r--r-- | test/test_util.c | 2 | ||||
-rw-r--r-- | test/util.c | 50 | ||||
-rw-r--r-- | test/util.h | 8 |
7 files changed, 64 insertions, 17 deletions
diff --git a/test/framework.c b/test/framework.c index 88c9ba48..a5328afb 100644 --- a/test/framework.c +++ b/test/framework.c @@ -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); - } -} diff --git a/test/framework.h b/test/framework.h index 9e8357b2..56857055 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 ff2ad931..1d39bfca 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 <stdlib.h> #include <stdio.h> diff --git a/test/test_argument_processing.c b/test/test_argument_processing.c index bd5cefd2..a5efe13f 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 020b6dfc..b8d24bee 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 00000000..1cef0359 --- /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 <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 index 00000000..d4afb115 --- /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 |