From 85028967d8fe15a13c3d872d0435a73f7f286079 Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sat, 17 Aug 2024 09:57:56 -0500 Subject: [PATCH] Add aliases for bundle/module - issue #1486 info.jdn -> bundle/info.jdn bundle.janet -> bundle/init.janet --- examples/sample-bundle-aliases/aliases-mod.janet | 1 + examples/sample-bundle-aliases/bundle.janet | 3 +++ examples/sample-bundle-aliases/info.jdn | 4 ++++ src/boot/boot.janet | 7 ++++++- test/helper.janet | 16 +++++++++++++--- test/suite-bundle.janet | 9 +++++++++ 6 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 examples/sample-bundle-aliases/aliases-mod.janet create mode 100644 examples/sample-bundle-aliases/bundle.janet create mode 100644 examples/sample-bundle-aliases/info.jdn diff --git a/examples/sample-bundle-aliases/aliases-mod.janet b/examples/sample-bundle-aliases/aliases-mod.janet new file mode 100644 index 00000000..a5f66831 --- /dev/null +++ b/examples/sample-bundle-aliases/aliases-mod.janet @@ -0,0 +1 @@ +(defn fun [x] (range x)) diff --git a/examples/sample-bundle-aliases/bundle.janet b/examples/sample-bundle-aliases/bundle.janet new file mode 100644 index 00000000..fc6eefac --- /dev/null +++ b/examples/sample-bundle-aliases/bundle.janet @@ -0,0 +1,3 @@ +(defn install + [manifest &] + (bundle/add-file manifest "aliases-mod.janet")) diff --git a/examples/sample-bundle-aliases/info.jdn b/examples/sample-bundle-aliases/info.jdn new file mode 100644 index 00000000..65bb8646 --- /dev/null +++ b/examples/sample-bundle-aliases/info.jdn @@ -0,0 +1,4 @@ +@{ + :name "sample-bundle-aliases" + :dependencies ["sample-dep1" "sample-dep2"] +} diff --git a/src/boot/boot.janet b/src/boot/boot.janet index 2bfd4269..ba6774ca 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -4219,7 +4219,8 @@ (def check (get config :check)) (def s (sep)) # Check meta file for dependencies and default name - (def infofile-pre (string path s "bundle" s "info.jdn")) + (def infofile-pre-1 (string path s "bundle" s "info.jdn")) + (def infofile-pre (if (fexists infofile-pre-1) infofile-pre-1 (string path s "info.jdn"))) # allow for alias (var default-bundle-name nil) (when (os/stat infofile-pre :mode) (def info (-> infofile-pre slurp parse)) @@ -4239,6 +4240,10 @@ # Setup installed paths (prime-bundle-paths) (os/mkdir (bundle-dir bundle-name)) + # Aliases for common bundle/ files + (def bundle.janet (string path s "bundle.janet")) + (when (fexists bundle.janet) (copyfile bundle.janet (bundle-file bundle-name "init.janet"))) + (when (fexists infofile-pre) (copyfile infofile-pre (bundle-file bundle-name "info.jdn"))) # Copy some files into the new location unconditionally (def implicit-sources (string path s "bundle")) (when (= :directory (os/stat implicit-sources :mode)) diff --git a/test/helper.janet b/test/helper.janet index 799f3993..aed83897 100644 --- a/test/helper.janet +++ b/test/helper.janet @@ -7,21 +7,31 @@ (def is-verbose (os/getenv "VERBOSE")) -(defn assert +(defn- assert-no-tail "Override's the default assert with some nice error handling." [x &opt e] (default e "assert error") (++ num-tests-run) (when x (++ num-tests-passed)) (def str (string e)) - (def frame (last (debug/stack (fiber/current)))) + (def stack (debug/stack (fiber/current))) + (def frame (last stack)) (def line-info (string/format "%s:%d" (frame :source) (frame :source-line))) (if x (when is-verbose (eprintf "\e[32m✔\e[0m %s: %s: %v" line-info (describe e) x)) - (do (eprintf "\e[31m✘\e[0m %s: %s: %v" line-info (describe e) x) (eflush))) + (do + (eprintf "\e[31m✘\e[0m %s: %s: %v" line-info (describe e) x) (eflush))) x) +(defmacro assert + [x &opt e] + (def xx (gensym)) + ~(do + (def ,xx ,x) + (,assert-no-tail ,xx ,e) + ,xx)) + (defmacro assert-error [msg & forms] (def errsym (keyword (gensym))) diff --git a/test/suite-bundle.janet b/test/suite-bundle.janet index f7452bd2..3b9d1b96 100644 --- a/test/suite-bundle.janet +++ b/test/suite-bundle.janet @@ -23,6 +23,8 @@ (assert true) # smoke test +# Testing here is stateful since we are manipulating the filesystem. + # Copy since not exposed in boot.janet (defn- bundle-rpath [path] @@ -100,6 +102,13 @@ (assert-error "cannot uninstall sample-dep1, breaks dependent bundles @[\"sample-bundle\"]" (bundle/uninstall "sample-dep1")) +# Check bundle file aliases +(assert-no-error "sample-bundle-aliases install" (bundle/install "./examples/sample-bundle-aliases")) +(assert (= 4 (length (bundle/list))) "bundles are listed correctly 5") +(assert-no-error "import aliases" (import aliases-mod)) +(assert (deep= (range 12) (aliases-mod/fun 12)) "using sample-bundle-aliases") +(assert-no-error "aliases uninstall" (bundle/uninstall "sample-bundle-aliases")) + # Now re-install sample-bundle as auto-remove (assert-no-error "sample-bundle install" (bundle/reinstall "sample-bundle" :auto-remove true))