mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-31 07:33:01 +00:00 
			
		
		
		
	Save :source-form in environment when debugging is enabled.
This commit is contained in:
		| @@ -2,6 +2,7 @@ | ||||
| All notable changes to this project will be documented in this file. | ||||
|  | ||||
| ## Unreleased - ??? | ||||
| - Save `:source-form` in environment entries when `*debug*` is set. | ||||
| - 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 `geomean` function | ||||
|   | ||||
| @@ -39,6 +39,7 @@ | ||||
|       (buffer/format buf "%j" (in args index)) | ||||
|       (set index (+ index 1))) | ||||
|     (array/push modifiers (string buf ")\n\n" docstr)) | ||||
|     (if (dyn :debug) (array/push modifiers {:source-form (dyn :macro-form)})) | ||||
|     # Build return value | ||||
|     ~(def ,name ,;modifiers (fn ,name ,;(tuple/slice more start))))) | ||||
|  | ||||
| @@ -4654,6 +4655,9 @@ | ||||
|       (put flat :doc nil)) | ||||
|     (when (boot/config :no-sourcemaps) | ||||
|       (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 | ||||
|     (when-let [sm (get flat :source-map)] | ||||
|       (put flat :source-map [(string/replace-all "\\" "/" (sm 0)) (sm 1) (sm 2)])) | ||||
|   | ||||
| @@ -4,14 +4,20 @@ | ||||
| (var num-tests-run 0) | ||||
| (var suite-name 0) | ||||
| (var start-time 0) | ||||
| (var skip-count 0) | ||||
| (var skip-n 0) | ||||
|  | ||||
| (def is-verbose (os/getenv "VERBOSE")) | ||||
|  | ||||
| (defn- assert-no-tail | ||||
|   "Override's the default assert with some nice error handling." | ||||
|   [x &opt e] | ||||
|   (default e "assert error") | ||||
|   (++ num-tests-run) | ||||
|   (when (pos? skip-n) | ||||
|     (-- skip-n) | ||||
|     (++ skip-count) | ||||
|     (break x)) | ||||
|   (default e "assert error") | ||||
|   (when x (++ num-tests-passed)) | ||||
|   (def str (string e)) | ||||
|   (def stack (debug/stack (fiber/current))) | ||||
| @@ -24,9 +30,16 @@ | ||||
|       (eprintf "\e[31m✘\e[0m %s: %s: %v" line-info (describe e) x) (eflush))) | ||||
|   x) | ||||
|  | ||||
| (defn skip-asserts | ||||
|   "Skip some asserts" | ||||
|   [n] | ||||
|   (+= skip-n n) | ||||
|   nil) | ||||
|  | ||||
| (defmacro assert | ||||
|   [x &opt e] | ||||
|   (def xx (gensym)) | ||||
|   (default e ~',x) | ||||
|   ~(do | ||||
|      (def ,xx ,x) | ||||
|      (,assert-no-tail ,xx ,e) | ||||
| @@ -62,8 +75,8 @@ | ||||
| (defn end-suite [] | ||||
|   (def delta (- (os/clock) start-time)) | ||||
|   (eprinf "Finished suite %s in %.3f seconds - " suite-name delta) | ||||
|   (eprint num-tests-passed " of " num-tests-run " tests passed.") | ||||
|   (if (not= num-tests-passed num-tests-run) (os/exit 1))) | ||||
|   (eprint num-tests-passed " of " num-tests-run " tests passed (" skip-count " skipped).") | ||||
|   (if (not= (+ skip-count num-tests-passed) num-tests-run) (os/exit 1))) | ||||
|  | ||||
| (defn rmrf | ||||
|   "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 3]) "array/remove 4") | ||||
|  | ||||
|  | ||||
| # array/peek | ||||
| (assert (nil? (array/peek @[])) "array/peek empty") | ||||
|  | ||||
|   | ||||
| @@ -979,4 +979,11 @@ | ||||
| (assert (= :a (with-env @{:b :a} (dyn :b))) "with-env dyn") | ||||
| (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) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Calvin Rose
					Calvin Rose