From acd7010e6b951b7888168f4655bcf2db12018099 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Fri, 9 Oct 2026 17:35:05 +0300 Subject: [PATCH] resolve a relative SEX_MODULE_PATH entry from the working directory make-absolute-pathname with no directory of its own put `src' under the root, so SEX_MODULE_PATH=src searched /src/. Fixes #48. --- sex-modules.scm | 3 +-- tests/Makefile | 2 +- tests/module-path.scm | 22 ++++++++++++++++++++++ tests/run.scm | 1 + 4 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 tests/module-path.scm diff --git a/sex-modules.scm b/sex-modules.scm index c3f1c61..a613cb3 100644 --- a/sex-modules.scm +++ b/sex-modules.scm @@ -159,6 +159,5 @@ (get-env-var "SEX_MODULE_PATH"))) (when sex-module-path-env-var (set! +persistent-module-paths+ - (map (lambda (p) - (make-absolute-pathname p #f #f)) + (map to-absolute-pathname (string-split sex-module-path-env-var ":")))))) diff --git a/tests/Makefile b/tests/Makefile index 1e87b3c..9a4b6c6 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -6,7 +6,7 @@ MODULE_FLAGS = -emit-all-import-libraries -module-registration -c MODULES = utils types infer sex-macros reader sex-modules semen sex-fmt-c fmt-c-writer sexc SEX_OBJ = $(MODULES:%=%.o) -TESTS = basic semen reader fmt-c-writer utils line-directives codegen encapsulation args types infer +TESTS = basic semen reader fmt-c-writer utils line-directives codegen encapsulation args module-path types infer TEST_SRCS = $(TESTS:%=%.scm) sex-tests: run.scm $(TEST_SRCS) $(SEX_OBJ) diff --git a/tests/module-path.scm b/tests/module-path.scm new file mode 100644 index 0000000..fbce788 --- /dev/null +++ b/tests/module-path.scm @@ -0,0 +1,22 @@ +;;; Where imports are looked for. SEX_MODULE_PATH is read once, at the +;;; start, from the directory sexc was started in. + +(import (chicken pathname) + (chicken process-context) + sex-modules) + +(test-group "module path" + ;; make-absolute-pathname took `src' for a directory under the root, + ;; and an import searched /src/ + (set-environment-variable! "SEX_MODULE_PATH" "src:/abs/lib") + (load-persistent-module-paths) + (test "a relative entry is from the working directory" + (make-absolute-pathname (current-directory) "src") + (second (get-module-paths))) + (test "an absolute one is as written" + "/abs/lib" + (third (get-module-paths))) + + (set-environment-variable! "SEX_MODULE_PATH" "") + (load-persistent-module-paths) + (unset-environment-variable! "SEX_MODULE_PATH")) diff --git a/tests/run.scm b/tests/run.scm index d0cc9ca..8464382 100644 --- a/tests/run.scm +++ b/tests/run.scm @@ -10,6 +10,7 @@ (include "codegen.scm") (include "encapsulation.scm") (include "args.scm") +(include "module-path.scm") (include "types.scm") (include "infer.scm")