018d2f87b6f0b047a86ce59ebc05443be81be835 — Zach Smith 3 months ago 7fa1a6f master v0.6.3
Remove blacklist code
3 files changed, 1 insertions(+), 52 deletions(-)

M src/env.janet
M test/markdown.janet
D test/require.janet
M src/env.janet => src/env.janet +1 -32
@@ 1,22 1,5 @@
(import spork/temple)

(def required-checks @{})
(def exec-blacklist @{})

(defmacro defrequire
  Define a function, preceded by the name of an external program. If
  this program is not present when Bagatto is run, this function will
  raise an error.
  [program name args & body]
  ~((put env/required-checks ,program true)
     (defn ,name
       (when (in (dyn :executable-blacklist) ,program)
         (error (string "Required executable not installed: " ,program)))

(defn- on-path?
  (let [f (file/open "/dev/null" :w)]

@@ 29,21 12,7 @@
    nil :ok
    janet-path (put root-env :syspath janet-path)))

(defn- populate-exec-blacklist!
  Iterate through all the executables declared with `defrequire` and
  check for their existence in the path. Add a blacklist of all
  executables that are absent from the path to the given environment.
  (loop [check :keys required-checks]
    (unless (on-path? check)
      (put exec-blacklist check true))))

(defn setdyn-blacklist! [] (setdyn :executable-blacklist exec-blacklist))

(defn prepare-root-env!

M test/markdown.janet => test/markdown.janet +0 -2
@@ 1,8 1,6 @@
(import testament :prefix "" :exit true)
(import /bagatto)

(setdyn :executable-blacklist {})

(deftest render-nested-md
  (let [nesting ```
                * [one](https://janetdocs.com)

D test/require.janet => test/require.janet +0 -18
@@ 1,18 0,0 @@
(import testament :prefix "" :exit true)
(import /src/env)

(setdyn :executable-blacklist {})

(deftest in-place
  (env/defrequire "ls" should-run [] :ok)
  (is (= :ok (should-run))))

(deftest not-in-place
  (env/defrequire "this-application-cannot-be-found" should-fail [] :ok)
  (assert-thrown (should-fail)))