From b56fd9d3586a08a75a7d9caa81171dcfb67bdb4b Mon Sep 17 00:00:00 2001 From: Filipe Brandenburger Date: Fri, 1 May 2015 17:43:51 -0700 Subject: [PATCH] build-sys: split test cases in lib/ into their own files In order to avoid compiling the same source files twice, with and without the TEST_PROGRAM define. Tested that the build still works and that `make distcheck` works as expected. Tested that the test_* programs in lib/ keep working. (Though they are not really invoked by `make check` and in particular test_nsutils is quite useless, test_fileutils also quite poor.) Signed-off-by: Filipe Brandenburger --- lib/Makefile.am | 11 +++++------ lib/fileutils.c | 10 ---------- lib/nsutils.c | 15 --------------- lib/strutils.c | 14 -------------- lib/test_fileutils.c | 10 ++++++++++ lib/test_nsutils.c | 15 +++++++++++++++ lib/test_strutils.c | 38 ++++++++++++++++++++++++++++++++++++++ 7 files changed, 68 insertions(+), 45 deletions(-) create mode 100644 lib/test_fileutils.c create mode 100644 lib/test_nsutils.c create mode 100644 lib/test_strutils.c diff --git a/lib/Makefile.am b/lib/Makefile.am index f09cb8c0..d88e750f 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,12 +1,11 @@ AM_CPPFLAGS = \ -include $(top_builddir)/config.h \ -I$(top_srcdir) \ - -I$(top_srcdir)/include - -AM_CPPFLAGS += -DTEST_PROGRAM + -I$(top_srcdir)/include \ + -DLOCALEDIR=\"$(localedir)\" noinst_PROGRAMS = test_strutils test_fileutils test_nsutils -test_strutils_SOURCES = strutils.c -test_fileutils_SOURCES = fileutils.c -test_nsutils_SOURCES = nsutils.c +test_strutils_SOURCES = test_strutils.c strutils.c +test_fileutils_SOURCES = test_fileutils.c fileutils.c +test_nsutils_SOURCES = test_nsutils.c nsutils.c diff --git a/lib/fileutils.c b/lib/fileutils.c index 1ade3d80..14c7452f 100644 --- a/lib/fileutils.c +++ b/lib/fileutils.c @@ -43,13 +43,3 @@ void close_stdout(void) if (close_stream(stderr) != 0) _exit(EXIT_FAILURE); } - -#ifdef TEST_PROGRAM -#include -int main(int argc, char *argv[]) -{ - atexit(close_stdout); - printf("Hello, World!\n"); - return EXIT_SUCCESS; -} -#endif /* TEST_PROGRAM */ diff --git a/lib/nsutils.c b/lib/nsutils.c index d1cc6c96..673258ec 100644 --- a/lib/nsutils.c +++ b/lib/nsutils.c @@ -8,13 +8,6 @@ #include "proc/readproc.h" #include "nsutils.h" -#ifdef TEST_PROGRAM -const char *get_ns_name(int id) -{ - return NULL; -} -#endif /* TEST_PROGRAM */ - /* we need to fill in only namespace information */ int ns_read(pid_t pid, proc_t *ns_task) { @@ -35,11 +28,3 @@ int ns_read(pid_t pid, proc_t *ns_task) } return rc; } - -#ifdef TEST_PROGRAM -int main(int argc, char *argv[]) -{ - printf("Hello, World!\n"); - return EXIT_SUCCESS; -} -#endif /* TEST_PROGRAM */ diff --git a/lib/strutils.c b/lib/strutils.c index 1b84f8ab..0fd3cf71 100644 --- a/lib/strutils.c +++ b/lib/strutils.c @@ -60,17 +60,3 @@ double strtod_or_err(const char *str, const char *errmesg) error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str); return 0; } - -#ifdef TEST_PROGRAM -int main(int argc, char *argv[]) -{ - if (argc < 2) { - error(EXIT_FAILURE, 0, "no arguments"); - } else if (argc < 3) { - printf("%ld\n", strtol_or_err(argv[1], "strtol_or_err")); - } else { - printf("%lf\n", strtod_or_err(argv[2], "strtod_or_err")); - } - return EXIT_SUCCESS; -} -#endif /* TEST_PROGRAM */ diff --git a/lib/test_fileutils.c b/lib/test_fileutils.c new file mode 100644 index 00000000..ebfc5e25 --- /dev/null +++ b/lib/test_fileutils.c @@ -0,0 +1,10 @@ +#include +#include +#include "fileutils.h" + +int main(int argc, char *argv[]) +{ + atexit(close_stdout); + printf("Hello, World!\n"); + return EXIT_SUCCESS; +} diff --git a/lib/test_nsutils.c b/lib/test_nsutils.c new file mode 100644 index 00000000..d8f3d2cf --- /dev/null +++ b/lib/test_nsutils.c @@ -0,0 +1,15 @@ +#include +#include + +#include "nsutils.h" + +const char *get_ns_name(int id) +{ + return NULL; +} + +int main(int argc, char *argv[]) +{ + printf("Hello, World!\n"); + return EXIT_SUCCESS; +} diff --git a/lib/test_strutils.c b/lib/test_strutils.c new file mode 100644 index 00000000..4a7c7aaa --- /dev/null +++ b/lib/test_strutils.c @@ -0,0 +1,38 @@ +/* + * test_strutils.c - tests for strutils.c routines + * This file was copied from util-linux at fall 2011. + * + * Copyright (C) 2010 Karel Zak + * Copyright (C) 2010 Davidlohr Bueso + * + * 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 2 + * 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 "c.h" +#include "strutils.h" + +int main(int argc, char *argv[]) +{ + if (argc < 2) { + error(EXIT_FAILURE, 0, "no arguments"); + } else if (argc < 3) { + printf("%ld\n", strtol_or_err(argv[1], "strtol_or_err")); + } else { + printf("%lf\n", strtod_or_err(argv[2], "strtod_or_err")); + } + return EXIT_SUCCESS; +}