posix.test 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. ;;;; posix.test --- Test suite for Guile POSIX functions. -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
  4. ;;;;
  5. ;;;; This program is free software; you can redistribute it and/or modify
  6. ;;;; it under the terms of the GNU General Public License as published by
  7. ;;;; the Free Software Foundation; either version 2, or (at your option)
  8. ;;;; any later version.
  9. ;;;;
  10. ;;;; This program is distributed in the hope that it will be useful,
  11. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;;;; GNU General Public License for more details.
  14. ;;;;
  15. ;;;; You should have received a copy of the GNU General Public License
  16. ;;;; along with this software; see the file COPYING. If not, write to
  17. ;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. ;;;; Boston, MA 02110-1301 USA
  19. (define-module (test-suite test-posix)
  20. :use-module (test-suite lib))
  21. ;; FIXME: The following exec tests are disabled since on an i386 debian with
  22. ;; glibc 2.3.2 they seem to interact badly with threads.test, the latter
  23. ;; dies with signal 32 (one of the SIGRTs). Don't know how or why, or who's
  24. ;; at fault (though it seems to happen with or without the recent memory
  25. ;; leak fix in these error cases).
  26. ;;
  27. ;; execl
  28. ;;
  29. ;; (with-test-prefix "execl"
  30. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  31. ;; (execl "./nosuchprog" "./nosuchprog" "some arg")))
  32. ;;
  33. ;; execlp
  34. ;;
  35. ;; (with-test-prefix "execlp"
  36. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  37. ;; (execlp "./nosuchprog" "./nosuchprog" "some arg")))
  38. ;;
  39. ;; execle
  40. ;;
  41. ;; (with-test-prefix "execle"
  42. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  43. ;; (execle "./nosuchprog" '() "./nosuchprog" "some arg"))
  44. ;; (pass-if-exception "./nosuchprog" '(system-error . ".*")
  45. ;; (execle "./nosuchprog" '("FOO=1" "BAR=2") "./nosuchprog" "some arg")))
  46. ;;
  47. ;; mkstemp!
  48. ;;
  49. (with-test-prefix "mkstemp!"
  50. ;; the temporary names used in the tests here are kept to 8 characters so
  51. ;; they'll work on a DOS 8.3 file system
  52. (define (string-copy str)
  53. (list->string (string->list str)))
  54. (pass-if-exception "number arg" exception:wrong-type-arg
  55. (mkstemp! 123))
  56. (pass-if "filename string modified"
  57. (let* ((template "T-XXXXXX")
  58. (str (string-copy template))
  59. (port (mkstemp! str))
  60. (result (not (string=? str template))))
  61. (delete-file str)
  62. result)))
  63. ;;
  64. ;; putenv
  65. ;;
  66. (with-test-prefix "putenv"
  67. (pass-if "something"
  68. (putenv "FOO=something")
  69. (equal? "something" (getenv "FOO")))
  70. (pass-if "replacing"
  71. (putenv "FOO=one")
  72. (putenv "FOO=two")
  73. (equal? "two" (getenv "FOO")))
  74. (pass-if "empty"
  75. (putenv "FOO=")
  76. (equal? "" (getenv "FOO")))
  77. (pass-if "removing"
  78. (putenv "FOO=bar")
  79. (putenv "FOO")
  80. (not (getenv "FOO")))
  81. (pass-if "modifying string doesn't change env"
  82. (let ((s (string-copy "FOO=bar")))
  83. (putenv s)
  84. (string-set! s 5 #\x)
  85. (equal? "bar" (getenv "FOO")))))
  86. ;;
  87. ;; setenv
  88. ;;
  89. (with-test-prefix "setenv"
  90. (pass-if "something"
  91. (setenv "FOO" "something")
  92. (equal? "something" (getenv "FOO")))
  93. (pass-if "replacing"
  94. (setenv "FOO" "one")
  95. (setenv "FOO" "two")
  96. (equal? "two" (getenv "FOO")))
  97. (pass-if "empty"
  98. (setenv "FOO" "")
  99. (equal? "" (getenv "FOO")))
  100. (pass-if "removing"
  101. (setenv "FOO" "something")
  102. (setenv "FOO" #f)
  103. (not (getenv "FOO"))))
  104. ;;
  105. ;; unsetenv
  106. ;;
  107. (with-test-prefix "unsetenv"
  108. (pass-if "something"
  109. (putenv "FOO=something")
  110. (unsetenv "FOO")
  111. (not (getenv "FOO")))
  112. (pass-if "empty"
  113. (putenv "FOO=")
  114. (unsetenv "FOO")
  115. (not (getenv "FOO"))))
  116. ;;
  117. ;; ttyname
  118. ;;
  119. (with-test-prefix "ttyname"
  120. (pass-if-exception "non-tty argument" exception:system-error
  121. ;; This used to crash in 1.8.1 and earlier.
  122. (let ((file (false-if-exception
  123. (open-output-file "/dev/null"))))
  124. (if (not file)
  125. (throw 'unsupported)
  126. (ttyname file)))))