This repository was archived by the owner on Nov 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathprolog_test.go
More file actions
74 lines (67 loc) · 1.86 KB
/
Copy pathprolog_test.go
File metadata and controls
74 lines (67 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package golog
// This file runs Go tests for Prolog test files under a 't' directory.
// This gives us an easy way to write many Prolog tests without writing
// a bunch of manual Go tests. Because the tests are written in Prolog
// they can be reused by other Prolog implementations.
import "os"
import "testing"
import "github.com/mndrix/golog/read"
import "github.com/mndrix/golog/term"
import . "github.com/mndrix/golog/util"
func TestPureProlog(t *testing.T) {
// find all t/*.pl files
file, err := os.Open("t")
MaybePanic(err)
names, err := file.Readdirnames(-1)
useModule := read.Term_(`:- use_module(library(tap)).`)
env := term.NewBindings()
// run tests found in each file
for _, name := range names {
if name[0] == '.' {
continue // skip hidden files
}
//t.Logf("-------------- %s", name)
openTest := func() *os.File {
f, err := os.Open("t/" + name)
MaybePanic(err)
return f
}
// which tests does the file have?
pastUseModule := false
tests := make([]term.Term, 0)
terms := read.TermAll_(openTest())
for _, s := range terms {
x := s.(term.Callable)
if pastUseModule {
if x.Arity() == 2 && x.Name() == ":-" {
tests = append(tests, x.Arguments()[0])
} else {
tests = append(tests, x)
}
} else {
// look for use_module(library(tap)) declaration
_, err := s.Unify(env, useModule)
if err == nil {
pastUseModule = true
//t.Logf("found use_module directive")
}
}
}
// run each test in this file
m := NewMachine().Consult(openTest())
for _, test := range tests {
x := test.(term.Callable)
//t.Logf("proving: %s", test)
canProve := m.CanProve(test)
if x.Arity() > 0 && x.Arguments()[0].String() == "fail" {
if canProve {
t.Errorf("%s: %s should fail", name, test)
}
} else {
if !canProve {
t.Errorf("%s: %s failed", name, test)
}
}
}
}
}