Skip to content

Commit ad387d3

Browse files
committed
Fix fenced code in Forth.
1 parent 7e4a867 commit ad387d3

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

testing-with-tap/forth.md

+36-36
Original file line numberDiff line numberDiff line change
@@ -25,61 +25,61 @@ You may not be familiar with [Forth](https://en.wikipedia.org/wiki/Forth_(progra
2525
It's recommended that whenever possible your TAP should start with a plan. The plan says how many tests are expected to run and looks like this:
2626

2727
```
28-
1..10
28+
1..10
2929
```
3030

3131
The plan always takes the form 1..*number* of tests.
3232
In Forth we can output a plan like this:
3333

3434
```
35-
." 1..10" cr
35+
." 1..10" cr
3636
```
3737

3838
Or you can define the word plan like this:
3939

4040
```
41-
: plan ( n -- )
42-
." 1.." . cr
43-
;
41+
: plan ( n -- )
42+
." 1.." . cr
43+
;
4444
```
4545

4646
and use it like this:
4747

4848
```
49-
10 plan
49+
10 plan
5050
```
5151

5252
### Test results
5353

5454
The general form of a test result is either
5555

5656
```
57-
ok test-number description
57+
ok test-number description
5858
```
5959

6060
or
6161

6262
```
63-
not ok test-number description
63+
not ok test-number description
6464
```
6565

6666
The description is optional so we'll omit it for now and concentrate on generating results that a TAP parser can process.
6767
We need a variable to hold the number of the next test. In Forth that looks like this:
6868

6969
```
70-
Variable test#
71-
0 test# !
70+
Variable test#
71+
0 test# !
7272
```
7373

7474
And we need something to output the result:
7575

7676
```
77-
: ok ( f -- )
78-
0= if ." not " then
79-
." ok "
80-
test# dup @ 1+ dup . swap !
81-
cr
82-
;
77+
: ok ( f -- )
78+
0= if ." not " then
79+
." ok "
80+
test# dup @ 1+ dup . swap !
81+
cr
82+
;
8383
```
8484

8585
Now we have a word called ok which checks the top value on the stack and outputs 'ok' or 'not ok' depending on whether it's true (non-zero) or false (zero). With that we have everything necessary to start TAP based testing.
@@ -90,37 +90,37 @@ Now we have a word called ok which checks the top value on the stack and outputs
9090
Here's a simple test of addition and subtraction using the words we just defined:
9191

9292
```
93-
#! /usr/local/bin/gforth
94-
95-
require tap.fs
96-
97-
2 plan
98-
1 1 + 2 = ok
99-
2 1 - 1 = ok
100-
101-
bye
93+
#! /usr/local/bin/gforth
94+
95+
require tap.fs
96+
97+
2 plan
98+
1 1 + 2 = ok
99+
2 1 - 1 = ok
100+
101+
bye
102102
```
103103

104104
It assumes that we saved our TAP generating code in a file called tap.fs. When run it will output
105105

106106
```
107-
1..2
108-
ok 1
109-
ok 2
107+
1..2
108+
ok 1
109+
ok 2
110110
```
111111

112112
### Analysing the results
113113

114114
If you have the Perl prove utility (which is part of [Test::Harness](http://search.cpan.org/dist/Test-Harness/) you can use it to run this test script and analyse the results:
115115

116116
```
117-
$ prove -v simple.fs
118-
t/simple...1..2
119-
ok 1
120-
ok 2
121-
ok
122-
All tests successful.
123-
Files=1, Tests=2, 0 wallclock secs ( 0.01 cusr + 0.02 csys = 0.03 CPU)
117+
$ prove -v simple.fs
118+
t/simple...1..2
119+
ok 1
120+
ok 2
121+
ok
122+
All tests successful.
123+
Files=1, Tests=2, 0 wallclock secs ( 0.01 cusr + 0.02 csys = 0.03 CPU)
124124
```
125125

126126
#### Get the code
@@ -129,4 +129,4 @@ Here's a slightly extended version of the code in this article:
129129

130130
[forth-tap-0.0.1.tar.gz](/assets/forth-tap-0.0.1.tar.gz)
131131

132-
You'll need [GNU Forth](http://www.gnu.org/software/gforth) and Perl installed to run it.
132+
You'll need [GNU Forth](http://www.gnu.org/software/gforth) and Perl installed to run it.

0 commit comments

Comments
 (0)