Skip to content

Commit 83a192c

Browse files
author
Ioannis Sermetziadis
authored
fix: log errors once (#52)
* fix: log command error once * test: fix testdata and automate update of testdata
1 parent 9ef2278 commit 83a192c

9 files changed

Lines changed: 22 additions & 128 deletions

File tree

cmd/gitmono/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,11 @@ func run() int {
8585
}
8686
}
8787

88-
// parse options and trigger command
88+
// parse options to trigger command
89+
// errors are logged by the flags library
8990
_, err = flagsParser.Parse()
90-
if exit, code := checkError(err); exit {
91-
return code
91+
if err != nil {
92+
return 1
9293
}
9394
return 0
9495
}

cmd/gitmono/main_cmd_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import (
1111
)
1212

1313
// TestCommand uses google/go-cmdtest to run commands and verify output
14+
//
15+
// Use UPDATE_TESTDATA=true to perform update of testdata file from test output.
16+
// By default go-cmdtest runs in compare mode which compares testdata with actual test output.
1417
func TestCommand(t *testing.T) {
1518
t.Parallel()
1619

@@ -56,7 +59,7 @@ func TestCommand(t *testing.T) {
5659
assert.Nil(t, err)
5760

5861
ts.Commands["gitmono"] = cmdtest.InProcessProgram("gitmono", run)
59-
ts.Run(t, false)
62+
ts.Run(t, isUpdateTestdataMode())
6063
}
6164
}
6265

@@ -68,7 +71,13 @@ func TestCommandFailures(t *testing.T) {
6871
assert.Nil(t, err)
6972

7073
ts.Commands["gitmono"] = cmdtest.InProcessProgram("gitmono", run)
71-
ts.Run(t, false)
74+
ts.Run(t, isUpdateTestdataMode())
75+
}
76+
77+
func isUpdateTestdataMode() bool {
78+
updateMode, found := os.LookupEnv("UPDATE_TESTDATA")
79+
return found && updateMode == "true"
80+
7281
}
7382

7483
func setupRepo(t *testing.T) func() {

cmd/gitmono/testdata/diff/diff.ct

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,3 @@ Help Options:
2727
diff:
2828
-f= The starting point of reference range
2929
-t= The ending point of reference range (default: HEAD)
30-
31-
Usage:
32-
gitmono [OPTIONS] diff [diff-OPTIONS]
33-
34-
Application Options:
35-
-p= The project directory to operate on (default: .)
36-
-v Enable verbose loggging
37-
--dry-run Do not persist any write action
38-
--commit-scheme= The scheme parse commit messages with (common,
39-
conventional) (default: conventional)
40-
--version-prefix= The prefix to prepend to version
41-
42-
Help Options:
43-
-h, --help Show this help message
44-
45-
[diff command options]
46-
47-
diff:
48-
-f= The starting point of reference range
49-
-t= The ending point of reference range (default: HEAD)

cmd/gitmono/testdata/help/help.ct

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,3 @@ Available commands:
1919
log
2020
release
2121
version
22-
23-
Usage:
24-
gitmono [OPTIONS] <command>
25-
26-
Application Options:
27-
-p= The project directory to operate on (default: .)
28-
-v Enable verbose loggging
29-
--dry-run Do not persist any write action
30-
--commit-scheme= The scheme parse commit messages with (common,
31-
conventional) (default: conventional)
32-
--version-prefix= The prefix to prepend to version
33-
34-
Help Options:
35-
-h, --help Show this help message
36-
37-
Available commands:
38-
diff
39-
init
40-
log
41-
release
42-
version

cmd/gitmono/testdata/init/init.ct

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,3 @@ Help Options:
2626
-c= The commit ID to release initial versions on (default:
2727
HEAD)
2828
--print-tag Print tag instead of version
29-
30-
Usage:
31-
gitmono [OPTIONS] init [init-OPTIONS]
32-
33-
Application Options:
34-
-p= The project directory to operate on (default: .)
35-
-v Enable verbose loggging
36-
--dry-run Do not persist any write action
37-
--commit-scheme= The scheme parse commit messages with (common,
38-
conventional) (default: conventional)
39-
--version-prefix= The prefix to prepend to version
40-
41-
Help Options:
42-
-h, --help Show this help message
43-
44-
[init command options]
45-
46-
init:
47-
-c= The commit ID to release initial versions on (default:
48-
HEAD)
49-
--print-tag Print tag instead of version

cmd/gitmono/testdata/log/log.ct

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,23 +27,3 @@ Help Options:
2727
log:
2828
-f= The starting point of reference range
2929
-t= The ending point of reference range (default: HEAD)
30-
31-
Usage:
32-
gitmono [OPTIONS] log [log-OPTIONS]
33-
34-
Application Options:
35-
-p= The project directory to operate on (default: .)
36-
-v Enable verbose loggging
37-
--dry-run Do not persist any write action
38-
--commit-scheme= The scheme parse commit messages with (common,
39-
conventional) (default: conventional)
40-
--version-prefix= The prefix to prepend to version
41-
42-
Help Options:
43-
-h, --help Show this help message
44-
45-
[log command options]
46-
47-
log:
48-
-f= The starting point of reference range
49-
-t= The ending point of reference range (default: HEAD)

cmd/gitmono/testdata/release/release.ct

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
$ gitmono release -p project-released --> FAIL
22
no commits to release
3-
no commits to release
43

54
$ gitmono release -p project-breaking-change --version-prefix=v -c HEAD --dry-run
65
v1.0.0
@@ -33,23 +32,3 @@ Help Options:
3332
release:
3433
-c= The commit ID to release versions on (default: HEAD)
3534
--print-tag Print tag instead of version
36-
37-
Usage:
38-
gitmono [OPTIONS] release [release-OPTIONS]
39-
40-
Application Options:
41-
-p= The project directory to operate on (default: .)
42-
-v Enable verbose loggging
43-
--dry-run Do not persist any write action
44-
--commit-scheme= The scheme parse commit messages with (common,
45-
conventional) (default: conventional)
46-
--version-prefix= The prefix to prepend to version
47-
48-
Help Options:
49-
-h, --help Show this help message
50-
51-
[release command options]
52-
53-
release:
54-
-c= The commit ID to release versions on (default: HEAD)
55-
--print-tag Print tag instead of version

cmd/gitmono/testdata/version/version.ct

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,3 @@ Help Options:
2929
version:
3030
--print-tag Print the tag of the current version
3131
--print-commit Print the commit of the current version
32-
33-
Usage:
34-
gitmono [OPTIONS] version [version-OPTIONS]
35-
36-
Application Options:
37-
-p= The project directory to operate on (default: .)
38-
-v Enable verbose loggging
39-
--dry-run Do not persist any write action
40-
--commit-scheme= The scheme parse commit messages with (common,
41-
conventional) (default: conventional)
42-
--version-prefix= The prefix to prepend to version
43-
44-
Help Options:
45-
-h, --help Show this help message
46-
47-
[version command options]
48-
49-
version:
50-
--print-tag Print the tag of the current version
51-
--print-commit Print the commit of the current version

pkg/gitmono/commit_parse_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ func Test_conventionalCommitParse(t *testing.T) {
9696
},
9797
want: majorBumper,
9898
},
99+
{
100+
name: "use breaking change with exclamation",
101+
args: args{
102+
msg: "fix!: bug that introduces breaking API change\nAPI change",
103+
},
104+
want: majorBumper,
105+
},
99106
{
100107
name: "feature implmenentation",
101108
args: args{

0 commit comments

Comments
 (0)