From 66c7cdc2f498704142e90a52ac24f302505c5e48 Mon Sep 17 00:00:00 2001 From: Weilin Shi <934587911@qq.com> Date: Fri, 22 Sep 2017 10:41:09 +0800 Subject: [PATCH] update: do not panic in init function parse fail update: extract test for small image from TestNewCaptcha fix: typo in test --- captcha.go | 6 +----- captcha_test.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/captcha.go b/captcha.go index cbfc396..ce7d7c4 100644 --- a/captcha.go +++ b/captcha.go @@ -71,11 +71,7 @@ func (data *Data) WriteTo(w io.Writer) error { } func init() { - var err error - ttfFont, err = freetype.ParseFont(ttf) - if err != nil { - panic(err) - } + ttfFont, _ = freetype.ParseFont(ttf) } // LoadFont let you load an external font diff --git a/captcha_test.go b/captcha_test.go index eaebc66..5f7383c 100644 --- a/captcha_test.go +++ b/captcha_test.go @@ -8,7 +8,6 @@ import ( ) func TestNewCaptcha(t *testing.T) { - New(36, 12) data, err := New(150, 50) if err != nil { t.Fatal(err) @@ -17,6 +16,13 @@ func TestNewCaptcha(t *testing.T) { data.WriteTo(buf) } +func TestSmallCaptcha(t *testing.T) { + _, err := New(36, 12) + if err != nil { + t.Fatal(err) + } +} + func TestNewCaptchaOptions(t *testing.T) { New(100, 34, func(options *Options) { options.BackgroundColor = color.Opaque @@ -46,6 +52,6 @@ func TestLoadFont(t *testing.T) { err = LoadFont([]byte("invalid")) if err == nil { - t.Fatal("LoadFont incorrecly parse an invalid font") + t.Fatal("LoadFont incorrectly parse an invalid font") } }