diff --git a/test-suite/tests/socket.test b/test-suite/tests/socket.test index 8fccc36c5..cc512bf26 100644 --- a/test-suite/tests/socket.test +++ b/test-suite/tests/socket.test @@ -1,6 +1,6 @@ ;;;; socket.test --- test socket functions -*- scheme -*- ;;;; -;;;; Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. +;;;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. ;;;; ;;;; This library is free software; you can redistribute it and/or ;;;; modify it under the terms of the GNU Lesser General Public @@ -174,13 +174,28 @@ ;;; AF_UNIX sockets and `make-socket-address' ;;; +(define %tmpdir + ;; Honor `$TMPDIR', which tmpnam(3) doesn't do. + (or (getenv "TMPDIR") "/tmp")) + +(define %curdir + ;; Remember the current working directory. + (getcwd)) + +;; Temporarily cd to %TMPDIR. The goal is to work around path name +;; limitations, which can lead to exceptions like: +;; +;; (misc-error "scm_to_sockaddr" +;; "unix address path too long: ~A" +;; ("/tmp/nix-build-fb7bph4ifh0vr3ihigm702dzffdnapfj-guile-coverage-1.9.5.drv-0/guile-test-socket-1258553296-77619") +;; #f) +(chdir %tmpdir) + (define (temp-file-path) - ;; Return a temporary file path that honors `$TMPDIR', which `tmpnam' - ;; doesn't do. - (let ((dir (or (getenv "TMPDIR") "/tmp"))) - (string-append dir "/guile-test-socket-" - (number->string (current-time)) "-" - (number->string (random 100000))))) + ;; Return a temporary file name, assuming the current directory is %TMPDIR. + (string-append "guile-test-socket-" + (number->string (current-time)) "-" + (number->string (random 100000)))) (if (defined? 'AF_UNIX) @@ -408,4 +423,7 @@ (let ((status (cdr (waitpid server-pid)))) (eq? 0 (status:exit-val status))))) - #t))) \ No newline at end of file + #t))) + +;; Switch back to the previous directory. +(false-if-exception (chdir %curdir))