From: Eric Blake Date: Fri, 11 Sep 2009 14:59:54 +0000 (-0600) Subject: test-canonicalize-lgpl: consolidate into single C program X-Git-Tag: v0.1~5474 X-Git-Url: http://erislabs.org.uk/gitweb/?a=commitdiff_plain;h=59a85b3ebaf70211eb568441a9d2c33619c97ae6;p=gnulib.git test-canonicalize-lgpl: consolidate into single C program Testing canonicalize bugs is easier if the setup can be run under control of the debugger, rather than in a driver script. As a bonus side effect, parallel testing with test-canonicalize no longer competes for the file name "./ise". * tests/test-canonicalize-lgpl.sh: Delete; move setup into... * tests/test-canonicalize-lgpl.c (main): ...the program, making it easier to run in debugger. Add some tests. * modules/canonicalize-lgpl-tests (Files): Remove unused file. (configure.ac, Makefile.am): Simplify. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 6ee35f04e..063a07bb0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,12 @@ 2009-09-17 Eric Blake + test-canonicalize-lgpl: consolidate into single C program + * tests/test-canonicalize-lgpl.sh: Delete; move setup into... + * tests/test-canonicalize-lgpl.c (main): ...the program, making it + easier to run in debugger. Add some tests. + * modules/canonicalize-lgpl-tests (Files): Remove unused file. + (configure.ac, Makefile.am): Simplify. + canonicalize: avoid resolvepath * m4/canonicalize.m4 (gl_FUNC_CANONICALIZE_FILENAME_MODE): Delete unnecessary checks. diff --git a/modules/canonicalize-lgpl-tests b/modules/canonicalize-lgpl-tests index ac40166d4..200950986 100644 --- a/modules/canonicalize-lgpl-tests +++ b/modules/canonicalize-lgpl-tests @@ -1,16 +1,11 @@ Files: -tests/test-canonicalize-lgpl.sh tests/test-canonicalize-lgpl.c Depends-on: configure.ac: AC_CHECK_FUNCS_ONCE([symlink]) -HAVE_SYMLINK=$ac_cv_func_symlink -AC_SUBST([HAVE_SYMLINK]) Makefile.am: -TESTS += test-canonicalize-lgpl.sh -TESTS_ENVIRONMENT += EXEEXT='@EXEEXT@' HAVE_SYMLINK='$(HAVE_SYMLINK)' +TESTS += test-canonicalize-lgpl check_PROGRAMS += test-canonicalize-lgpl -test_canonicalize_lgpl_LDADD = $(LDADD) diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index 29b919df8..bc58d5904 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -1,5 +1,5 @@ /* Test of execution of program termination handlers. - Copyright (C) 2007-2008 Free Software Foundation, Inc. + Copyright (C) 2007-2009 Free Software Foundation, Inc. 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 @@ -20,9 +20,17 @@ #include "canonicalize.h" +#include +#include #include #include #include +#include +#include + +#if !HAVE_SYMLINK +# define symlink(a,b) (-1) +#endif /* !HAVE_SYMLINK */ #define ASSERT(expr) \ do \ @@ -36,6 +44,8 @@ } \ while (0) +#define BASE "t-can-lgpl.tmp" + int main () { @@ -45,29 +55,75 @@ main () return 0; #endif + /* Setup some hierarchy to be used by this test. Start by removing + any leftovers from a previous partial run. */ + { + int fd; + ASSERT (system ("rm -rf " BASE " ise") == 0); + ASSERT (mkdir (BASE, 0700) == 0); + fd = creat (BASE "/tra", 0600); + ASSERT (0 <= fd); + ASSERT (close (fd) == 0); + } + + /* Check for ., .., intermediate // handling, and for error cases. */ + { + char *result = canonicalize_file_name (BASE "//./..//" BASE "/tra"); + ASSERT (result != NULL); + ASSERT (strstr (result, "/" BASE "/tra") + == result + strlen (result) - strlen ("/" BASE "/tra")); + free (result); + errno = 0; + result = canonicalize_file_name (""); + ASSERT (result == NULL); + ASSERT (errno == ENOENT); + errno = 0; + result = canonicalize_file_name (NULL); + ASSERT (result == NULL); + ASSERT (errno == EINVAL); + } + + /* From here on out, tests involve symlinks. */ + if (symlink (BASE "/ket", "ise") != 0) + { + ASSERT (remove (BASE "/tra") == 0); + ASSERT (rmdir (BASE) == 0); + fputs ("skipping test: symlinks not supported on this filesystem\n", + stderr); + return 77; + } + ASSERT (symlink ("bef", BASE "/plo") == 0); + ASSERT (symlink ("tra", BASE "/huk") == 0); + ASSERT (symlink ("lum", BASE "/bef") == 0); + ASSERT (symlink ("wum", BASE "/ouk") == 0); + ASSERT (symlink ("../ise", BASE "/ket") == 0); + ASSERT (mkdir (BASE "/lum", 0700) == 0); + /* Check that the symbolic link to a file can be resolved. */ { - char *result1 = canonicalize_file_name ("t-can-lgpl.tmp/huk"); - char *result2 = canonicalize_file_name ("t-can-lgpl.tmp/tra"); + char *result1 = canonicalize_file_name (BASE "/huk"); + char *result2 = canonicalize_file_name (BASE "/tra"); ASSERT (result1 != NULL); ASSERT (result2 != NULL); ASSERT (strcmp (result1, result2) == 0); - ASSERT (strcmp (result1 + strlen (result1) - 19, "/t-can-lgpl.tmp/tra") == 0); + ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/tra"), + "/" BASE "/tra") == 0); free (result1); free (result2); } /* Check that the symbolic link to a directory can be resolved. */ { - char *result1 = canonicalize_file_name ("t-can-lgpl.tmp/plo"); - char *result2 = canonicalize_file_name ("t-can-lgpl.tmp/bef"); - char *result3 = canonicalize_file_name ("t-can-lgpl.tmp/lum"); + char *result1 = canonicalize_file_name (BASE "/plo"); + char *result2 = canonicalize_file_name (BASE "/bef"); + char *result3 = canonicalize_file_name (BASE "/lum"); ASSERT (result1 != NULL); ASSERT (result2 != NULL); ASSERT (result3 != NULL); ASSERT (strcmp (result1, result2) == 0); ASSERT (strcmp (result2, result3) == 0); - ASSERT (strcmp (result1 + strlen (result1) - 19, "/t-can-lgpl.tmp/lum") == 0); + ASSERT (strcmp (result1 + strlen (result1) - strlen ("/" BASE "/lum"), + "/" BASE "/lum") == 0); free (result1); free (result2); free (result3); @@ -75,15 +131,32 @@ main () /* Check that a symbolic link to a nonexistent file yields NULL. */ { - char *result = canonicalize_file_name ("t-can-lgpl.tmp/ouk"); + char *result; + errno = 0; + result = canonicalize_file_name (BASE "/ouk"); ASSERT (result == NULL); + ASSERT (errno == ENOENT); } /* Check that a loop of symbolic links is detected. */ { - char *result = canonicalize_file_name ("ise"); + char *result; + errno = 0; + result = canonicalize_file_name ("ise"); ASSERT (result == NULL); + ASSERT (errno == ELOOP); } + /* Cleanup. */ + ASSERT (remove (BASE "/plo") == 0); + ASSERT (remove (BASE "/huk") == 0); + ASSERT (remove (BASE "/bef") == 0); + ASSERT (remove (BASE "/ouk") == 0); + ASSERT (remove (BASE "/ket") == 0); + ASSERT (remove (BASE "/lum") == 0); + ASSERT (remove (BASE "/tra") == 0); + ASSERT (remove (BASE) == 0); + ASSERT (remove ("ise") == 0); + return 0; } diff --git a/tests/test-canonicalize-lgpl.sh b/tests/test-canonicalize-lgpl.sh deleted file mode 100755 index e439b7a15..000000000 --- a/tests/test-canonicalize-lgpl.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh - -tmpfiles="" -trap 'rm -fr $tmpfiles' 1 2 3 15 - -tmpfiles="$tmpfiles t-can-lgpl.tmp ise" -mkdir t-can-lgpl.tmp -test "x$HAVE_SYMLINK" = xyes \ - && ln -s t-can-lgpl.tmp/ket ise \ - || { echo "Skipping test: symbolic links not supported on this filesystem" - rm -fr $tmpfiles - exit 77 - } -(cd t-can-lgpl.tmp \ - && ln -s bef plo \ - && ln -s tra huk \ - && ln -s lum bef \ - && ln -s wum ouk \ - && ln -s ../ise ket \ - && echo > tra \ - && mkdir lum -) || exit 1 - -./test-canonicalize-lgpl${EXEEXT} -result=$? - -rm -fr $tmpfiles - -exit $result