diff --git a/examples/sample-bad-bundle1/info.jdn b/examples/sample-bad-bundle1/info.jdn new file mode 100644 index 00000000..ed04ca73 --- /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 00000000..96936f9f --- /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 cc8f3fa0..7bf1262c 100644 --- a/src/boot/boot.janet +++ b/src/boot/boot.janet @@ -4338,8 +4338,8 @@ # 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 - (fexists infofile-src2) infofile-src2)) + (def infofile-src (if (fexists infofile-src1) infofile-src1 infofile-src2)) + (assert (fexists infofile-src) "bundle must contain info.jdn or bundle/info.jdn") (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) @@ -4348,16 +4348,20 @@ (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 initfile + (def initfile-src1 (string path s "bundle" s "init.janet")) + (def initfile-src2 (string path s "bundle.janet")) + (def initfile-src (if (fexists initfile-src1) initfile-src1 initfile-src2)) + (assert (fexists initfile-src) "bundle must contain bundle.janet or bundle/init.janet") # 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 infofile + (when (fexists infofile-src2) + (copyfile infofile-src2 (bundle-file bundle-name "info.jdn"))) # 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)) + (when (fexists initfile-src2) + (copyfile initfile-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,15 +4370,13 @@ (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)) - (def deps (seq [d :in (get info :dependencies @[])] - (string (if (dictionary? d) (get d :name) d)))) - (def missing (filter (complement bundle/installed?) deps)) - (when (next missing) - (error (string "missing dependencies " (string/join missing ", ")))) - (put man :dependencies deps) - (put man :info info)) + (def deps (seq [d :in (get info :dependencies @[])] + (string (if (dictionary? d) (get d :name) d)))) + (def missing (filter (complement bundle/installed?) deps)) + (when (next missing) + (error (string "missing dependencies " (string/join missing ", ")))) + (put man :dependencies deps) + (put man :info info) (def module (get-bundle-module bundle-name)) (def clean (get config :clean)) (def check (get config :check)) diff --git a/test/helper.janet b/test/helper.janet index 4a6c8596..c7b1e242 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 0d228cc9..d24fd226 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 initfile +(assert-error-value "bad test" + "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 "bad test" + "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")