Last active
September 18, 2015 01:12
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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