test-path-handling.scm 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. (use-modules
  2. ;; for unit testing forms
  3. (srfi srfi-64))
  4. (use-modules
  5. ;; import the module to test
  6. (path-handling))
  7. (test-begin "path-handling-test")
  8. (test-group
  9. "absolute-path-test"
  10. (define path-to-current-dir
  11. (dirname (or (current-filename)
  12. (canonicalize-path "."))))
  13. (define non-existing-file-name
  14. "non-existing-file.txt")
  15. (display
  16. (simple-format
  17. #f "non existing file: ~a\n"
  18. (absolute-path non-existing-file-name)))
  19. (display
  20. (simple-format
  21. #f "path to current directory: ~a\n"
  22. path-to-current-dir))
  23. ;; absolute path existing
  24. (test-eqv path-to-current-dir (absolute-path path-to-current-dir))
  25. (test-assert (absolute-path? (absolute-path path-to-current-dir)))
  26. ;; absolute path not existing
  27. (test-eqv "/a/b/c" (absolute-path "/a/b/c"))
  28. (test-assert (absolute-path? (absolute-path "/a/b/c")))
  29. ;; non-absolute path existing
  30. (test-equal (string-append path-to-current-dir
  31. file-name-separator-string
  32. (basename (current-filename)))
  33. (absolute-path (current-filename) #:working-directory path-to-current-dir))
  34. (test-assert (absolute-path? (absolute-path (current-filename))))
  35. ;; non-absolute path not existing
  36. (test-assert (not (file-exists? non-existing-file-name)))
  37. (test-equal (string-append path-to-current-dir
  38. file-name-separator-string
  39. non-existing-file-name)
  40. (absolute-path non-existing-file-name #:working-directory path-to-current-dir))
  41. (test-assert (absolute-path? (absolute-path non-existing-file-name))))
  42. (test-group
  43. "path-join-test"
  44. (test-equal "a/b/c" (path-join "a" "b" "c"))
  45. (test-equal "/a/b/c" (path-join "" "a" "b" "c"))
  46. (test-equal "/b/c" (path-join "" "a" "/b" "c"))
  47. (test-equal "/c" (path-join "" "a" "b" "/c")))
  48. ;; Finish the testsuite, and report results.
  49. (test-end "path-handling-test")