adjusted some error messages and added the section name in logs

This commit is contained in:
Celestino Amoroso 2024-05-06 04:21:50 +02:00
parent 9c66056c18
commit 903f1ae1ce
3 changed files with 13 additions and 15 deletions

View File

@ -5,7 +5,6 @@
package expr
import (
"fmt"
"strings"
"testing"
)
@ -53,7 +52,7 @@ func TestExpr(t *testing.T) {
ImportOsFuncs(ctx)
parser := NewParser(ctx)
logTest(t, i+1, input.source, input.wantResult, input.wantErr)
logTest(t, i+1, "Expr", input.source, input.wantResult, input.wantErr)
r := strings.NewReader(input.source)
scanner := NewScanner(r, DefaultTranslations())
@ -81,5 +80,5 @@ func TestExpr(t *testing.T) {
failed++
}
}
t.Log(fmt.Sprintf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed))
t.Logf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed)
}

View File

@ -6,7 +6,6 @@ package expr
import (
"errors"
"fmt"
"strings"
"testing"
)
@ -50,7 +49,7 @@ func TestFuncs(t *testing.T) {
// ImportOsFuncs(ctx)
parser := NewParser(ctx)
logTest(t, i+1, input.source, input.wantResult, input.wantErr)
logTest(t, i+1, "Funcs", input.source, input.wantResult, input.wantErr)
r := strings.NewReader(input.source)
scanner := NewScanner(r, DefaultTranslations())
@ -78,5 +77,5 @@ func TestFuncs(t *testing.T) {
failed++
}
}
t.Log(fmt.Sprintf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed))
t.Logf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed)
}

View File

@ -6,7 +6,6 @@ package expr
import (
"errors"
"fmt"
"reflect"
"strings"
"testing"
@ -205,7 +204,7 @@ func TestParser(t *testing.T) {
ImportImportFuncs(ctx)
parser := NewParser(ctx)
logTest(t, i+1, input.source, input.wantResult, input.wantErr)
logTest(t, i+1, "General", input.source, input.wantResult, input.wantErr)
r := strings.NewReader(input.source)
scanner := NewScanner(r, DefaultTranslations())
@ -238,7 +237,7 @@ func TestParser(t *testing.T) {
}
}
}
t.Log(fmt.Sprintf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed))
t.Logf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed)
}
func TestListParser(t *testing.T) {
@ -258,8 +257,9 @@ func TestListParser(t *testing.T) {
/* 7 */ {`add([1,4,3,2])`, int64(10), nil},
/* 8 */ {`add([1,[2,2],3,2])`, int64(10), nil},
/* 9 */ {`mul([1,4,3.0,2])`, float64(24.0), nil},
/* 10 */ {`add([1,"hello"])`, nil, errors.New(`add(): param nr 2 has wrong type string, number expected`)},
/* 10 */ {`add([1,"hello"])`, nil, errors.New(`add(): param nr 2 (2 in 1) has wrong type string, number expected`)},
/* 11 */ {`[a=1,b=2,c=3] but a+b+c`, int64(6), nil},
// /* 8 */ {`[int(x)|x=csv("test.csv",1,all(),1)]`, []any{int64(10), int64(40), int64(20)}, nil},
// /* 9 */ {`sum(@[int(x)|x=csv("test.csv",1,all(),1)])`, []any{int64(10), int64(40), int64(20)}, nil},
}
@ -282,7 +282,7 @@ func TestListParser(t *testing.T) {
ImportMathFuncs(ctx)
parser := NewParser(ctx)
logTest(t, i+1, input.source, input.wantResult, input.wantErr)
logTest(t, i+1, "List", input.source, input.wantResult, input.wantErr)
r := strings.NewReader(input.source)
scanner := NewScanner(r, DefaultTranslations())
@ -334,13 +334,13 @@ func TestListParser(t *testing.T) {
failed++
}
}
t.Log(fmt.Sprintf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed))
t.Logf("test count: %d, succeeded count: %d, failed count: %d", len(inputs), succeeded, failed)
}
func logTest(t *testing.T, n int, source string, wantResult any, wantErr error) {
func logTest(t *testing.T, n int, section, source string, wantResult any, wantErr error) {
if wantErr == nil {
t.Log(fmt.Sprintf("[+]Test nr %3d -- %q --> %v", n, source, wantResult))
t.Logf("[+]%s nr %3d -- %q --> %v", section, n, source, wantResult)
} else {
t.Log(fmt.Sprintf("[-]Test nr %3d -- %q --> %v", n, source, wantErr))
t.Logf("[-]%s nr %3d -- %q --> %v", section, n, source, wantErr)
}
}