summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Burwell <ben@benburwell.com>2019-09-23 13:38:14 -0400
committerBen Burwell <ben@benburwell.com>2019-09-23 13:38:14 -0400
commit5d3f80f17a10fcfd6b5fd4fb4a2d42afaf7dc789 (patch)
treef779edfdb650c6d36cf5ecb8678a7fee66866e52
parent8f24258d7d284663b5e90719eecfd2b4c44eb632 (diff)
Just use a single custom test flag
-rw-r--r--custom_test.go29
-rw-r--r--testdata/tests.txt7
2 files changed, 20 insertions, 16 deletions
diff --git a/custom_test.go b/custom_test.go
index a8bdfe6..e73d4d7 100644
--- a/custom_test.go
+++ b/custom_test.go
@@ -10,22 +10,20 @@ import (
)
var (
- runCustom bool
- customCases string
+ customTests string
)
func TestMain(m *testing.M) {
- flag.BoolVar(&runCustom, "custom", false, "run custom tests")
- flag.StringVar(&customCases, "custom.cases", "", "input file for custom test cases")
+ flag.StringVar(&customTests, "custom", "", "input file for custom test cases")
flag.Parse()
os.Exit(m.Run())
}
func TestCustom(t *testing.T) {
- if !runCustom {
- t.Skip("skipping custom testing")
+ if customTests == "" {
+ t.Skip("skipping custom tests")
}
- f, err := os.Open(customCases)
+ f, err := os.Open(customTests)
if err != nil {
t.Fatalf("could not open custom test input: %v", err)
}
@@ -37,7 +35,7 @@ func TestCustom(t *testing.T) {
buf := bytes.NewBuffer(data)
for {
// read input
- inp, err := buf.ReadBytes('\t')
+ inp, err := buf.ReadBytes(',')
if err == io.EOF {
return
} else if err != nil {
@@ -47,7 +45,7 @@ func TestCustom(t *testing.T) {
// read expected output
exp, err := buf.ReadBytes('\n')
if err == io.EOF {
- t.Fatalf("found input with no matching output")
+ return
} else if err != nil {
t.Fatalf("read error: %v", err)
}
@@ -56,11 +54,16 @@ func TestCustom(t *testing.T) {
t.Fatalf("malformed input")
}
- result := Encode(string(inp[:len(inp)-2]))
- if result != string(exp[:len(exp)-2]) {
- t.Logf("input: %s", inp)
+ inString := string(inp[:len(inp)-1])
+ expectString := string(exp[:len(exp)-1])
+
+ t.Logf("encoding custom input %q, expecting %q", inString, expectString)
+
+ result := Encode(inString)
+ if result != expectString {
+ t.Logf("input: %s", inString)
t.Logf("output: %s", result)
- t.Logf("expected: %s", exp)
+ t.Logf("expected: %s", expectString)
t.Fail()
}
}
diff --git a/testdata/tests.txt b/testdata/tests.txt
index 49b590e..53defee 100644
--- a/testdata/tests.txt
+++ b/testdata/tests.txt
@@ -1,3 +1,4 @@
-inp lqs
-a d
-Z C
+inp,lqs
+a,d
+Z,C
+AAaa,DDdd