Skip to content

Commit

Permalink
make mutator testing a little bit simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmski committed Dec 29, 2014
1 parent 854b834 commit b3d854d
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
1 change: 0 additions & 1 deletion mutator/branch/mutateelse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestMutateElse(t *testing.T) {

test.Mutator(
t,
"../../testdata/test.go",
"../../testdata/branch/mutateelse.go",
m,
1,
Expand Down
1 change: 0 additions & 1 deletion mutator/branch/mutateif_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ func TestMutateIf(t *testing.T) {

test.Mutator(
t,
"../../testdata/test.go",
"../../testdata/branch/mutateif.go",
m,
2,
Expand Down
1 change: 0 additions & 1 deletion mutator/expression/remove_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ func TestMutateElse(t *testing.T) {
test.Mutator(
t,
"../../testdata/expression/remove.go",
"../../testdata/expression/remove.go",
m,
6,
)
Expand Down
6 changes: 3 additions & 3 deletions test/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions testdata/branch/mutateif.go
Original file line number Diff line number Diff line change
@@ -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++
}
}

0 comments on commit b3d854d

Please sign in to comment.