dati

data and template interface
git clone git://git.gearsix.net/dati
Log | Files | Refs | Atom | README | LICENSE

commit 638dd77b2d8a40a5f86b95c62011b7ca52de6dfe
parent 606a9b864c321d22c35580287e6f4b7c803b12bd
Author: GeaRSiX <gearsix@tuta.io>
Date:   Thu,  3 Jun 2021 13:54:34 +0100

minor fix to print in data.go; Error->Fatal in *_test.go files

Diffstat:
Mdata.go | 2+-
Mdata_test.go | 16++++++++--------
Mfile_test.go | 16++++++++--------
Mtemplate_test.go | 16++++++++--------
4 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/data.go b/data.go @@ -61,7 +61,7 @@ func LoadDataFile(path string, outp interface{}) error { if e == nil { lang := filepath.Ext(path)[1:] // don't include '.' if e = LoadData(lang, f, outp); e != nil { - e = fmt.Errorf("failed to load data '%s': %s", e.Error()) + e = fmt.Errorf("failed to load data '%s': %s", path, e.Error()) } } diff --git a/data_test.go b/data_test.go @@ -54,7 +54,7 @@ func validateData(t *testing.T, d interface{}, e error, lang string) { var b []byte if e != nil { - t.Error(e) + t.Fatal(e) } switch lang { @@ -70,7 +70,7 @@ func validateData(t *testing.T, d interface{}, e error, lang string) { t.Error(e) } if string(b) != good[lang] { - t.Errorf("incorrect %s: %s does not match %s", lang, b, good[lang]) + t.Fatalf("incorrect %s: %s does not match %s", lang, b, good[lang]) } } @@ -84,13 +84,13 @@ func TestLoadData(t *testing.T) { } if e = LoadData("json", strings.NewReader(badData), &d); e == nil { - t.Errorf("bad data passed") + t.Fatalf("bad data passed") } if e = LoadData("toml", strings.NewReader(""), &d); e != nil { - t.Errorf("empty data failed %s, %s", d, e) + t.Fatalf("empty data failed %s, %s", d, e) } if e = LoadData("void", strings.NewReader("shouldn't pass"), &d); e == nil { - t.Errorf("invalid data language passed: %s, %s", d, e) + t.Fatalf("invalid data language passed: %s, %s", d, e) } return @@ -113,18 +113,18 @@ func TestLoadDataFile(t *testing.T) { writeTestFile(t, p, badData) e = LoadDataFile(p, &d) if e == nil { - t.Errorf("bad data passed") + t.Fatalf("bad data passed") } p = tdir + "/empty.json" writeTestFile(t, p, "") e = LoadDataFile(p, &d) if e != nil { - t.Errorf("empty file failed: %s", e) + t.Fatalf("empty file failed: %s", e) } if e = LoadDataFile("non-existing-file.toml", &d); e == nil { - t.Errorf("non-existing file passed: %s, %s", d, e) + t.Fatalf("non-existing file passed: %s, %s", d, e) } return diff --git a/file_test.go b/file_test.go @@ -16,22 +16,22 @@ func TestSortFileList(t *testing.T) { sorted, err = SortFileList(paths, "filename") if err != nil { - t.Error(err) + t.Fatal(err) } for i, p := range sorted { if filepath.Base(p) != strconv.Itoa(i+1) { - t.Errorf("invalid order returned sorted[%d] is %s", i, p) + t.Fatalf("invalid order returned sorted[%d] is %s", i, p) } } sorted, err = SortFileList(paths, "filename-desc") if err != nil { - t.Error(err) + t.Fatal(err) } j := 3 for i := 0; i < len(sorted); i++ { if filepath.Base(sorted[i]) != strconv.Itoa(j) { - t.Errorf("invalid order returned sorted[%d] is %s", i, sorted[i]) + t.Fatalf("invalid order returned sorted[%d] is %s", i, sorted[i]) } j-- } @@ -47,22 +47,22 @@ func TestSortFileList(t *testing.T) { sorted, err = SortFileList(paths, "modified") if err != nil { - t.Error(err) + t.Fatal(err) } for i := range paths { if sorted[i] != paths[i] { - t.Errorf("invalid order returned %s - %s", sorted, paths) + t.Fataf("invalid order returned %s - %s", sorted, paths) } } sorted, err = SortFileList(paths, "modified-desc") if err != nil { - t.Error(err) + t.Fatal(err) } j = 2 for i := 0; i < len(paths); i++ { if sorted[i] != paths[j] { - t.Errorf("invalid order returned %s - %s", sorted, paths) + t.Fatalf("invalid order returned %s - %s", sorted, paths) } j-- } diff --git a/template_test.go b/template_test.go @@ -55,7 +55,7 @@ func validateTemplateFile(t *testing.T, template Template, root string, partials ttype := getTemplateType(root) if reflect.TypeOf(template.Template).String() != types[ttype] { - t.Error("invalid template loaded") + t.Fatal("invalid template loaded") } if types[ttype] == "*template.Template" { @@ -66,14 +66,14 @@ func validateTemplateFile(t *testing.T, template Template, root string, partials reflect.ValueOf(p), }) if rv[0].IsNil() { - t.Errorf("missing defined template '%s'", p) + t.Fatalf("missing defined template '%s'", p) rv = reflect.ValueOf(template.Template).MethodByName("DefinedTemplates").Call([]reflect.Value{}) t.Log(rv) } } rv = reflect.ValueOf(template.Template).MethodByName("Name").Call([]reflect.Value{}) if rv[0].String() != filepath.Base(root) { - t.Errorf("invalid template name: %s does not match %s", + t.Fatalf("invalid template name: %s does not match %s", rv[0].String(), filepath.Base(root)) } } @@ -115,28 +115,28 @@ func TestLoadTemplateFile(t *testing.T) { for g, root := range gr { // good root, good partials if template, e := LoadTemplateFile(root, gp[g]); e != nil { - t.Error(e) + t.Fatal(e) } else { validateTemplateFile(t, template, root, gp[g]) } } for _, root := range br { // bad root, good partials if _, e := LoadTemplateFile(root, gp...); e == nil { - t.Errorf("no error for bad template with good partials\n") + t.Fatalf("no error for bad template with good partials\n") } } for _, root := range br { // bad root, bad partials if _, e := LoadTemplateFile(root, bp...); e == nil { - t.Errorf("no error for bad template with bad partials\n") + t.Fatalf("no error for bad template with bad partials\n") } } } func validateExecute(t *testing.T, results string, expect string, e error) { if e != nil { - t.Error(e) + t.Fatal(e) } else if results != expect { - t.Errorf("invalid results: '%s' should match '%s'", results, expect) + t.Fatalf("invalid results: '%s' should match '%s'", results, expect) } }