From 544b5426f4e03bcc4bc30e85a876848e6cf8871c Mon Sep 17 00:00:00 2001 From: Arran Ubels Date: Wed, 15 Feb 2023 16:20:46 +1100 Subject: [PATCH] Test improvements.. I think --- parseany_test.go | 51 +++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/parseany_test.go b/parseany_test.go index e4f9de9..7582465 100644 --- a/parseany_test.go +++ b/parseany_test.go @@ -10,7 +10,7 @@ import ( func TestOne(t *testing.T) { time.Local = time.UTC - var ts time.Time = MustParse("2020-07-20+08:00") + var ts = MustParse("2020-07-20+08:00") assert.Equal(t, "2020-07-19 16:00:00 +0000 UTC", fmt.Sprintf("%v", ts.In(time.UTC))) } @@ -435,28 +435,35 @@ func TestParse(t *testing.T) { assert.NotEqual(t, nil, err) for _, th := range testInputs { - if len(th.loc) > 0 { - loc, err := time.LoadLocation(th.loc) - if err != nil { - t.Fatalf("Expected to load location %q but got %v", th.loc, err) + t.Run(th.in, func(t *testing.T) { + defer func() { + if r := recover(); r != nil { + t.Fatalf("error: %s", r) + } + }() + if len(th.loc) > 0 { + loc, err := time.LoadLocation(th.loc) + if err != nil { + t.Fatalf("Expected to load location %q but got %v", th.loc, err) + } + ts, err = ParseIn(th.in, loc) + if err != nil { + t.Fatalf("expected to parse %q but got %v", th.in, err) + } + got := fmt.Sprintf("%v", ts.In(time.UTC)) + assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in) + if th.out != got { + t.Fatalf("whoops, got %s, expected %s", got, th.out) + } + } else { + ts = MustParse(th.in) + got := fmt.Sprintf("%v", ts.In(time.UTC)) + assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in) + if th.out != got { + t.Fatalf("whoops, got %s, expected %s", got, th.out) + } } - ts, err = ParseIn(th.in, loc) - if err != nil { - t.Fatalf("expected to parse %q but got %v", th.in, err) - } - got := fmt.Sprintf("%v", ts.In(time.UTC)) - assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in) - if th.out != got { - panic("whoops") - } - } else { - ts = MustParse(th.in) - got := fmt.Sprintf("%v", ts.In(time.UTC)) - assert.Equal(t, th.out, got, "Expected %q but got %q from %q", th.out, got, th.in) - if th.out != got { - panic("whoops") - } - } + }) } // some errors