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 <filbranden@google.com>
This commit is contained in:
parent
04d96fe136
commit
b56fd9d358
@ -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
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
@ -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 */
|
||||
|
10
lib/test_fileutils.c
Normal file
10
lib/test_fileutils.c
Normal file
@ -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;
|
||||
}
|
15
lib/test_nsutils.c
Normal file
15
lib/test_nsutils.c
Normal file
@ -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;
|
||||
}
|
38
lib/test_strutils.c
Normal file
38
lib/test_strutils.c
Normal file
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user