Skip to content

Commit

Permalink
update build tests
Browse files Browse the repository at this point in the history
Remove io/ioutil references.
Separate ok tests from err tests.
  • Loading branch information
efreitasn committed Jan 16, 2024
1 parent 1bf7f64 commit dca79ed
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package egen
import (
"fmt"
"html/template"
"io/ioutil"
"io"
"os"
"path"
"reflect"
Expand Down Expand Up @@ -33,12 +33,10 @@ func TestBuild_ok(t *testing.T) {
latexGenerator = &latexTestGenerator{}

okDir := path.Join("testdata", "build", "ok")
errDir := path.Join("testdata", "build", "err")

tests := []struct {
bc BuildConfig
nonNilErr bool
expected string
bc BuildConfig
expected string
}{
{
BuildConfig{
Expand All @@ -57,7 +55,6 @@ func TestBuild_ok(t *testing.T) {
},
},
},
false,
path.Join(okDir, "1", "out"),
},
{
Expand All @@ -77,17 +74,39 @@ func TestBuild_ok(t *testing.T) {
},
},
},
false,
path.Join(okDir, "2", "out"),
},
{
BuildConfig{
InPath: path.Join(okDir, "3", "in"),
OutPath: path.Join(okDir, "3", "test_output"),
},
false,
path.Join(okDir, "3", "out"),
},
}

for _, test := range tests {
t.Run(test.bc.InPath, func(t *testing.T) {
err := Build(test.bc)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
// defer os.RemoveAll(buildOutPath)

compareDirsRec(t, test.expected, test.bc.OutPath)
})
}
}

func TestBuild_err(t *testing.T) {
latexGenerator = &latexTestGenerator{}

errDir := path.Join("testdata", "build", "err")

tests := []struct {
bc BuildConfig
expected string
}{
{
BuildConfig{
InPath: path.Join(errDir, "1", "in"),
Expand All @@ -105,7 +124,6 @@ func TestBuild_ok(t *testing.T) {
},
},
},
true,
path.Join(errDir, "1", "out"),
},
{
Expand All @@ -125,7 +143,6 @@ func TestBuild_ok(t *testing.T) {
},
},
},
true,
path.Join(errDir, "2", "out"),
},
{
Expand All @@ -145,7 +162,6 @@ func TestBuild_ok(t *testing.T) {
},
},
},
true,
path.Join(errDir, "3", "out"),
},
{
Expand All @@ -165,26 +181,16 @@ func TestBuild_ok(t *testing.T) {
},
},
},
true,
path.Join(errDir, "4", "out"),
},
}

for _, test := range tests {
t.Run(test.bc.InPath, func(t *testing.T) {
err := Build(test.bc)
if test.nonNilErr {
if err == nil {
t.Fatal("expected an error")
}

return
} else if err != nil {
t.Fatalf("unexpected err: %v", err)
if err == nil {
t.Fatal("expected an error")
}
// defer os.RemoveAll(buildOutPath)

compareDirsRec(t, test.expected, test.bc.OutPath)
})
}
}
Expand Down Expand Up @@ -237,7 +243,7 @@ func compareDirsRec(t *testing.T, a, b string) {
t.Fatalf("unexpected err: %v", err)
}

aFileDirContentBs, err := ioutil.ReadAll(aFileDir)
aFileDirContentBs, err := io.ReadAll(aFileDir)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
Expand All @@ -247,7 +253,7 @@ func compareDirsRec(t *testing.T, a, b string) {
t.Fatalf("unexpected err: %v", err)
}

bFileDirContentBs, err := ioutil.ReadAll(bFileDir)
bFileDirContentBs, err := io.ReadAll(bFileDir)
if err != nil {
t.Fatalf("unexpected err: %v", err)
}
Expand Down

0 comments on commit dca79ed

Please sign in to comment.