fs-at-test.scm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ;;;; Copyright (C) 2021 Maxime Devos <maximedevos at telenet dot be>
  2. ;;;;
  3. ;;;; This library is free software; you can redistribute it and/or
  4. ;;;; modify it under the terms of the GNU Lesser General Public
  5. ;;;; License as published by the Free Software Foundation; either
  6. ;;;; version 3 of the License, or (at your option) any later version.
  7. ;;;;
  8. ;;;; This library is distributed in the hope that it will be useful,
  9. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. ;;;; Lesser General Public License for more details.
  12. ;;;;
  13. ;;;; You should have received a copy of the GNU Lesser General Public
  14. ;;;; License along with this library; if not, write to the Free Software
  15. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 U>
  16. (use-modules (srfi srfi-64)
  17. (fs-at))
  18. ;; XXX use call-with-temporary-directory or something
  19. ;; like that.
  20. ;; XXX don't rely on GC for closing ports
  21. (define *testdir* (make-parameter "/tmp/fs-at-test"))
  22. (define (file-in-testdir name)
  23. (string-append (*testdir*) name))
  24. (define (t:mkdir)
  25. (let* ((test (open (*testdir*) O_RDONLY))
  26. (new (make-path-at test "mkdir0")))
  27. (mkdir new)
  28. (test-eq "type of diretory made with mkdirat"
  29. 'directory
  30. (stat:type (stat new)))))
  31. (define (touch where)
  32. (open where O_CREAT))
  33. (define (stat:repro f)
  34. (let ((s (stat f)))
  35. ;; XXX investigate
  36. (vector-set! s 17 'dont-look-at-ctimensec)
  37. ;; XXX I presume these are affected as well
  38. (vector-set! s 10 'dont-look-at-ctime)
  39. (vector-set! s 8 'dont-look-at-atime)
  40. (vector-set! s 6 'dont-look-at-atimensec)
  41. s))
  42. (define (t:stat)
  43. (let* ((test (open (*testdir*) O_RDONLY))
  44. (new (make-path-at test "stat0"))
  45. (new-port (touch new)))
  46. (let ((guile-stat (stat:repro (string-append (*testdir*) "/stat0")))
  47. (port-stat (stat:repro new-port))
  48. (stat-at (stat:repro new)))
  49. (test-equal "stat filename/port" guile-stat port-stat)
  50. (test-equal "stat filename/at" guile-stat stat-at))))
  51. (define (test)
  52. (if (file-exists? (*testdir*))
  53. (system* "rm" "-r" (*testdir*)))
  54. (mkdir (*testdir*))
  55. (test-begin "fs-at")
  56. (t:mkdir)
  57. (t:stat)
  58. (test-end "fs-at"))
  59. (test)