Files
sex/tests/module-path.scm
alex-eg 6198c51e88 look up a module on SEX_MODULE_PATH through an import in its test
The test read the search list off get-module-paths, exported for it
alone; importing a module from each entry checks what the list is for.
2026-10-20 11:48:55 +03:00

39 lines
1.4 KiB
Scheme

;;; Where imports are looked for. SEX_MODULE_PATH is read once, at the
;;; start, from the directory sexc was started in.
(import (chicken file)
(chicken pathname)
(chicken process-context)
semen
sex-modules)
(define (write-module dir name)
(create-directory dir #t)
(with-output-to-file (make-pathname dir name "sex")
(lambda () (display "(pub fn found () int)"))))
(test-group "module path"
;; make-absolute-pathname took `src' for a directory under the root,
;; and an import searched /src/
(let ((start (current-directory))
(scratch (create-temporary-directory)))
(write-module (make-pathname scratch "src") "mp-relative")
(write-module (make-pathname scratch "lib") "mp-absolute")
(change-directory scratch)
(set-environment-variable! "SEX_MODULE_PATH"
(string-append "src:" (make-pathname scratch "lib")))
(load-persistent-module-paths)
(change-directory start)
(test "a relative entry is from the working directory"
'((pub fn found () int))
(semen-process '((import mp-relative))))
(test "an absolute one is as written"
'((pub fn found () int))
(semen-process '((import mp-absolute))))
(set-environment-variable! "SEX_MODULE_PATH" "")
(load-persistent-module-paths)
(unset-environment-variable! "SEX_MODULE_PATH")
(delete-directory scratch #t)))