From bdc18d6f9f0a85e4c7ca7956b3bb3dd378c67693 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Thu, 8 Aug 2019 17:32:44 +0200 Subject: [PATCH 1/6] Ignore all stderr messages, which include warnings on word redefinitions --- test/run-tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-tests.py b/test/run-tests.py index 6f77f53..73f9f6e 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -6,7 +6,7 @@ passed, failed, verbose, quiet = 0, 0, 0, 0 def run (forthfile): - return os.popen ("gforth ../ttester-codewars.4th " + forthfile + " -e bye").readlines () + return os.popen ("gforth ../ttester-codewars.4th " + forthfile + " -e bye 2>/dev/null").readlines () def timeless (lines): return [re.sub(r'\d+', '0', l) if "" in l else l for l in lines] From f5ba1170c98aa43187d41ed809983fba1ff7e5be Mon Sep 17 00:00:00 2001 From: nomennescio Date: Thu, 8 Aug 2019 22:36:44 +0200 Subject: [PATCH 2/6] Updated stack comments --- ttester-codewars.4th | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ttester-codewars.4th b/ttester-codewars.4th index 8553ffb..a4c92a5 100644 --- a/ttester-codewars.4th +++ b/ttester-codewars.4th @@ -2,10 +2,10 @@ decimal s" test/ttester.fs" included -: #ms ( dmicroseconds -- len c-addr ) <# # # # [char] . hold #s #> ; +: #ms ( dmicroseconds -- c-addr len ) <# # # # [char] . hold #s #> ; -: describe#{ ( len c-addr -- ) cr ." " type cr utime ; -: it#{ ( len c-addr -- ) cr ." " type cr utime ; +: describe#{ ( c-addr len -- ) cr ." " type cr utime ; +: it#{ ( c-addr len -- ) cr ." " type cr utime ; : }# ( -- ) utime cr ." " 2swap d- #ms type ." ms" cr ; : failed# ( -- ) cr ." " ; @@ -56,4 +56,4 @@ variable ^different 3037000493 constant #m \ prime number < sqrt (2^63-1) 53 constant #p \ prime number : c# { hash pow c -- hash' pow' } c pow * hash + #m mod pow #p * #m mod ; \ polynomial rolling hash function, single char -: s# { c-addr u -- hash } 0 1 c-addr u 0 +do { s } s c@ c# s char+ loop 2drop ; \ string hash \ No newline at end of file +: s# { c-addr len -- hash } 0 1 c-addr len 0 +do { s } s c@ c# s char+ loop 2drop ; \ string hash \ No newline at end of file From e3fb359fae683b56b9ae710c714ea2df8d48cb77 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Thu, 8 Aug 2019 22:37:47 +0200 Subject: [PATCH 3/6] Redefine '->' to handle stack underflow --- ttester-codewars.4th | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ttester-codewars.4th b/ttester-codewars.4th index a4c92a5..78fefce 100644 --- a/ttester-codewars.4th +++ b/ttester-codewars.4th @@ -33,6 +33,13 @@ variable ^different ' different$ ^different ! : <{ T{ ; +: -> depth dup ACTUAL-DEPTH ! + START-DEPTH @ >= if + depth START-DEPTH @ - 0 +do ACTUAL-RESULTS i cells + ! loop + else + START-DEPTH @ depth - -1 +do 0 loop + then + F-> ; : }> depth ACTUAL-DEPTH @ = if depth START-DEPTH @ > if From 201e797444f15892a51a8d6dcf3573b3d5c21e71 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Thu, 8 Aug 2019 22:38:15 +0200 Subject: [PATCH 4/6] Improve error message --- ttester-codewars.4th | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ttester-codewars.4th b/ttester-codewars.4th index 78fefce..3ad39b4 100644 --- a/ttester-codewars.4th +++ b/ttester-codewars.4th @@ -26,7 +26,7 @@ variable ^different RESULTS @ 0 +do ACTUAL-RESULTS i cells + @ . loop cr ; : nresults$ ." Wrong number of results, expected " depth START-DEPTH @ - . - ." , got " ACTUAL-DEPTH @ START-DEPTH @ - . cr ; + ." , got " ACTUAL-DEPTH @ START-DEPTH @ - dup 0< if negate ." a " . ." cell stack underflow" else . then cr ; ' passed$ ^passed ! ' nresults$ ^nresults ! From 7f09d4447ff2088386f51c7a0d2d23c465ca0551 Mon Sep 17 00:00:00 2001 From: nomennescio Date: Thu, 8 Aug 2019 22:38:36 +0200 Subject: [PATCH 5/6] Add stack underflow test --- test/test-stack-underflow.4th | 18 ++++++++++++++++ test/test-stack-underflow.expected | 34 ++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 test/test-stack-underflow.4th create mode 100644 test/test-stack-underflow.expected diff --git a/test/test-stack-underflow.4th b/test/test-stack-underflow.4th new file mode 100644 index 0000000..1b3aa54 --- /dev/null +++ b/test/test-stack-underflow.4th @@ -0,0 +1,18 @@ +\ Copyright 2019 nomennescio +s" stack underflow" describe#{ + s" single test" it#{ + <{ drop -> 0 }> + }# + s" double test" it#{ + <{ drop -> 0 }> + <{ drop drop -> 0 }> + }# + s" double test" it#{ + <{ drop -> 0 0 }> + <{ drop drop -> 0 0 }> + }# + s" double test" it#{ + <{ drop -> 0 0 }> + <{ drop drop -> 0 }> + }# +}# diff --git a/test/test-stack-underflow.expected b/test/test-stack-underflow.expected new file mode 100644 index 0000000..aeab6a5 --- /dev/null +++ b/test/test-stack-underflow.expected @@ -0,0 +1,34 @@ + +stack underflow + +single test + +Wrong number of results, expected 1 , got a 1 cell stack underflow + +0.033 ms + +double test + +Wrong number of results, expected 1 , got a 1 cell stack underflow + +Wrong number of results, expected 1 , got a 2 cell stack underflow + +1565296144893.672 ms + +double test + +Wrong number of results, expected 2 , got a 1 cell stack underflow + +Wrong number of results, expected 2 , got a 2 cell stack underflow + +1565296144893.759 ms + +double test + +Wrong number of results, expected 2 , got a 1 cell stack underflow + +Wrong number of results, expected 1 , got a 2 cell stack underflow + +1565296144893.836 ms + +0.311 ms From 61bd0c9777a39de1b6e5f8bebb4475f9002b956a Mon Sep 17 00:00:00 2001 From: nomennescio Date: Fri, 9 Aug 2019 12:42:08 +0200 Subject: [PATCH 6/6] Filter stderr --- test/run-tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/run-tests.py b/test/run-tests.py index 73f9f6e..ebb8a9b 100755 --- a/test/run-tests.py +++ b/test/run-tests.py @@ -6,7 +6,7 @@ passed, failed, verbose, quiet = 0, 0, 0, 0 def run (forthfile): - return os.popen ("gforth ../ttester-codewars.4th " + forthfile + " -e bye 2>/dev/null").readlines () + return os.popen ("bash -c 'gforth ../ttester-codewars.4th " + forthfile + " -e bye 2> >(sed -E \"s/redefined [^ ]+ //g\" >&2)'").readlines () def timeless (lines): return [re.sub(r'\d+', '0', l) if "" in l else l for l in lines]