]> granicus.if.org Git - procps-ng/commitdiff
build-sys: split test cases in lib/ into their own files
authorFilipe Brandenburger <filbranden@google.com>
Sat, 2 May 2015 00:43:51 +0000 (17:43 -0700)
committerFilipe Brandenburger <filbranden@google.com>
Sat, 2 May 2015 00:43:51 +0000 (17:43 -0700)
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 <filbranden@google.com>
lib/Makefile.am
lib/fileutils.c
lib/nsutils.c
lib/strutils.c
lib/test_fileutils.c [new file with mode: 0644]
lib/test_nsutils.c [new file with mode: 0644]
lib/test_strutils.c [new file with mode: 0644]

index f09cb8c09a9582a0daec4f71bc9c3a3f909ad693..d88e750f34536094ec80de83d87aaade6d6f6497 100644 (file)
@@ -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
index 1ade3d80fda552b6de877abbe47053a4e8e10ef1..14c7452f1021e690a2a84e37a50c381c2dc12fa5 100644 (file)
@@ -43,13 +43,3 @@ void close_stdout(void)
        if (close_stream(stderr) != 0)
                _exit(EXIT_FAILURE);
 }
-
-#ifdef TEST_PROGRAM
-#include <stdio.h>
-int main(int argc, char *argv[])
-{
-       atexit(close_stdout);
-       printf("Hello, World!\n");
-       return EXIT_SUCCESS;
-}
-#endif                         /* TEST_PROGRAM */
index d1cc6c96abdb8a5b8172119541737fec526940e1..673258ecc64d874e89bed9c74725474046bf177d 100644 (file)
@@ -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 */
index 1b84f8ab95ea3ba6f7dd0919b1b1f5328ef5c9d4..0fd3cf715d26fd3a19928d65afdb196abfd66252 100644 (file)
@@ -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 (file)
index 0000000..ebfc5e2
--- /dev/null
@@ -0,0 +1,10 @@
+#include <stdio.h>
+#include <stdlib.h>
+#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 (file)
index 0000000..d8f3d2c
--- /dev/null
@@ -0,0 +1,15 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#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 (file)
index 0000000..4a7c7aa
--- /dev/null
@@ -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 <kzak@redhat.com>
+ * Copyright (C) 2010 Davidlohr Bueso <dave@gnu.org>
+ *
+ * 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 <stdlib.h>
+
+#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;
+}