Skip to content

Commit

Permalink
always gofmt the generated source code
Browse files Browse the repository at this point in the history
  • Loading branch information
zimmski committed Dec 29, 2014
1 parent 211e427 commit 87c0a49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
19 changes: 9 additions & 10 deletions cmd/go-mutesting/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package main

import (
"bytes"
"fmt"
"go/ast"
"go/format"
"go/printer"
"go/token"
"io"
Expand Down Expand Up @@ -132,7 +134,7 @@ func main() {

MUTATOR:
for _, name := range mutator.List() {
if len(opts.Mutator.DisableMutators) != 0 {
if len(opts.Mutator.DisableMutators) > 0 {
for _, d := range opts.Mutator.DisableMutators {
pattern := strings.HasSuffix(d, "*")

Expand Down Expand Up @@ -206,7 +208,7 @@ MUTATOR:
}
debug("Save mutation into %q", mutationFile)

if len(execs) != 0 {
if len(execs) > 0 {
debug("Execute %q for mutation", opts.Exec.Exec)

execCommand := exec.Command(execs[0], execs[1:]...)
Expand Down Expand Up @@ -277,7 +279,7 @@ MUTATOR:
debug("Remove %q", tmpDir)
}

if len(execs) != 0 {
if len(execs) > 0 {
fmt.Printf("The mutation score is %f (%d passed, %d failed, %d skipped, total is %d)\n", float64(passed)/float64(passed+failed), passed, failed, skipped, passed+failed+skipped)
} else {
fmt.Println("Cannot do a mutation testing summary since no exec command was given.")
Expand Down Expand Up @@ -323,20 +325,17 @@ func copyFile(src string, dst string) (err error) {
}

func saveAST(file string, fset *token.FileSet, node ast.Node) error {
f, err := os.Create(file)
if err != nil {
return err
}
var buf bytes.Buffer

err = printer.Fprint(f, fset, node)
err := printer.Fprint(&buf, fset, node)
if err != nil {
return err
}

err = f.Close()
src, err := format.Source(buf.Bytes())
if err != nil {
return err
}

return nil
return ioutil.WriteFile(file, src, 0666)
}
1 change: 1 addition & 0 deletions scripts/simple.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ case $GOMUTESTING_RESULT in
exit 2
;;
*) # Unkown exit code -> SKIP
echo "Unknown exit code"
echo "$GOMUTESTING_DIFF"

exit $GOMUTESTING_RESULT
Expand Down

0 comments on commit 87c0a49

Please sign in to comment.