From 0c0fce30d964b9de5d44ea2841dd44c81f75c5dc Mon Sep 17 00:00:00 2001 From: Ben Burwell Date: Fri, 20 Sep 2019 17:05:13 -0400 Subject: fuzz -> custom --- custom_test.go | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ fuzz_test.go | 68 ---------------------------------------------------------- 2 files changed, 68 insertions(+), 68 deletions(-) create mode 100644 custom_test.go delete mode 100644 fuzz_test.go diff --git a/custom_test.go b/custom_test.go new file mode 100644 index 0000000..a8bdfe6 --- /dev/null +++ b/custom_test.go @@ -0,0 +1,68 @@ +package caesar + +import ( + "bytes" + "flag" + "io" + "io/ioutil" + "os" + "testing" +) + +var ( + runCustom bool + customCases 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.Parse() + os.Exit(m.Run()) +} + +func TestCustom(t *testing.T) { + if !runCustom { + t.Skip("skipping custom testing") + } + f, err := os.Open(customCases) + if err != nil { + t.Fatalf("could not open custom test input: %v", err) + } + defer f.Close() + data, err := ioutil.ReadAll(f) + if err != nil { + t.Fatalf("could not read custom test input: %v", err) + } + buf := bytes.NewBuffer(data) + for { + // read input + inp, err := buf.ReadBytes('\t') + if err == io.EOF { + return + } else if err != nil { + t.Fatalf("read error: %v", err) + } + + // read expected output + exp, err := buf.ReadBytes('\n') + if err == io.EOF { + t.Fatalf("found input with no matching output") + } else if err != nil { + t.Fatalf("read error: %v", err) + } + + if len(inp) < 2 || len(exp) < 2 { + t.Fatalf("malformed input") + } + + result := Encode(string(inp[:len(inp)-2])) + if result != string(exp[:len(exp)-2]) { + t.Logf("input: %s", inp) + t.Logf("output: %s", result) + t.Logf("expected: %s", exp) + t.Fail() + } + } + Encode(string(data)) +} diff --git a/fuzz_test.go b/fuzz_test.go deleted file mode 100644 index 71fdcb1..0000000 --- a/fuzz_test.go +++ /dev/null @@ -1,68 +0,0 @@ -package caesar - -import ( - "bytes" - "flag" - "io" - "io/ioutil" - "os" - "testing" -) - -var ( - runFuzz bool - fuzzInput string -) - -func TestMain(m *testing.M) { - flag.BoolVar(&runFuzz, "fuzz", false, "run the fuzz tests") - flag.StringVar(&fuzzInput, "fuzz.input", "", "input file for fuzz test") - flag.Parse() - os.Exit(m.Run()) -} - -func TestFuzz(t *testing.T) { - if !runFuzz { - t.Skip("skipping fuzz test") - } - f, err := os.Open(fuzzInput) - if err != nil { - t.Fatalf("could not open fuzz input: %v", err) - } - defer f.Close() - data, err := ioutil.ReadAll(f) - if err != nil { - t.Fatalf("could not read fuzz input: %v", err) - } - buf := bytes.NewBuffer(data) - for { - // read input - inp, err := buf.ReadBytes('\t') - if err == io.EOF { - return - } else if err != nil { - t.Fatalf("read error: %v", err) - } - - // read expected output - exp, err := buf.ReadBytes('\n') - if err == io.EOF { - t.Fatalf("found input with no matching output") - } else if err != nil { - t.Fatalf("read error: %v", err) - } - - if len(inp) < 2 || len(exp) < 2 { - t.Fatalf("malformed input") - } - - result := Encode(string(inp[:len(inp)-2])) - if result != string(exp[:len(exp)-2]) { - t.Logf("input: %s", inp) - t.Logf("output: %s", result) - t.Logf("expected: %s", exp) - t.Fail() - } - } - Encode(string(data)) -} -- cgit v1.2.3