mirror of
https://github.com/janet-lang/janet
synced 2025-01-20 20:26:51 +00:00
Save :source-form in environment when debugging is enabled.
This commit is contained in:
parent
43ecd4f2d8
commit
5a199716cb
@ -2,6 +2,7 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
|
|
||||||
## Unreleased - ???
|
## Unreleased - ???
|
||||||
|
- Save `:source-form` in environment entries when `*debug*` is set.
|
||||||
- Add experimental `filewatch/` module for listening to file system changes.
|
- Add experimental `filewatch/` module for listening to file system changes.
|
||||||
- Add `bundle/who-is` to query which bundle a file on disk was installed by.
|
- Add `bundle/who-is` to query which bundle a file on disk was installed by.
|
||||||
- Add `geomean` function
|
- Add `geomean` function
|
||||||
|
@ -39,6 +39,7 @@
|
|||||||
(buffer/format buf "%j" (in args index))
|
(buffer/format buf "%j" (in args index))
|
||||||
(set index (+ index 1)))
|
(set index (+ index 1)))
|
||||||
(array/push modifiers (string buf ")\n\n" docstr))
|
(array/push modifiers (string buf ")\n\n" docstr))
|
||||||
|
(if (dyn :debug) (array/push modifiers {:source-form (dyn :macro-form)}))
|
||||||
# Build return value
|
# Build return value
|
||||||
~(def ,name ,;modifiers (fn ,name ,;(tuple/slice more start)))))
|
~(def ,name ,;modifiers (fn ,name ,;(tuple/slice more start)))))
|
||||||
|
|
||||||
@ -4654,6 +4655,9 @@
|
|||||||
(put flat :doc nil))
|
(put flat :doc nil))
|
||||||
(when (boot/config :no-sourcemaps)
|
(when (boot/config :no-sourcemaps)
|
||||||
(put flat :source-map nil))
|
(put flat :source-map nil))
|
||||||
|
(unless (v :private)
|
||||||
|
(unless (v :doc)
|
||||||
|
(errorf "no docs: %v %p" k v))) # make sure we have docs
|
||||||
# Fix directory separators on windows to make image identical between windows and non-windows
|
# Fix directory separators on windows to make image identical between windows and non-windows
|
||||||
(when-let [sm (get flat :source-map)]
|
(when-let [sm (get flat :source-map)]
|
||||||
(put flat :source-map [(string/replace-all "\\" "/" (sm 0)) (sm 1) (sm 2)]))
|
(put flat :source-map [(string/replace-all "\\" "/" (sm 0)) (sm 1) (sm 2)]))
|
||||||
|
@ -4,14 +4,20 @@
|
|||||||
(var num-tests-run 0)
|
(var num-tests-run 0)
|
||||||
(var suite-name 0)
|
(var suite-name 0)
|
||||||
(var start-time 0)
|
(var start-time 0)
|
||||||
|
(var skip-count 0)
|
||||||
|
(var skip-n 0)
|
||||||
|
|
||||||
(def is-verbose (os/getenv "VERBOSE"))
|
(def is-verbose (os/getenv "VERBOSE"))
|
||||||
|
|
||||||
(defn- assert-no-tail
|
(defn- assert-no-tail
|
||||||
"Override's the default assert with some nice error handling."
|
"Override's the default assert with some nice error handling."
|
||||||
[x &opt e]
|
[x &opt e]
|
||||||
(default e "assert error")
|
|
||||||
(++ num-tests-run)
|
(++ num-tests-run)
|
||||||
|
(when (pos? skip-n)
|
||||||
|
(-- skip-n)
|
||||||
|
(++ skip-count)
|
||||||
|
(break x))
|
||||||
|
(default e "assert error")
|
||||||
(when x (++ num-tests-passed))
|
(when x (++ num-tests-passed))
|
||||||
(def str (string e))
|
(def str (string e))
|
||||||
(def stack (debug/stack (fiber/current)))
|
(def stack (debug/stack (fiber/current)))
|
||||||
@ -24,9 +30,16 @@
|
|||||||
(eprintf "\e[31m✘\e[0m %s: %s: %v" line-info (describe e) x) (eflush)))
|
(eprintf "\e[31m✘\e[0m %s: %s: %v" line-info (describe e) x) (eflush)))
|
||||||
x)
|
x)
|
||||||
|
|
||||||
|
(defn skip-asserts
|
||||||
|
"Skip some asserts"
|
||||||
|
[n]
|
||||||
|
(+= skip-n n)
|
||||||
|
nil)
|
||||||
|
|
||||||
(defmacro assert
|
(defmacro assert
|
||||||
[x &opt e]
|
[x &opt e]
|
||||||
(def xx (gensym))
|
(def xx (gensym))
|
||||||
|
(default e ~',x)
|
||||||
~(do
|
~(do
|
||||||
(def ,xx ,x)
|
(def ,xx ,x)
|
||||||
(,assert-no-tail ,xx ,e)
|
(,assert-no-tail ,xx ,e)
|
||||||
@ -62,8 +75,8 @@
|
|||||||
(defn end-suite []
|
(defn end-suite []
|
||||||
(def delta (- (os/clock) start-time))
|
(def delta (- (os/clock) start-time))
|
||||||
(eprinf "Finished suite %s in %.3f seconds - " suite-name delta)
|
(eprinf "Finished suite %s in %.3f seconds - " suite-name delta)
|
||||||
(eprint num-tests-passed " of " num-tests-run " tests passed.")
|
(eprint num-tests-passed " of " num-tests-run " tests passed (" skip-count " skipped).")
|
||||||
(if (not= num-tests-passed num-tests-run) (os/exit 1)))
|
(if (not= (+ skip-count num-tests-passed) num-tests-run) (os/exit 1)))
|
||||||
|
|
||||||
(defn rmrf
|
(defn rmrf
|
||||||
"rm -rf in janet"
|
"rm -rf in janet"
|
||||||
|
@ -46,7 +46,6 @@
|
|||||||
(assert (deep= (array/remove @[1 2 3 4 5] 2 200) @[1 2]) "array/remove 3")
|
(assert (deep= (array/remove @[1 2 3 4 5] 2 200) @[1 2]) "array/remove 3")
|
||||||
(assert (deep= (array/remove @[1 2 3 4 5] -2 200) @[1 2 3]) "array/remove 4")
|
(assert (deep= (array/remove @[1 2 3 4 5] -2 200) @[1 2 3]) "array/remove 4")
|
||||||
|
|
||||||
|
|
||||||
# array/peek
|
# array/peek
|
||||||
(assert (nil? (array/peek @[])) "array/peek empty")
|
(assert (nil? (array/peek @[])) "array/peek empty")
|
||||||
|
|
||||||
|
@ -979,4 +979,11 @@
|
|||||||
(assert (= :a (with-env @{:b :a} (dyn :b))) "with-env dyn")
|
(assert (= :a (with-env @{:b :a} (dyn :b))) "with-env dyn")
|
||||||
(assert-error "unknown symbol +" (with-env @{} (eval '(+ 1 2))))
|
(assert-error "unknown symbol +" (with-env @{} (eval '(+ 1 2))))
|
||||||
|
|
||||||
|
(setdyn *debug* true)
|
||||||
|
(def source '(defn a [x] (+ x x)))
|
||||||
|
(eval source)
|
||||||
|
(assert (= 20 (a 10)))
|
||||||
|
(assert (deep= (get (dyn 'a) :source-form) source))
|
||||||
|
(setdyn *debug* nil)
|
||||||
|
|
||||||
(end-suite)
|
(end-suite)
|
||||||
|
Loading…
Reference in New Issue
Block a user