From c4b6b29db7f8073b1c5adbb67a444b7c0168b858 Mon Sep 17 00:00:00 2001 From: Frederik Vosberg Date: Thu, 27 Jul 2017 21:02:36 +0200 Subject: [PATCH] [PATCH] Remove side effect caused by chdir from test - fixes #23 The TestDotImports changed the directory, so every test afterwards was executed from another directory and calls like New("testpackages/emptyinterface", "") failed. --- pkg/moq/moq_test.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/moq/moq_test.go b/pkg/moq/moq_test.go index a0429b0..ed159b7 100644 --- a/pkg/moq/moq_test.go +++ b/pkg/moq/moq_test.go @@ -196,10 +196,20 @@ func TestVendoredPackages(t *testing.T) { // TestDotImports tests for https://github.com/matryer/moq/issues/21. func TestDotImports(t *testing.T) { - err := os.Chdir("testpackages/dotimport") + preDir, err := os.Getwd() + if err != nil { + t.Errorf("Getwd: %s", err) + } + err = os.Chdir("testpackages/dotimport") if err != nil { t.Errorf("Chdir: %s", err) } + defer func() { + err := os.Chdir(preDir) + if err != nil { + t.Errorf("Chdir back: %s", err) + } + }() m, err := New(".", "moqtest_test") if err != nil { t.Fatalf("moq.New: %s", err)