]> gitweb.factorcode.org Git - factor.git/blobdiff - basis/tools/scaffold/scaffold.factor
tools.scaffold: Support unit tests with more than one output with run-string helper...
[factor.git] / basis / tools / scaffold / scaffold.factor
index 0d73e7a2d512ee1fe279aecef0d6e7e7002fe9e7..845f2324e279c8163d72578cc973823bba4fe56e 100644 (file)
@@ -5,9 +5,9 @@ classes classes.error combinators combinators.short-circuit
 continuations eval hashtables help.markup interpolate io
 io.directories io.encodings.utf8 io.files io.pathnames
 io.streams.string kernel math math.parser namespaces prettyprint
-quotations sequences sequences.extras sets sorting splitting
-strings system timers unicode urls vocabs vocabs.loader
-vocabs.metadata words words.symbol ;
+quotations sequences sets sorting splitting strings system
+timers unicode urls vocabs vocabs.loader vocabs.metadata words
+words.symbol ;
 IN: tools.scaffold
 
 SYMBOL: developer-name
@@ -393,23 +393,23 @@ ${example-indent}}
     ".factor-roots" scaffold-rc ;
 
 : make-unit-test ( answer code -- str )
-   [
-        prepend-lines-with-spaces
-        "{\n" "\n}" surround
-    ] [
-        prepend-lines-with-spaces
-        "[\n" "\n] unit-test\n" surround
-    ] bi* " " glue ;
+    split-lines [ "    " prepend ] map "\n" join
+    "[\n" "\n] unit-test\n" surround
+    " " glue ;
+
+: run-string ( string -- datastack )
+    parse-string V{ } clone swap with-datastack ; inline
 
 : scaffold-unit-test ( -- str/f )
     read-contents dup "" = [
         drop f
     ] [
-        [ eval( -- x ) unparse ] keep make-unit-test
+        [ run-string unparse ] keep
+        make-unit-test
     ] if ;
 
 : scaffold-unit-tests ( -- str )
-    [ scaffold-unit-test ] loop>array "\n\n" join ;
+    [ scaffold-unit-test dup ] [ ] produce nip "\n\n" join ;
 
 HOOK: scaffold-emacs os ( -- )