diff --git a/basis/tools/test/test-tests.factor b/basis/tools/test/test-tests.factor index fd51d8af8b..a58212ef81 100644 --- a/basis/tools/test/test-tests.factor +++ b/basis/tools/test/test-tests.factor @@ -1,6 +1,7 @@ +USING: continuations debugger io io.errors io.streams.string +kernel math multiline namespaces sequences tools.test +tools.test.private ; IN: tools.test.tests -USING: continuations debugger io.streams.string kernel namespaces -sequences tools.test tools.test.private ; { 1 } [ [ @@ -18,3 +19,17 @@ sequences tools.test tools.test.private ; create-test-failure [ error. ] with-string-writer "OBJ-CURRENT-THREAD" swap subseq? ] unit-test + +UNIT-TEST: [ 1 1 + ] { 2 } + +STDOUT-UNIT-TEST: [ "hello" write ] "hello" +STDERR-UNIT-TEST: [ "hello" ewrite ] "hello" + +![[ + +]] \ No newline at end of file diff --git a/basis/tools/test/test.factor b/basis/tools/test/test.factor index 478d0267f2..876c2d7240 100644 --- a/basis/tools/test/test.factor +++ b/basis/tools/test/test.factor @@ -1,13 +1,14 @@ ! Copyright (C) 2003, 2010 Slava Pestov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors arrays assocs combinators command-line -compiler.units continuations debugger effects fry -generalizations io io.files.temp io.files.unique kernel lexer -locals macros math.functions math.vectors namespaces parser -prettyprint quotations sequences sequences.generalizations -source-files source-files.errors source-files.errors.debugger -splitting stack-checker summary system tools.errors unicode -vocabs vocabs.files vocabs.metadata vocabs.parser words ; +compiler.units constructors continuations debugger effects fry +generalizations io io.files.temp io.files.unique +io.streams.string kernel lexer locals macros math.functions +math.vectors namespaces parser prettyprint quotations sequences +sequences.generalizations source-files source-files.errors +source-files.errors.debugger splitting stack-checker summary +system tools.errors unicode vocabs vocabs.files vocabs.metadata +vocabs.parser words ; FROM: vocabs.hierarchy => load ; IN: tools.test @@ -238,6 +239,65 @@ SYNTAX: \UNIT-TEST: ] recover ] append! ; +TUPLE: unit-test-failed-section quot ; +CONSTRUCTOR: unit-test-failed-section ( quot -- obj ) ; +SYMBOL: UNIT-TEST-FAILED> +SYNTAX: \ parse-until suffix! ; + +TUPLE: unit-test-code quot ; +CONSTRUCTOR: unit-test-code ( quot -- obj ) ; +SYNTAX: \UNIT-TEST-CODE: scan-object suffix! ; + +TUPLE: got-stack stack ; +CONSTRUCTOR: got-stack ( stack -- obj ) ; +SYNTAX: \GOT-STACK: scan-object suffix! ; + +TUPLE: expected-stack stack ; +CONSTRUCTOR: expected-stack ( stack -- obj ) ; +SYNTAX: \EXPECTED-STACK: scan-object suffix! ; + +TUPLE: got-stdout string ; +CONSTRUCTOR: got-stdout ( string -- obj ) ; +SYNTAX: \GOT-STDOUT: scan-object suffix! ; + +TUPLE: got-stderr string ; +CONSTRUCTOR: got-stderr ( string -- obj ) ; +SYNTAX: \GOT-STDERR: scan-object suffix! ; + +TUPLE: expected-stdout string ; +CONSTRUCTOR: expected-stdout ( string -- obj ) ; +SYNTAX: \EXPECTED-STDOUT: scan-object suffix! ; + +TUPLE: expected-stderr string ; +CONSTRUCTOR: expected-stderr ( string -- obj ) ; +SYNTAX: \EXPECTED-STDERR: scan-object suffix! ; + +TUPLE: named-unit-test name test stack ; +CONSTRUCTOR: named-unit-test ( name test stack -- obj ) ; +SYNTAX: \NAMED-UNIT-TEST: + scan-new-word scan-object scan-object suffix! ; + +TUPLE: stdout-unit-test test string ; +CONSTRUCTOR: stdout-unit-test ( test string -- obj ) ; + +: run-stdout-unit-test ( obj -- ) + [ test>> '[ _ with-string-writer ] call( -- string ) ] + [ string>> ] bi assert-string= ; inline + +SYNTAX: \STDOUT-UNIT-TEST: + scan-object scan-object '[ _ run-stdout-unit-test ] append! ; + +TUPLE: stderr-unit-test test string ; +CONSTRUCTOR: stderr-unit-test ( test string -- obj ) ; + +: run-stderr-unit-test ( obj -- ) + [ test>> '[ _ with-error-string-writer ] call( -- string ) ] + [ string>> ] bi assert-string= ; inline + +SYNTAX: \STDERR-UNIT-TEST: + scan-object scan-object '[ _ run-stderr-unit-test ] append! ; + M: test-failure error. ( error -- ) { [ error-location print nl ] diff --git a/extra/syntax/extras/authors.txt b/extra/syntax/extras/authors.txt new file mode 100644 index 0000000000..7c1b2f2279 --- /dev/null +++ b/extra/syntax/extras/authors.txt @@ -0,0 +1 @@ +Doug Coleman diff --git a/extra/syntax/extras/extras-tests.factor b/extra/syntax/extras/extras-tests.factor new file mode 100644 index 0000000000..89b77ec23d --- /dev/null +++ b/extra/syntax/extras/extras-tests.factor @@ -0,0 +1,11 @@ +! Copyright (C) 2017 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: tools.test syntax.extras ; +IN: syntax.extras.tests + + +CONSTANT: nums2 + +UNIT-TEST: [ nums1 ] { { 1 2 3 } } +UNIT-TEST: [ nums2 ] { { 1 2 3 } } + diff --git a/extra/syntax/extras/extras.factor b/extra/syntax/extras/extras.factor new file mode 100644 index 0000000000..64e7fcfed7 --- /dev/null +++ b/extra/syntax/extras/extras.factor @@ -0,0 +1,22 @@ +! Copyright (C) 2017 Doug Coleman. +! See http://factorcode.org/license.txt for BSD license. +USING: arrays parser sequences vectors words.constant ; +IN: syntax.extras + +SYMBOL: \ARRAY> +SYNTAX: \ parse-until >array suffix! ; + +SYMBOL: \array> +SYNTAX: \ parse-until >array suffix! ; + + +SYMBOL: \;ARRAY> +SYNTAX: \ parse-until >array define-constant ; + +SYMBOL: \VECTOR> +SYNTAX: \ parse-until >vector suffix! ; + +SYMBOL: \;VECTOR> +SYNTAX: \ parse-until >vector define-constant ;