Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52323b51 authored by Paul Duffin's avatar Paul Duffin
Browse files

Avoid SetErrorHandler mutating FixtureFactory

A FixtureFactory is supposed to be immutable to allow them to be safely
shared but unfortunately the implementation of SetErrorHandler broke
that constraint. That made it very easy to mistakenly add an error
handler specific to a test to a shared factory breaking other tests
that use that factory.

This change causes SetErrorHandler to create a new instance of the
factory to avoid that.

Bug: 181070625
Test: m nothing
Change-Id: Ia5356a04189099c88880a2a521af29ab72560f30
parent d6ceb860
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -182,7 +182,8 @@ type FixtureFactory interface {
	// Create a Fixture.
	Fixture(t *testing.T, preparers ...FixturePreparer) Fixture

	// Set the error handler that will be used to check any errors reported by the test.
	// SetErrorHandler creates a new FixtureFactory that will use the supplied error handler to check
	// the errors (may be 0) reported by the test.
	//
	// The default handlers is FixtureExpectsNoErrors which will fail the go test immediately if any
	// errors are reported.
@@ -578,8 +579,10 @@ func (f *fixtureFactory) Fixture(t *testing.T, preparers ...FixturePreparer) Fix
}

func (f *fixtureFactory) SetErrorHandler(errorHandler FixtureErrorHandler) FixtureFactory {
	f.errorHandler = errorHandler
	return f
	newFactory := &fixtureFactory{}
	*newFactory = *f
	newFactory.errorHandler = errorHandler
	return newFactory
}

func (f *fixtureFactory) RunTest(t *testing.T, preparers ...FixturePreparer) *TestResult {