a2831049b80eb871c4e6d6538c1de54648766965 — Zach Smith 4 months ago 3ab1647
Ignore jpm-managed deps
M .gitignore => .gitignore +2 -0
@@ 1,3 1,5 @@

A demo/vendoring/janet_modules/moondown.a => demo/vendoring/janet_modules/moondown.a +0 -0
A demo/vendoring/janet_modules/moondown.meta.janet => demo/vendoring/janet_modules/moondown.meta.janet +6 -0
@@ 0,0 1,6 @@
# Metadata for static library moondown.a

{ :ldflags (quote nil)
  :cpp false
  :static-entry "janet_module_entry_moondown"
  :lflags (quote nil)}
\ No newline at end of file

A demo/vendoring/janet_modules/moondown.so => demo/vendoring/janet_modules/moondown.so +0 -0
A demo/vendoring/janet_modules/tester.janet => demo/vendoring/janet_modules/tester.janet +111 -0
@@ 0,0 1,111 @@
# Stolen from https://github.com/janet-lang/janet/blob/master/test/helper.janet
# Helper code for running tests

(var num-tests-passed 0)
(var num-tests-run 0)
(var start-time 0)
(var suite-name "")

(defn assert
  "Override's the default assert with some nice error handling."
  [x e]
  (++ num-tests-run)
  (if x
    (++ num-tests-passed)
    (if (empty? suite-name)
      (print "Test: " e)
      (print "Suite: " suite-name "\nTest: " e)))

(defn test [e x]
    (assert x e)
    ([err fib]
     (file/write stdout "\n\e[31mx\e[0m ")
     (print e)
     (debug/stacktrace fib err)
     (os/exit 1))))

(defmacro is [form]
  (let [[op expected actual] form]
    ~(let [_op ,op
           len ,(length form)
           _expected ,expected
           _actual (if (= len 2)
           result (if (= len 2)
                    ~,(_op _expected)
                    ~,(_op _expected _actual))]
        (if result
            (printf "\nFailed: %q" ',form)
            (printf "Expected: %q" (or (= len 2) _expected))
            (printf "Actual: %q" _actual))))))

(defmacro catch [& forms]
     (do ,;forms)

(defmacro assert-error
  [msg & forms]
  (def errsym (keyword (gensym)))
  ~(assert (= ,errsym (try (do ,;forms) ([_] ,errsym))) ,msg))

(defmacro assert-no-error
  [msg & forms]
  (def errsym (keyword (gensym)))
  ~(assert (not= ,errsym (try (do ,;forms) ([_] ,errsym))) ,msg))

(defn start-suite [&opt name]
  (when (string? name)
    (set suite-name name))

  (set num-tests-passed 0)
  (set num-tests-run 0)
  (set start-time (os/clock)))

(defn end-suite []
  (let [delta (- (os/clock) start-time)
        failures? (not= num-tests-passed num-tests-run)]

    (printf "%s" (if failures? "\n" ""))

    (unless (empty? suite-name)
      (print "Suite: " suite-name))

    (printf "Tests: %d/%d passed" num-tests-passed num-tests-run)
    (printf "Duration: %.3f seconds" delta)

    (if failures?
      (os/exit 1)

(defmacro deftest [& forms]
     ,(splice forms)

(defmacro deftests [& forms]
  ~(deftest ,;forms))

(defmacro defsuite [name & forms]
     (start-suite ,name)
     ,(splice forms)