Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch year arg from int to string #20

Merged
merged 1 commit into from
Jan 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ var (
holder = flag.String("c", "Google LLC", "copyright holder")
license = flag.String("l", "apache", "license type: apache, bsd, mit")
licensef = flag.String("f", "", "license file")
year = flag.Int("y", time.Now().Year(), "year")
year = flag.String("y", fmt.Sprint(time.Now().Year()), "copyright year(s)")
)

func main() {
Expand Down
24 changes: 24 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,27 @@ func TestInitial(t *testing.T) {
run(t, "diff", "-r", filepath.Join(tmp, "initial"), "testdata/expected")
}
}

func TestMultiyear(t *testing.T) {
if os.Getenv("RUNME") != "" {
main()
return
}

tmp := tempDir(t)
t.Logf("tmp dir: %s", tmp)
samplefile := filepath.Join(tmp, "file.c")
const sampleLicensed = "testdata/multiyear_file.c"

run(t, "cp", "testdata/initial/file.c", samplefile)
cmd := exec.Command(os.Args[0],
"-test.run=TestMultiyear",
"-l", "bsd", "-c", "Google LLC",
"-y", "2015-2017,2019", samplefile,
)
cmd.Env = []string{"RUNME=1"}
if out, err := cmd.CombinedOutput(); err != nil {
t.Fatalf("%v\n%s", err, out)
}
run(t, "diff", samplefile, sampleLicensed)
}
12 changes: 12 additions & 0 deletions testdata/multiyear_file.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2015-2017,2019 Google LLC All rights reserved.
* Use of this source code is governed by a BSD-style
* license that can be found in the LICENSE file.
*/

#include <stdio.h>

int main() {
printf("Hello world\n");
return 0;
}
2 changes: 1 addition & 1 deletion tmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
}

type copyrightData struct {
Year int
Year string
Holder string
}

Expand Down