Skip to content

Instantly share code, notes, and snippets.

@pratikmallya
Last active September 18, 2015 01:12
Show Gist options
  • Save pratikmallya/9860c0aa38b0d4ce0cc1 to your computer and use it in GitHub Desktop.
Save pratikmallya/9860c0aa38b0d4ce0cc1 to your computer and use it in GitHub Desktop.
Simple test which fails if code is not in the go format. Include this code in your package and code contributions will fail if not submitted with the correct format.
// include package name here
import (
"bytes"
"fmt"
"os/exec"
"testing"
)
func TestCodeFormattedCorrectly(t *testing.T) {
cmd := exec.Command("gofmt", "-l", ".")
var out bytes.Buffer
cmd.Stdout = &out
err := cmd.Run()
if err != nil {
t.Error(fmt.Sprintf("Unexpected Error %v", err))
}
if out.String() != "" {
t.Error(fmt.Sprintf("Please run gofmt. The following files are in the wrong format: %v", out.String()))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment