]> gitweb.factorcode.org Git - factor.git/commitdiff
help.lint.checks: improve check-example to print the stack (if any).
authorJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 May 2017 15:40:47 +0000 (08:40 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Fri, 5 May 2017 15:40:47 +0000 (08:40 -0700)
Any output from the example will be preserved like it currently is,
and any objects on the stack will be printed the same way they are
in the listener prefixed by ``--- Data stack:``.

basis/help/lint/checks/checks.factor

index e5f3a93e4a40bb936df721ee94d6616c2b0e56a9..8e3d73487d6a0891129519b2107433dc2a506fba 100644 (file)
@@ -1,10 +1,11 @@
 ! Copyright (C) 2009 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
 USING: accessors arrays assocs classes classes.struct
-classes.tuple combinators combinators.short-circuit debugger
-definitions effects eval formatting fry grouping help
-help.markup help.topics io io.streams.string kernel macros math
-namespaces sequences sequences.deep sets splitting strings
+classes.tuple combinators combinators.short-circuit
+combinators.smart continuations debugger definitions effects
+eval formatting fry grouping help help.markup help.topics io
+io.streams.string kernel macros math namespaces parser.notes
+prettyprint sequences sequences.deep sets splitting strings
 summary tools.destructors unicode vocabs vocabs.loader words
 words.constant words.symbol ;
 IN: help.lint.checks
@@ -28,12 +29,23 @@ SYMBOL: vocab-articles
         } member?
     ] reject ;
 
+: eval-with-stack ( str -- output )
+    [
+        [
+            parser-quiet? on parse-string [
+                output>array [
+                    nl "--- Data stack:" print stack.
+                ] unless-empty
+            ] call( quot -- )
+        ] [ nip print-error ] recover
+    ] with-string-writer ;
+
 : check-example ( element -- )
     [
         '[
             _ rest [
                 but-last "\n" join
-                [ (eval>string) ] call( code -- output )
+                eval-with-stack
                 "\n" ?tail drop
             ] keep
             last assert=