From b3d854de9f22e8090c3c4ce762652ea7a5f2958f Mon Sep 17 00:00:00 2001 From: Markus Zimmermann Date: Mon, 29 Dec 2014 13:48:48 +0100 Subject: [PATCH] make mutator testing a little bit simpler --- mutator/branch/mutateelse_test.go | 1 - mutator/branch/mutateif_test.go | 1 - mutator/expression/remove_test.go | 1 - test/mutator.go | 6 +++--- testdata/{test.go => branch/mutateelse.go} | 0 testdata/branch/mutateif.go | 23 ++++++++++++++++++++++ 6 files changed, 26 insertions(+), 6 deletions(-) rename testdata/{test.go => branch/mutateelse.go} (100%) create mode 100644 testdata/branch/mutateif.go diff --git a/mutator/branch/mutateelse_test.go b/mutator/branch/mutateelse_test.go index 3a31ad5..4290b7f 100644 --- a/mutator/branch/mutateelse_test.go +++ b/mutator/branch/mutateelse_test.go @@ -14,7 +14,6 @@ func TestMutateElse(t *testing.T) { test.Mutator( t, - "../../testdata/test.go", "../../testdata/branch/mutateelse.go", m, 1, diff --git a/mutator/branch/mutateif_test.go b/mutator/branch/mutateif_test.go index 407bdb6..2c44b6d 100644 --- a/mutator/branch/mutateif_test.go +++ b/mutator/branch/mutateif_test.go @@ -14,7 +14,6 @@ func TestMutateIf(t *testing.T) { test.Mutator( t, - "../../testdata/test.go", "../../testdata/branch/mutateif.go", m, 2, diff --git a/mutator/expression/remove_test.go b/mutator/expression/remove_test.go index c5e072c..2b3a939 100644 --- a/mutator/expression/remove_test.go +++ b/mutator/expression/remove_test.go @@ -15,7 +15,6 @@ func TestMutateElse(t *testing.T) { test.Mutator( t, "../../testdata/expression/remove.go", - "../../testdata/expression/remove.go", m, 6, ) diff --git a/test/mutator.go b/test/mutator.go index 41e9145..39a816c 100644 --- a/test/mutator.go +++ b/test/mutator.go @@ -15,8 +15,8 @@ import ( // Mutator tests a mutator. // It mutates the given original file with the given mutator. Every mutation is then validated with the given changed file. The mutation overall count is validated with the given count. -func Mutator(t *testing.T, originalFilePath string, changedFilePath string, m mutator.Mutator, count uint) { - originalFile, err := ioutil.ReadFile(originalFilePath) +func Mutator(t *testing.T, testFile string, m mutator.Mutator, count uint) { + originalFile, err := ioutil.ReadFile(testFile) assert.Nil(t, err) f, fset, err := mutesting.ParseSource(originalFile) @@ -39,7 +39,7 @@ func Mutator(t *testing.T, originalFilePath string, changedFilePath string, m mu err = printer.Fprint(buf, fset, f) assert.Nil(t, err) - changedFile, err := ioutil.ReadFile(fmt.Sprintf("%s.%d.go", changedFilePath, i)) + changedFile, err := ioutil.ReadFile(fmt.Sprintf("%s.%d.go", testFile, i)) assert.Nil(t, err) assert.Equal(t, string(changedFile), buf.String()) diff --git a/testdata/test.go b/testdata/branch/mutateelse.go similarity index 100% rename from testdata/test.go rename to testdata/branch/mutateelse.go diff --git a/testdata/branch/mutateif.go b/testdata/branch/mutateif.go new file mode 100644 index 0000000..1675adb --- /dev/null +++ b/testdata/branch/mutateif.go @@ -0,0 +1,23 @@ +// +build example-main + +package main + +import ( + "fmt" +) + +func main() { + i := 1 + + for i != 4 { + if i == 1 { + fmt.Println(i) + } else if i == 2 { + fmt.Println(i * 2) + } else { + fmt.Println(i * 3) + } + + i++ + } +}