Skip to content

Commit 2e5cf00

Browse files
authored
Merge pull request #20 from google/multiyear
Switch year arg from int to string
2 parents b4fa55f + f6c8b89 commit 2e5cf00

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ var (
4848
holder = flag.String("c", "Google LLC", "copyright holder")
4949
license = flag.String("l", "apache", "license type: apache, bsd, mit")
5050
licensef = flag.String("f", "", "license file")
51-
year = flag.Int("y", time.Now().Year(), "year")
51+
year = flag.String("y", fmt.Sprint(time.Now().Year()), "copyright year(s)")
5252
)
5353

5454
func main() {

main_test.go

+24
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,27 @@ func TestInitial(t *testing.T) {
6363
run(t, "diff", "-r", filepath.Join(tmp, "initial"), "testdata/expected")
6464
}
6565
}
66+
67+
func TestMultiyear(t *testing.T) {
68+
if os.Getenv("RUNME") != "" {
69+
main()
70+
return
71+
}
72+
73+
tmp := tempDir(t)
74+
t.Logf("tmp dir: %s", tmp)
75+
samplefile := filepath.Join(tmp, "file.c")
76+
const sampleLicensed = "testdata/multiyear_file.c"
77+
78+
run(t, "cp", "testdata/initial/file.c", samplefile)
79+
cmd := exec.Command(os.Args[0],
80+
"-test.run=TestMultiyear",
81+
"-l", "bsd", "-c", "Google LLC",
82+
"-y", "2015-2017,2019", samplefile,
83+
)
84+
cmd.Env = []string{"RUNME=1"}
85+
if out, err := cmd.CombinedOutput(); err != nil {
86+
t.Fatalf("%v\n%s", err, out)
87+
}
88+
run(t, "diff", samplefile, sampleLicensed)
89+
}

testdata/multiyear_file.c

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/*
2+
* Copyright (c) 2015-2017,2019 Google LLC All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
#include <stdio.h>
8+
9+
int main() {
10+
printf("Hello world\n");
11+
return 0;
12+
}

tmpl.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func init() {
3232
}
3333

3434
type copyrightData struct {
35-
Year int
35+
Year string
3636
Holder string
3737
}
3838

0 commit comments

Comments
 (0)