eval: Call RunTest from individual test files.

This commit is contained in:
Qi Xiao 2017-12-21 20:49:14 +00:00
parent e70fe7809b
commit 9f73206278
13 changed files with 48 additions and 33 deletions

View File

@ -1,5 +1,7 @@
package eval
func init() {
addToEvalTests([]Test{})
import "testing"
func TestBuiltinFnCmd(t *testing.T) {
RunTests(t, dataDir, []Test{})
}

View File

@ -1,7 +1,9 @@
package eval
func init() {
addToEvalTests([]Test{
import "testing"
func TestBuiltinFnContainer(t *testing.T) {
RunTests(t, dataDir, []Test{
{`range 3`, want{out: strs("0", "1", "2")}},
{`range 1 3`, want{out: strs("1", "2")}},
{`range 0 10 &step=3`, want{out: strs("0", "3", "6", "9")}},

View File

@ -1,7 +1,9 @@
package eval
func init() {
addToEvalTests([]Test{
import "testing"
func TestBuiltinFnFlow(t *testing.T) {
RunTests(t, dataDir, []Test{
{`run-parallel { put lorem } { echo ipsum }`,
want{out: strs("lorem"), bytesOut: []byte("ipsum\n")}},

View File

@ -2,12 +2,12 @@ package eval
import (
"path/filepath"
"testing"
)
var pathSep = string(filepath.Separator)
func init() {
addToEvalTests([]Test{
func TestBuiltinFnFS(t *testing.T) {
pathSep := string(filepath.Separator)
RunTests(t, dataDir, []Test{
{`path-base a/b/c.png`, want{out: strs("c.png")}},
{`tilde-abbr $E:HOME` + pathSep + `foobar`,
want{out: strs("~" + pathSep + "foobar")}},

View File

@ -1,7 +1,9 @@
package eval
func init() {
addToEvalTests([]Test{
import "testing"
func TestBuiltinFnIO(t *testing.T) {
RunTests(t, dataDir, []Test{
{`put foo bar`, want{out: strs("foo", "bar")}},
{`print [foo bar]`, want{bytesOut: []byte("[foo bar]")}},

View File

@ -1,7 +1,9 @@
package eval
func init() {
addToEvalTests([]Test{
import "testing"
func TestBuiltinFnNum(t *testing.T) {
RunTests(t, dataDir, []Test{
{`== 1 1.0`, wantTrue},
{`== 10 0xa`, wantTrue},
{`== a a`, want{err: errAny}},

View File

@ -1,7 +1,9 @@
package eval
func init() {
addToEvalTests([]Test{
import "testing"
func TestBuiltinFnStr(t *testing.T) {
RunTests(t, dataDir, []Test{
{`==s haha haha`, wantTrue},
{`==s 10 10.0`, wantFalse},
{`<s a b`, wantTrue},

View File

@ -1,5 +1,7 @@
package eval
import "testing"
var builtinFnTests = []Test{
{"nop", wantNothing},
{"nop a b", wantNothing},
@ -40,6 +42,6 @@ var builtinFnTests = []Test{
{`(constantly foo) bad`, want{err: errAny}},
}
func init() {
addToEvalTests(builtinFnTests)
func TestBuiltinFn(t *testing.T) {
RunTests(t, dataDir, builtinFnTests)
}

View File

@ -1,5 +1,7 @@
package eval
import "testing"
var builtinSpecialTests = []Test{
// Control structures
// ------------------
@ -62,6 +64,6 @@ var builtinSpecialTests = []Test{
// TODO: Test module namespace
}
func init() {
addToEvalTests(builtinSpecialTests)
func TestBuiltinSpecial(t *testing.T) {
RunTests(t, dataDir, builtinSpecialTests)
}

View File

@ -1,5 +1,7 @@
package eval
import "testing"
var opTests = []Test{
// Chunks
// ------
@ -78,6 +80,6 @@ var opTests = []Test{
want{bytesOut: []byte("haha\n")}},
}
func init() {
addToEvalTests(opTests)
func TestOp(t *testing.T) {
RunTests(t, dataDir, opTests)
}

View File

@ -1,5 +1,7 @@
package eval
import "testing"
var valueTests = []Test{
// Compounding
// -----------
@ -94,6 +96,6 @@ var valueTests = []Test{
{"[a &k=v]{ put $a $k } foo", want{out: strs("foo", "v")}},
}
func init() {
addToEvalTests(valueTests)
func TestValue(t *testing.T) {
RunTests(t, dataDir, valueTests)
}

View File

@ -17,12 +17,7 @@ func TestBuiltinPid(t *testing.T) {
}
}
// To be called from init in separate test files.
func addToEvalTests(tests []Test) {
evalTests = append(evalTests, tests...)
}
var evalTests = []Test{
var miscEvalTests = []Test{
// Pseudo-namespaces local: and up:
{"x=lorem; []{local:x=ipsum; put $up:x $local:x}",
want{out: strs("lorem", "ipsum")}},
@ -33,8 +28,8 @@ var evalTests = []Test{
{"del E:FOO; put $E:FOO", want{out: strs("")}},
}
func TestEval(t *testing.T) {
testEval(t, dataDir, evalTests)
func TestMiscEval(t *testing.T) {
RunTests(t, dataDir, miscEvalTests)
}
func TestMultipleEval(t *testing.T) {

View File

@ -102,7 +102,7 @@ func (t Test) WantAnyErr(err error) Test {
return t
}
func testEval(t *testing.T, dataDir string, evalTests []Test) {
func RunTests(t *testing.T, dataDir string, evalTests []Test) {
for _, tt := range evalTests {
// fmt.Printf("eval %q\n", tt.text)