Skip to content

Commit 462e533

Browse files
committed
Add Cram tests
1 parent 49a6fec commit 462e533

File tree

7 files changed

+158
-7
lines changed

7 files changed

+158
-7
lines changed

dune-project

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
(name stellogen)
2020
(synopsis "Stellogen is a minimalistic and logic-agnostic programming
2121
language based on term unification.")
22-
(depends base menhir (alcotest :with-test) sedlex ppx_deriving)
22+
(depends base menhir sedlex ppx_deriving)
2323
(tags
2424
("transcendental syntax" "logic programming" "constraint programming" "resolution logic" "unification" "self-assembly")))
2525

stellogen.opam

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ depends: [
2121
"dune" {>= "3.7"}
2222
"base"
2323
"menhir"
24-
"alcotest" {with-test}
2524
"sedlex"
2625
"ppx_deriving"
2726
"odoc" {with-doc}

test/README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Stellogen Tests
2+
3+
This directory contains Cram tests for Stellogen.
4+
5+
## Test Files
6+
7+
- `subjects.t` - Tests for basic syntax subjects in `test/subjects/`
8+
- `examples.t` - Tests for all examples in `examples/`
9+
10+
## Running Tests
11+
12+
Run all tests:
13+
```bash
14+
dune test
15+
```
16+
17+
Run tests and update expected outputs:
18+
```bash
19+
dune test --auto-promote
20+
```
21+
22+
Run specific test file:
23+
```bash
24+
dune test test/examples.t
25+
```
26+
27+
## About Cram Tests
28+
29+
Cram tests are simple text-based tests that show shell commands and their expected outputs:
30+
31+
```
32+
$ command
33+
expected output
34+
```
35+
36+
When a test runs successfully without any expected output specified, it just verifies the command exits successfully (exit code 0).
37+
38+
## Adding New Tests
39+
40+
To add a new test:
41+
42+
1. Create a `.t` file in this directory
43+
2. Write commands starting with ` $ ` (two spaces, dollar sign, space)
44+
3. Run `dune test --auto-promote` to capture the output
45+
4. Review the promoted output and commit
46+
47+
## Modifying Test Dependencies
48+
49+
Test dependencies are declared in `test/dune`. If you add new test fixtures, add them to the `deps` section.

test/dune

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
(test
2-
(name test)
3-
(modules test)
1+
; Cram tests for Stellogen examples and subjects
2+
(cram
43
(deps
54
(glob_files ./subjects/*.sg)
65
(glob_files ../examples/*.sg)
7-
(glob_files ../exercises/solutions/*.sg))
8-
(libraries alcotest base stellogen))
6+
(glob_files ../exercises/solutions/*.sg)
7+
(package stellogen)))
98

109
(env
1110
(dev

test/examples.t

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
Test examples directory
2+
========================
3+
4+
Automata example:
5+
$ sgen run ../examples/automata.sg
6+
{}
7+
accept
8+
{}
9+
{}
10+
11+
Binary4 example:
12+
$ sgen run ../examples/binary4.sg
13+
{ [(+b b1 4 1)] [(+b b1 3 0)] [(+b b1 2 0)] [(+b b1 1 0)] }
14+
{ [(+b b2 4 1)] [(+b b2 3 1)] [(+b b2 2 0)] [(+b b2 1 0)] }
15+
{ [(+b r 4 1)] [(+b r 3 0)] [(+b r 2 0)] [(+b r 1 0)] }
16+
{ [(+b r 4 1)] [(+b r 3 1)] [(+b r 2 0)] [(+b r 1 0)] }
17+
{ [(+b r 4 0)] [(+b r 3 1)] [(+b r 2 1)] [(+b r 1 1)] }
18+
{ [(+b r2 4 0)] [(+b r2 3 1)] [(+b r2 2 1)] [(+b r2 1 1)] }
19+
20+
Circuits example:
21+
$ sgen run ../examples/circuits.sg
22+
{ [(-c3 0) (-1 0) (-c2 0) (-not 0 0) 0 0] [(-c3 0) (-c2 1) 0 0] }
23+
{ [(-0 1)] [(-not 0 0)] }
24+
25+
Lambda calculus example:
26+
$ sgen run ../examples/lambda.sg
27+
[(out (%cons r X7)) (ida (exp (%cons l X7) d))]
28+
[(out X7) (x (exp X7 d))]
29+
30+
Linear lambda example:
31+
$ sgen run ../examples/linear_lambda.sg
32+
{}
33+
{}
34+
35+
MALL (multiplicative-additive linear logic) example:
36+
$ sgen run ../examples/mall.sg
37+
{ [(-3 (%cons r (%cons l X4))) (-3 (%cons r (%cons r X4))) || (slice c b)] [(c X11) (d X11) || (slice c a)] }
38+
39+
MLL (multiplicative linear logic) example:
40+
$ sgen run ../examples/mll.sg
41+
{}
42+
43+
Natural numbers example:
44+
$ sgen run ../examples/nat.sg
45+
(+nat (s (s (s 0))))
46+
(res 1)
47+
(res 0)
48+
49+
NPDA (non-deterministic pushdown automaton) example:
50+
$ sgen run ../examples/npda.sg
51+
{ [accept] [accept] }
52+
accept
53+
accept
54+
{}
55+
56+
Prolog-style examples:
57+
$ sgen run ../examples/prolog.sg
58+
(s (s (s (s 0))))
59+
[(-grandparent tom Z0) Z0]
60+
{ [ok (-to 1)] [(-from 5)] [(-from 4)] [(-from 5)] }
61+
62+
Stack example:
63+
$ sgen run ../examples/stack.sg
64+
(save 0)
65+
66+
Sum types example:
67+
$ sgen run ../examples/sumtypes.sg
68+
a
69+
70+
Syntax reference:
71+
$ sgen run ../examples/syntax.sg
72+
a
73+
{ [c] [b] [a] }
74+
(%string hello world)
75+
(function a b)
76+
{ [(-f X0) (-f Y0) (r X0 Y0) || (!= X Y)] [(+f b)] [(+f a)] }
77+
{ [(r b a) || (!= b a)] [(r a b) || (!= a b)] }
78+
(+n2 (s (s 0)))
79+
{ [(+field test2) (%cons (+f b) (%cons ok %nil))] [(+field test1) (%cons (+f a) (%cons ok %nil))] }
80+
[(+f a) ok]
81+
[(+f b) ok]
82+
(-field test2)
83+
84+
Turing machine example:
85+
$ sgen run ../examples/turing.sg
86+
reject
87+
reject
88+
reject
89+
accept
90+
accept
91+
accept
92+
accept
93+
accept

test/subjects.t

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Test subjects - basic syntax tests
2+
=====================================
3+
4+
Linear execution test:
5+
$ sgen run subjects/linear.sg
6+
7+
Prolog-style test:
8+
$ sgen run subjects/prolog.sg
9+
10+
Records test:
11+
$ sgen run subjects/records.sg
File renamed without changes.

0 commit comments

Comments
 (0)