From f6c8b89ee532814a6f0f08a9749fd043b9bf5d57 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 7 Jan 2019 14:10:08 +0100 Subject: [PATCH] Switch year arg from int to string This effectively allows for arbitrary copyright years. For instance, 2018-2019. --- main.go | 2 +- main_test.go | 24 ++++++++++++++++++++++++ testdata/multiyear_file.c | 12 ++++++++++++ tmpl.go | 2 +- 4 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 testdata/multiyear_file.c diff --git a/main.go b/main.go index 21e317d..e7a1b91 100644 --- a/main.go +++ b/main.go @@ -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() { diff --git a/main_test.go b/main_test.go index 41a95fa..334d170 100644 --- a/main_test.go +++ b/main_test.go @@ -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) +} diff --git a/testdata/multiyear_file.c b/testdata/multiyear_file.c new file mode 100644 index 0000000..c25b9a0 --- /dev/null +++ b/testdata/multiyear_file.c @@ -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 + +int main() { + printf("Hello world\n"); + return 0; +} diff --git a/tmpl.go b/tmpl.go index 6efc831..d582469 100644 --- a/tmpl.go +++ b/tmpl.go @@ -32,7 +32,7 @@ func init() { } type copyrightData struct { - Year int + Year string Holder string }