From 5d3f80f17a10fcfd6b5fd4fb4a2d42afaf7dc789 Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Mon, 23 Sep 2019 13:38:14 -0400 Subject: Just use a single custom test flag --- custom_test.go | 29 ++++++++++++++++------------- testdata/tests.txt | 7 ++++--- 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 -- cgit v1.2.3