From a47b35dc44f0e770a1bb1f7b53b6aa11d6895e0b Mon Sep 17 00:00:00 2001 From: Nick White Date: Wed, 26 Feb 2020 16:28:57 +0000 Subject: Fix flag parsing with go test, and switch to -short to gate long tests --- init_test.go | 19 +++++++++++++++++++ sauvola_test.go | 8 ++------ wipesides_test.go | 2 -- 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 init_test.go diff --git a/init_test.go b/init_test.go new file mode 100644 index 0000000..37e510b --- /dev/null +++ b/init_test.go @@ -0,0 +1,19 @@ +// Copyright 2019 Nick White. +// Use of this source code is governed by the GPLv3 +// license that can be found in the LICENSE file. + +package preproc + +import ( + "flag" + "os" + "testing" +) + +var update = flag.Bool("update", false, "update golden files") + +// TestMain is needed to ensure flags are parsed +func TestMain(m *testing.M) { + flag.Parse() + os.Exit(m.Run()) +} diff --git a/sauvola_test.go b/sauvola_test.go index f0433ba..fd5da60 100644 --- a/sauvola_test.go +++ b/sauvola_test.go @@ -5,7 +5,6 @@ package preproc import ( - "flag" "fmt" "image" "image/png" @@ -14,9 +13,6 @@ import ( ) func TestBinarization(t *testing.T) { - var slow = flag.Bool("slow", false, "include slow tests") - var update = flag.Bool("updatesauvola", false, "update golden files") - cases := []struct { name string orig string @@ -43,10 +39,10 @@ func TestBinarization(t *testing.T) { case "integralsauvola": actual = IntegralSauvola(orig, c.ksize, c.wsize) case "sauvola": - if *slow { + if !testing.Short() { actual = Sauvola(orig, c.ksize, c.wsize) } else { - t.Skip("Skipping slow test; use -slow to run it.\n") + t.Skip("Skipping long test due to -short flag.\n") } default: t.Fatalf("No method %s\n", c.name) diff --git a/wipesides_test.go b/wipesides_test.go index ffd60cb..4906c5b 100644 --- a/wipesides_test.go +++ b/wipesides_test.go @@ -8,7 +8,6 @@ package preproc // TODO: test non integral img version import ( - "flag" "fmt" "image" "image/png" @@ -17,7 +16,6 @@ import ( ) func TestWipeSides(t *testing.T) { - var update = flag.Bool("updatewipe", false, "update golden files") cases := []struct { name string orig string -- cgit v1.2.1-24-ge1ad