From 95644cab17b69efffe8dd8983827a063d9d336c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Jime=CC=81nez?= Date: Sun, 1 Nov 2015 15:12:29 +0000 Subject: [PATCH] Fixes issue #149 --- suite/suite.go | 1 + suite/suite_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/suite/suite.go b/suite/suite.go index ac6744d..f831e25 100644 --- a/suite/suite.go +++ b/suite/suite.go @@ -31,6 +31,7 @@ func (suite *Suite) T() *testing.T { func (suite *Suite) SetT(t *testing.T) { suite.t = t suite.Assertions = assert.New(t) + suite.require = require.New(t) } // Require returns a require context for suite. diff --git a/suite/suite_test.go b/suite/suite_test.go index 6a1bb2c..c7c4e88 100644 --- a/suite/suite_test.go +++ b/suite/suite_test.go @@ -9,6 +9,37 @@ import ( "github.com/stretchr/testify/assert" ) +// SuiteRequireTwice is intended to test the usage of suite.Require in two +// different tests +type SuiteRequireTwice struct{ Suite } + +// TestSuiteRequireTwice checks for regressions of issue #149 where +// suite.requirements was not initialised in suite.SetT() +// A regression would result on these tests panicking rather than failing. +func TestSuiteRequireTwice(t *testing.T) { + ok := testing.RunTests( + func(_, _ string) (bool, error) { return true, nil }, + []testing.InternalTest{{ + Name: "TestSuiteRequireTwice", + F: func(t *testing.T) { + suite := new(SuiteRequireTwice) + Run(t, suite) + }, + }}, + ) + assert.Equal(t, false, ok) +} + +func (s *SuiteRequireTwice) TestRequireOne() { + r := s.Require() + r.Equal(1, 2) +} + +func (s *SuiteRequireTwice) TestRequireTwo() { + r := s.Require() + r.Equal(1, 2) +} + // This suite is intended to store values to make sure that only // testing-suite-related methods are run. It's also a fully // functional example of a testing suite, using setup/teardown methods