Skip to content

Commit 6e10e94

Browse files
committed
Simple tests to verify test framework
1 parent 5d21825 commit 6e10e94

File tree

8 files changed

+64
-0
lines changed

8 files changed

+64
-0
lines changed

test/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Simple tests to verify the Forth test framework is still working
2+
3+
Run all tests by executing
4+
run-tests.py

test/run-tests.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
# Copyright 2019 nomennescio
3+
# MIT license
4+
5+
import glob, os, re
6+
7+
passed, failed = 0, 0
8+
9+
def run (forthfile):
10+
return os.popen ("gforth ../ttester-codewars.4th " + forthfile + " -e bye").readlines ()
11+
12+
def timeless (lines):
13+
return [re.sub(r'\d+', '0', l) if "<COMPLETEDIN::>" in l else l for l in lines]
14+
15+
def test (base):
16+
global passed, failed
17+
if (timeless (run (base + ".4th")) == timeless (open (base + ".expected").readlines ())):
18+
print ("Pass: " + base)
19+
passed += 1
20+
else:
21+
print ("Fail: " + base)
22+
failed += 1
23+
24+
prevdir = os.getcwd ()
25+
os.chdir (os.path.dirname (os.path.abspath (__file__)))
26+
27+
files = [os.path.splitext (f) for f in glob.glob ("*.4th")]
28+
for f,_ in files:
29+
test (f)
30+
31+
if (failed==0):
32+
print ("All {0} tests were successful".format (passed))
33+
else:
34+
print ("{0} out of {1} tests failed".format (failed, failed+passed))
35+
36+
os.chdir (prevdir)

test/test-describe.4th

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
\ Copyright 2019 nomennescio
2+
s" group of tests" describe#{
3+
s" single test" it#{
4+
<{ 0 -> 0 }>
5+
}#
6+
}#

test/test-describe.expected

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
<DESCRIBE::>group of tests
3+
4+
<IT::>single test
5+
6+
<PASSED::>Test Passed
7+
8+
<COMPLETEDIN::>0.021 ms
9+
10+
<COMPLETEDIN::>0.038 ms

test/test-fail.4th

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
\ Copyright 2019 nomennescio
2+
<{ 0 -> 1 }>

test/test-fail.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
<FAILED::>Expected 1 , got 0

test/test-pass.4th

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
\ Copyright 2019 nomennescio
2+
<{ 0 -> 0 }>

test/test-pass.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
<PASSED::>Test Passed

0 commit comments

Comments
 (0)