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 package eval
func init() { import "testing"
addToEvalTests([]Test{})
func TestBuiltinFnCmd(t *testing.T) {
RunTests(t, dataDir, []Test{})
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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