Hi,

currently, the test suite fails horribly in testfileinfo,
testfilecopy, testfile, testfnmatch, testmmap if you build with srcdir
different from builddir.

The attached patch fixes this by prepending APR_SRCDIR in the relevant
places as well as defining APR_SRCDIR in test/.  The test suite works
for me in both in-tree and out-of-tree builds with the patch applied.

Patch also available at
http://err.no/patches/apr_test_out_of_tree_build.diff

-- 
Tollef Fog Heen                                                        ,''`.
UNIX is user friendly, it's just picky about who its friends are      : :' :
                                                                      `. `' 
                                                                        `-  
Index: test/Makefile.in
===================================================================
--- test/Makefile.in	(revisjon 472307)
+++ test/Makefile.in	(arbeidskopi)
@@ -39,6 +39,8 @@
 INCDIR=../include
 INCLUDES=-I$(INCDIR) -I$(srcdir)/../include
 
+DEFS += -DAPR_SRCDIR='"$(srcdir)"'
+
 # link programs using -no-install to get real executables not
 # libtool wrapper scripts which link an executable when first run.
 LINK_PROG = $(LIBTOOL) $(LTFLAGS) --mode=link $(LT_LDFLAGS) $(COMPILE) @LT_NO_INSTALL@ $(ALL_LDFLAGS) -o $@
Index: test/testfileinfo.c
===================================================================
--- test/testfileinfo.c	(revisjon 472307)
+++ test/testfileinfo.c	(arbeidskopi)
@@ -23,8 +23,8 @@
 #include "apr_lib.h"
 #include "testutil.h"
 
-#define FILENAME "data/file_datafile.txt"
-#define NEWFILENAME "data/new_datafile.txt"
+#define FILENAME APR_SRCDIR "/data/file_datafile.txt"
+#define NEWFILENAME APR_SRCDIR "/data/new_datafile.txt"
 #define NEWFILEDATA "This is new text in a new file."
 
 static const struct view_fileinfo
Index: test/testfilecopy.c
===================================================================
--- test/testfilecopy.c	(revisjon 472307)
+++ test/testfilecopy.c	(arbeidskopi)
@@ -60,10 +60,11 @@
     apr_status_t rv;
 
     /* make absolutely sure that the dest file doesn't exist. */
+
     apr_file_remove("data/file_copy.txt", p);
     
-    copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
-                APR_FILE_SOURCE_PERMS, 0, p);
+    copy_helper(tc, APR_SRCDIR "/data/file_datafile.txt", 
+		"data/file_copy.txt", APR_FILE_SOURCE_PERMS, 0, p);
     rv = apr_file_remove("data/file_copy.txt", p);
     APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
 }
@@ -79,11 +80,11 @@
      * one file, then I copy another.  If the second copy succeeds, then
      * this works.
      */
-    copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
-                APR_FILE_SOURCE_PERMS, 0, p);
+    copy_helper(tc, APR_SRCDIR "/data/file_datafile.txt", 
+		"data/file_copy.txt", APR_FILE_SOURCE_PERMS, 0, p);
     
-    copy_helper(tc, "data/mmap_datafile.txt", "data/file_copy.txt", 
-                APR_FILE_SOURCE_PERMS, 0, p);
+    copy_helper(tc, APR_SRCDIR "/data/mmap_datafile.txt", 
+		"data/file_copy.txt", APR_FILE_SOURCE_PERMS, 0, p);
   
     rv = apr_file_remove("data/file_copy.txt", p);
     APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
@@ -96,8 +97,8 @@
     /* make absolutely sure that the dest file doesn't exist. */
     apr_file_remove("data/file_copy.txt", p);
 
-    copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
-                APR_FILE_SOURCE_PERMS, 0, p);
+    copy_helper(tc, APR_SRCDIR "/data/file_datafile.txt", 
+		"data/file_copy.txt", APR_FILE_SOURCE_PERMS, 0, p);
     rv = apr_file_remove("data/file_copy.txt", p);
     APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
 }
@@ -113,11 +114,11 @@
      * one file, then I copy another.  If the second copy succeeds, then
      * this works.
      */
-    copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
-                APR_FILE_SOURCE_PERMS, 0, p);
+    copy_helper(tc, APR_SRCDIR "/data/file_datafile.txt", 
+		"data/file_copy.txt", APR_FILE_SOURCE_PERMS, 0, p);
     
