]> gitweb.factorcode.org Git - factor.git/commitdiff
tools.test: print the callstack in test failures
authorBjörn Lindqvist <bjourne@gmail.com>
Thu, 3 Dec 2015 11:00:40 +0000 (12:00 +0100)
committerBjörn Lindqvist <bjourne@gmail.com>
Fri, 4 Dec 2015 15:57:40 +0000 (16:57 +0100)
So when mason reports a test failure it should include the whole
callstack. That should make it easier to catch the "No suitable
arithmetic method" random error that is hard to debug without a
callstack.

basis/debugger/debugger-tests.factor
basis/tools/test/test-tests.factor
basis/tools/test/test.factor

index 241b40913a9ba377822ddf28e76b9128e85fcc6e..52b5f559ba3d4fcbdd2541265b93485fbf886c6e 100644 (file)
@@ -1,4 +1,4 @@
-USING: accessors alien.syntax continuations debugger kernel
+USING: accessors alien.syntax continuations debugger kernel literals
 namespaces tools.test ;
 IN: debugger.tests
 
@@ -8,36 +8,36 @@ IN: debugger.tests
 { f } [ { "A" "B" } vm-error? ] unit-test
 
 { } [
-T{ test-failure
-    { error
-        {
-            "kernel-error"
-            10
-            {
-                B{
-                    88 73 110 112 117 116 69 110 97 98 108 101 0
-                }
-                B{
-                    88 73 110 112 117 116 69 110 97 98 108 101
-                    64 56 0
-                }
-                B{
-                    95 88 73 110 112 117 116 69 110 97 98 108
-                    101 64 56 0
-                }
-                B{
-                    64 88 73 110 112 117 116 69 110 97 98 108
-                    101 64 56 0
-                }
-            }
-            DLL" xinput1_3.dll"
-        }
-    }
-    { asset { "Unit Test" [ ] [ dup ] } }
-    { path "resource:basis/game/input/input-tests.factor" }
-    { line# 6 }
-    { continuation f }
-} error.
+    T{ test-failure
+       { error
+         {
+             "kernel-error"
+             10
+             {
+                 B{
+                     88 73 110 112 117 116 69 110 97 98 108 101 0
+                 }
+                 B{
+                     88 73 110 112 117 116 69 110 97 98 108 101
+                     64 56 0
+                 }
+                 B{
+                     95 88 73 110 112 117 116 69 110 97 98 108
+                     101 64 56 0
+                 }
+                 B{
+                     64 88 73 110 112 117 116 69 110 97 98 108
+                     101 64 56 0
+                 }
+             }
+             DLL" xinput1_3.dll"
+         }
+       }
+       { asset { "Unit Test" [ ] [ dup ] } }
+       { path "resource:basis/game/input/input-tests.factor" }
+       { line# 6 }
+       { continuation $[ current-continuation ] }
+    } error.
 ] unit-test
 
 { "foo" { 1 2 3 "foo" } } [
index 8ce7bf0631e82497870d57880ea34a328f61168e..fd51d8af8be899ca14e9d2301f7bb10328112995 100644 (file)
@@ -1,8 +1,20 @@
 IN: tools.test.tests
-USING: tools.test tools.test.private namespaces kernel sequences ;
+USING: continuations debugger io.streams.string kernel namespaces
+sequences tools.test tools.test.private ;
 
 { 1 } [
     [
         [ "OOPS" ] must-fail
     ] fake-unit-test length
 ] unit-test
+
+: create-test-failure ( -- error )
+    [ "hello" throw ] [
+        f "path" 25 error-continuation get test-failure boa
+    ] recover ;
+
+! Just verifies that the presented output contains a callstack.
+{ t } [
+    create-test-failure [ error. ] with-string-writer
+    "OBJ-CURRENT-THREAD" swap subseq?
+] unit-test
index 5ae7848d19a65ba1a9b679b6e3a6d06d023b8867..9f9c84dfe0a4382c37a6cd314c8031a10475251a 100644 (file)
@@ -161,7 +161,7 @@ M: test-failure error. ( error -- )
         [ error-location print nl ]
         [ asset>> [ experiment. nl ] when* ]
         [ error>> error. ]
-        [ continuation>> traceback-link. ]
+        [ continuation>> call>> callstack. ]
     } cleave ;
 
 : :test-failures ( -- ) test-failures get errors. ;