diff --git a/examples/sample-bad-bundle1/info.jdn b/examples/sample-bad-bundle1/info.jdn new file mode 100644 index 000000000..ed04ca733 --- /dev/null +++ b/examples/sample-bad-bundle1/info.jdn @@ -0,0 +1,3 @@ +@{ + :name "sample-bad-bundle1" +} diff --git a/examples/sample-bad-bundle/badmod.janet b/examples/sample-bad-bundle2/badmod.janet similarity index 100% rename from examples/sample-bad-bundle/badmod.janet rename to examples/sample-bad-bundle2/badmod.janet diff --git a/examples/sample-bad-bundle/bundle.janet b/examples/sample-bad-bundle2/bundle.janet similarity index 100% rename from examples/sample-bad-bundle/bundle.janet rename to examples/sample-bad-bundle2/bundle.janet diff --git a/examples/sample-bad-bundle2/info.jdn b/examples/sample-bad-bundle2/info.jdn new file mode 100644 index 000000000..96936f9f5 --- /dev/null +++ b/examples/sample-bad-bundle2/info.jdn @@ -0,0 +1,3 @@ +@{ + :name "sample-bad-bundle2" +} diff --git a/src/boot/boot.janet b/src/boot/boot.janet index cc8f3fa0b..d33a90661 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -4222,7 +4222,9 @@ (put new-env *syspath* fixed-syspath) (with-env new-env (put new-env :bundle-dir (bundle-dir bundle-name)) # get the syspath right - (require (string "@syspath/bundle/" bundle-name))))) + (try + (require (string "@syspath/bundle/" bundle-name)) + ([_] (error "bundle must contain bundle.janet or bundle/init.janet")))))) (defn- do-hook [module bundle-name hook & args] @@ -4338,26 +4340,33 @@ # Detect bundle name (def infofile-src1 (string path s "bundle" s "info.jdn")) (def infofile-src2 (string path s "info.jdn")) - (def infofile-src (cond (fexists infofile-src1) infofile-src1 + (def infofile-src (cond + (fexists infofile-src1) infofile-src1 (fexists infofile-src2) infofile-src2)) (def info (-?> infofile-src slurp parse)) (def bundle-name (get config :name (get info :name))) - (assertf bundle-name "unable to infer bundle name for %v, use :name argument" path) + (assertf bundle-name + "unable to infer bundle name for %v, use :name argument or add :name to info file" path) (assertf (not (string/check-set "\\/" bundle-name)) "bundle name %v cannot contain path separators" bundle-name) (assert (next bundle-name) "cannot use empty bundle-name") (assertf (not (fexists (get-manifest-filename bundle-name))) "bundle %v is already installed" bundle-name) + # Check bscript + (def bscript-src1 (string path s "bundle" s "init.janet")) + (def bscript-src2 (string path s "bundle.janet")) + (def bscript-src (cond + (fexists bscript-src1) bscript-src1 + (fexists bscript-src2) bscript-src2)) # Setup installed paths (prime-bundle-paths) (os/mkdir (bundle-dir bundle-name)) - # Copy infofile - (def infofile-dest (bundle-file bundle-name "info.jdn")) - (when infofile-src (copyfile infofile-src infofile-dest)) - # Copy aliased initfile - (def initfile-alias (string path s "bundle.janet")) - (def initfile-dest (bundle-file bundle-name "init.janet")) - (when (fexists initfile-alias) (copyfile initfile-alias initfile-dest)) + # Copy aliased infofile + (when (fexists infofile-src2) + (copyfile infofile-src2 (bundle-file bundle-name "info.jdn"))) + # Copy aliased bscript + (when (fexists bscript-src2) + (copyfile bscript-src2 (bundle-file bundle-name "init.janet"))) # Copy some files into the new location unconditionally (def implicit-sources (string path s "bundle")) (when (= :directory (os/stat implicit-sources :mode)) @@ -4366,8 +4375,7 @@ (merge-into man config) (sync-manifest man) (edefer (do (print "installation error, uninstalling") (bundle/uninstall bundle-name)) - (when (os/stat infofile-dest :mode) - (def info (-> infofile-dest slurp parse)) + (when info (def deps (seq [d :in (get info :dependencies @[])] (string (if (dictionary? d) (get d :name) d)))) (def missing (filter (complement bundle/installed?) deps)) diff --git a/test/helper.janet b/test/helper.janet index 4a6c8596b..c7b1e2429 100644 --- a/test/helper.janet +++ b/test/helper.janet @@ -50,6 +50,11 @@ (def errsym (keyword (gensym))) ~(assert (= ,errsym (try (do ,;forms) ([_] ,errsym))) ,msg)) +(defmacro assert-error-value + [msg errval & forms] + (def e (gensym)) + ~(assert (= ,errval (try (do ,;forms) ([,e] ,e))) ,msg)) + (defn check-compile-error [form] (def result (compile form)) diff --git a/test/suite-bundle.janet b/test/suite-bundle.janet index 0d228cc93..7da438cdd 100644 --- a/test/suite-bundle.janet +++ b/test/suite-bundle.janet @@ -117,8 +117,17 @@ (assert (= 0 (length (bundle/list))) "bundles are listed correctly 7") (assert (= 0 (length (bundle/topolist))) "bundles are listed correctly 8") +# Try installing a bundle that is missing bundle script +(assert-error-value "bundle missing bundle script" + "bundle must contain bundle.janet or bundle/init.janet" + (bundle/install "./examples/sample-bad-bundle1")) +(assert (= 0 (length (bundle/list))) "check failure 0") +(assert (= 0 (length (bundle/topolist))) "check failure 1") + # Try installing a bundle that fails check -(assert-error "bad test" (bundle/install "./examples/sample-bad-bundle" :check true)) +(assert-error-value "bundle check hook fails" + "Check failed!" + (bundle/install "./examples/sample-bad-bundle2" :check true)) (assert (= 0 (length (bundle/list))) "check failure 0") (assert (= 0 (length (bundle/topolist))) "check failure 1")