Implement -check flag
When this flag is used: * The program never modifies any files * If all files in the pattern contain a license, the program exits with a zero exit code * If at least one file in the pattern requires modification to include license text, the program prints such files to STDOUT and exits with a non-zero exit code
This commit is contained in:
45
main_test.go
45
main_test.go
@@ -139,3 +139,48 @@ func TestReadErrors(t *testing.T) {
|
||||
}
|
||||
run(t, "chmod", "0644", samplefile)
|
||||
}
|
||||
|
||||
func TestCheckSuccess(t *testing.T) {
|
||||
if os.Getenv("RUNME") != "" {
|
||||
main()
|
||||
return
|
||||
}
|
||||
|
||||
tmp := tempDir(t)
|
||||
t.Logf("tmp dir: %s", tmp)
|
||||
samplefile := filepath.Join(tmp, "file.c")
|
||||
|
||||
run(t, "cp", "testdata/expected/file.c", samplefile)
|
||||
cmd := exec.Command(os.Args[0],
|
||||
"-test.run=TestCheckSuccess",
|
||||
"-l", "apache", "-c", "Google LLC", "-y", "2018",
|
||||
"-check", samplefile,
|
||||
)
|
||||
cmd.Env = []string{"RUNME=1"}
|
||||
if out, err := cmd.CombinedOutput(); err != nil {
|
||||
t.Fatalf("%v\n%s", err, out)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckFail(t *testing.T) {
|
||||
if os.Getenv("RUNME") != "" {
|
||||
main()
|
||||
return
|
||||
}
|
||||
|
||||
tmp := tempDir(t)
|
||||
t.Logf("tmp dir: %s", tmp)
|
||||
samplefile := filepath.Join(tmp, "file.c")
|
||||
|
||||
run(t, "cp", "testdata/initial/file.c", samplefile)
|
||||
cmd := exec.Command(os.Args[0],
|
||||
"-test.run=TestCheckFail",
|
||||
"-l", "apache", "-c", "Google LLC", "-y", "2018",
|
||||
"-check", samplefile,
|
||||
)
|
||||
cmd.Env = []string{"RUNME=1"}
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err == nil {
|
||||
t.Fatalf("TestCheckFail exited with a zero exit code.\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user