github.com/zmap/zlint@v1.1.0/gofmt_test.go (about)

     1  /*
     2   * ZLint Copyright 2018 Regents of the University of Michigan
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
     5   * use this file except in compliance with the License. You may obtain a copy
     6   * of the License at http://www.apache.org/licenses/LICENSE-2.0
     7   *
     8   * Unless required by applicable law or agreed to in writing, software
     9   * distributed under the License is distributed on an "AS IS" BASIS,
    10   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
    11   * implied. See the License for the specific language governing
    12   * permissions and limitations under the License.
    13   */
    14  
    15  package zlint
    16  
    17  import (
    18  	"bytes"
    19  	"os/exec"
    20  	"testing"
    21  )
    22  
    23  func TestGofmt(t *testing.T) {
    24  	globs := []string{
    25  		"*.go",
    26  		"cmd/*.go",
    27  		"lints/*.go",
    28  		"util/*.go",
    29  	}
    30  	for _, glob := range globs {
    31  		gofmtCmd := "gofmt -s -l " + glob
    32  		cmd := exec.Command("/bin/sh", "-c", gofmtCmd)
    33  		var out bytes.Buffer
    34  		cmd.Stdout = &out
    35  		cmd.Run()
    36  		if out.String() != "" {
    37  			t.Errorf("glob %s not gofmt'ed", glob)
    38  		}
    39  	}
    40  }