-    copy_helper(tc, "data/mmap_datafile.txt", "data/file_copy.txt", 
-                APR_FILE_SOURCE_PERMS, 1, p);
+    copy_helper(tc, APR_SRCDIR "/data/mmap_datafile.txt", 
+		"data/file_copy.txt", APR_FILE_SOURCE_PERMS, 1, p);
   
     rv = apr_file_remove("data/file_copy.txt", p);
     APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
Index: test/testfile.c
===================================================================
--- test/testfile.c	(revisjon 472307)
+++ test/testfile.c	(arbeidskopi)
@@ -23,7 +23,7 @@
 #include "apr_lib.h"
 #include "testutil.h"
 
-#define DIRNAME "data"
+#define DIRNAME APR_SRCDIR "/data"
 #define FILENAME DIRNAME "/file_datafile.txt"
 #define TESTSTR  "This is the file data file."
 
Index: test/testfnmatch.c
===================================================================
--- test/testfnmatch.c	(revisjon 472307)
+++ test/testfnmatch.c	(arbeidskopi)
@@ -32,8 +32,7 @@
     apr_array_header_t *result;
     
     APR_ASSERT_SUCCESS(tc, "glob match against data/*.txt",
-                       apr_match_glob("data\\*.txt", &result, p));
-
+                       apr_match_glob(APR_SRCDIR "/data/*.txt", &result, p));
     ABTS_INT_EQUAL(tc, NUM_FILES, result->nelts);
 
     list = (char **)result->elts;
@@ -48,7 +47,11 @@
     int i;
     char **list;
     apr_array_header_t *result;
-    apr_filepath_set("data", p);
+    char *cwd;
+
+    apr_filepath_get(&cwd, 0, p);
+
+    apr_filepath_set(APR_SRCDIR "/data", p);
     
     APR_ASSERT_SUCCESS(tc, "glob match against *.txt with data as current",
                        apr_match_glob("*.txt", &result, p));
@@ -61,7 +64,7 @@
         char *dot = strrchr(list[i], '.');
         ABTS_STR_EQUAL(tc, dot, ".txt");
     }
-    apr_filepath_set("..", p);
+    apr_filepath_set(cwd, p);
 }
 
 abts_suite *testfnmatch(abts_suite *suite)
Index: test/testmmap.c
===================================================================
--- test/testmmap.c	(revisjon 472307)
+++ test/testmmap.c	(arbeidskopi)
@@ -57,10 +57,27 @@
     ABTS_TRUE(tc, file1[strlen(file1) - 1] != '/');
 
     oldfileptr = file1;
-    file1 = apr_pstrcat(p, file1,"/data/mmap_datafile.txt" ,NULL);
+    file1 = apr_pstrcat(p, file1, "/data/mmap_datafile.txt" ,NULL);
     ABTS_TRUE(tc, oldfileptr != file1);
 }
 
+static void create_file(abts_case *tc, void *data)
+{
+    apr_status_t rv;
+    apr_size_t bytes = strlen(TEST_STRING);
+
+    rv = apr_file_open(&thefile, file1, 
+		  APR_WRITE | APR_CREATE, 
+		  APR_UREAD | APR_UWRITE | APR_GREAD, p);
+    ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+
+    rv = apr_file_write(thefile, TEST_STRING, &bytes);
+    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
+
+    rv = apr_file_close(thefile);
+    ABTS_INT_EQUAL(tc, rv, APR_SUCCESS);
+}    
+
 static void test_file_close(abts_case *tc, void *data)
 {
     apr_status_t rv;
@@ -138,6 +155,7 @@
     fsize = strlen(TEST_STRING);
 
     abts_run_test(suite, create_filename, NULL);
+    abts_run_test(suite, create_file, NULL);
     abts_run_test(suite, test_file_open, NULL);
     abts_run_test(suite, test_get_filesize, NULL);
     abts_run_test(suite, test_mmap_create, NULL);
Index: configure.in
===================================================================
--- configure.in	(revisjon 472307)
+++ configure.in	(arbeidskopi)
@@ -2164,6 +2164,7 @@
 
 if test -d $srcdir/test; then
    AC_CONFIG_FILES([test/Makefile test/internal/Makefile])
+   $MKDIR $apr_builddir
 fi
 
 dir=include/arch/unix

Reply via email to