From f043b2c959bc9e402cbb99841017adf49d000cbf Mon Sep 17 00:00:00 2001 From: Ioannis Sermetziadis Date: Thu, 25 Aug 2022 19:19:56 +0300 Subject: [PATCH 1/2] fix: log command error once --- cmd/gitmono/main.go | 7 ++++--- pkg/gitmono/commit_parse_test.go | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/cmd/gitmono/main.go b/cmd/gitmono/main.go index beee00b..808dd65 100644 --- a/cmd/gitmono/main.go +++ b/cmd/gitmono/main.go @@ -85,10 +85,11 @@ func run() int { } } - // parse options and trigger command + // parse options to trigger command + // errors are logged by the flags library _, err = flagsParser.Parse() - if exit, code := checkError(err); exit { - return code + if err != nil { + return 1 } return 0 } diff --git a/pkg/gitmono/commit_parse_test.go b/pkg/gitmono/commit_parse_test.go index 26c023c..1d05977 100644 --- a/pkg/gitmono/commit_parse_test.go +++ b/pkg/gitmono/commit_parse_test.go @@ -96,6 +96,13 @@ func Test_conventionalCommitParse(t *testing.T) { }, want: majorBumper, }, + { + name: "use breaking change with exclamation", + args: args{ + msg: "fix!: bug that introduces breaking API change\nAPI change", + }, + want: majorBumper, + }, { name: "feature implmenentation", args: args{ From 1588d9043731111c5d1685e16db61a5b320eb743 Mon Sep 17 00:00:00 2001 From: Ioannis Sermetziadis Date: Thu, 25 Aug 2022 19:28:55 +0300 Subject: [PATCH 2/2] test: fix testdata and automate update of testdata --- cmd/gitmono/main_cmd_test.go | 13 +++++++++++-- cmd/gitmono/testdata/diff/diff.ct | 20 -------------------- cmd/gitmono/testdata/help/help.ct | 21 --------------------- cmd/gitmono/testdata/init/init.ct | 21 --------------------- cmd/gitmono/testdata/log/log.ct | 20 -------------------- cmd/gitmono/testdata/release/release.ct | 21 --------------------- cmd/gitmono/testdata/version/version.ct | 20 -------------------- 7 files changed, 11 insertions(+), 125 deletions(-) diff --git a/cmd/gitmono/main_cmd_test.go b/cmd/gitmono/main_cmd_test.go index e73ce22..469e8f4 100644 --- a/cmd/gitmono/main_cmd_test.go +++ b/cmd/gitmono/main_cmd_test.go @@ -11,6 +11,9 @@ import ( ) // TestCommand uses google/go-cmdtest to run commands and verify output +// +// Use UPDATE_TESTDATA=true to perform update of testdata file from test output. +// By default go-cmdtest runs in compare mode which compares testdata with actual test output. func TestCommand(t *testing.T) { t.Parallel() @@ -56,7 +59,7 @@ func TestCommand(t *testing.T) { assert.Nil(t, err) ts.Commands["gitmono"] = cmdtest.InProcessProgram("gitmono", run) - ts.Run(t, false) + ts.Run(t, isUpdateTestdataMode()) } } @@ -68,7 +71,13 @@ func TestCommandFailures(t *testing.T) { assert.Nil(t, err) ts.Commands["gitmono"] = cmdtest.InProcessProgram("gitmono", run) - ts.Run(t, false) + ts.Run(t, isUpdateTestdataMode()) +} + +func isUpdateTestdataMode() bool { + updateMode, found := os.LookupEnv("UPDATE_TESTDATA") + return found && updateMode == "true" + } func setupRepo(t *testing.T) func() { diff --git a/cmd/gitmono/testdata/diff/diff.ct b/cmd/gitmono/testdata/diff/diff.ct index d757936..e2c4719 100644 --- a/cmd/gitmono/testdata/diff/diff.ct +++ b/cmd/gitmono/testdata/diff/diff.ct @@ -27,23 +27,3 @@ Help Options: diff: -f= The starting point of reference range -t= The ending point of reference range (default: HEAD) - -Usage: - gitmono [OPTIONS] diff [diff-OPTIONS] - -Application Options: - -p= The project directory to operate on (default: .) - -v Enable verbose loggging - --dry-run Do not persist any write action - --commit-scheme= The scheme parse commit messages with (common, - conventional) (default: conventional) - --version-prefix= The prefix to prepend to version - -Help Options: - -h, --help Show this help message - -[diff command options] - - diff: - -f= The starting point of reference range - -t= The ending point of reference range (default: HEAD) diff --git a/cmd/gitmono/testdata/help/help.ct b/cmd/gitmono/testdata/help/help.ct index c6d6d27..040255a 100644 --- a/cmd/gitmono/testdata/help/help.ct +++ b/cmd/gitmono/testdata/help/help.ct @@ -19,24 +19,3 @@ Available commands: log release version - -Usage: - gitmono [OPTIONS] - -Application Options: - -p= The project directory to operate on (default: .) - -v Enable verbose loggging - --dry-run Do not persist any write action - --commit-scheme= The scheme parse commit messages with (common, - conventional) (default: conventional) - --version-prefix= The prefix to prepend to version - -Help Options: - -h, --help Show this help message - -Available commands: - diff - init - log - release - version diff --git a/cmd/gitmono/testdata/init/init.ct b/cmd/gitmono/testdata/init/init.ct index 9570385..a959797 100644 --- a/cmd/gitmono/testdata/init/init.ct +++ b/cmd/gitmono/testdata/init/init.ct @@ -26,24 +26,3 @@ Help Options: -c= The commit ID to release initial versions on (default: HEAD) --print-tag Print tag instead of version - -Usage: - gitmono [OPTIONS] init [init-OPTIONS] - -Application Options: - -p= The project directory to operate on (default: .) - -v Enable verbose loggging - --dry-run Do not persist any write action - --commit-scheme= The scheme parse commit messages with (common, - conventional) (default: conventional) - --version-prefix= The prefix to prepend to version - -Help Options: - -h, --help Show this help message - -[init command options] - - init: - -c= The commit ID to release initial versions on (default: - HEAD) - --print-tag Print tag instead of version diff --git a/cmd/gitmono/testdata/log/log.ct b/cmd/gitmono/testdata/log/log.ct index 94e9bbd..170d18b 100644 --- a/cmd/gitmono/testdata/log/log.ct +++ b/cmd/gitmono/testdata/log/log.ct @@ -27,23 +27,3 @@ Help Options: log: -f= The starting point of reference range -t= The ending point of reference range (default: HEAD) - -Usage: - gitmono [OPTIONS] log [log-OPTIONS] - -Application Options: - -p= The project directory to operate on (default: .) - -v Enable verbose loggging - --dry-run Do not persist any write action - --commit-scheme= The scheme parse commit messages with (common, - conventional) (default: conventional) - --version-prefix= The prefix to prepend to version - -Help Options: - -h, --help Show this help message - -[log command options] - - log: - -f= The starting point of reference range - -t= The ending point of reference range (default: HEAD) diff --git a/cmd/gitmono/testdata/release/release.ct b/cmd/gitmono/testdata/release/release.ct index 7cd1151..c29764f 100644 --- a/cmd/gitmono/testdata/release/release.ct +++ b/cmd/gitmono/testdata/release/release.ct @@ -1,6 +1,5 @@ $ gitmono release -p project-released --> FAIL no commits to release -no commits to release $ gitmono release -p project-breaking-change --version-prefix=v -c HEAD --dry-run v1.0.0 @@ -33,23 +32,3 @@ Help Options: release: -c= The commit ID to release versions on (default: HEAD) --print-tag Print tag instead of version - -Usage: - gitmono [OPTIONS] release [release-OPTIONS] - -Application Options: - -p= The project directory to operate on (default: .) - -v Enable verbose loggging - --dry-run Do not persist any write action - --commit-scheme= The scheme parse commit messages with (common, - conventional) (default: conventional) - --version-prefix= The prefix to prepend to version - -Help Options: - -h, --help Show this help message - -[release command options] - - release: - -c= The commit ID to release versions on (default: HEAD) - --print-tag Print tag instead of version diff --git a/cmd/gitmono/testdata/version/version.ct b/cmd/gitmono/testdata/version/version.ct index 044198a..f28de59 100644 --- a/cmd/gitmono/testdata/version/version.ct +++ b/cmd/gitmono/testdata/version/version.ct @@ -29,23 +29,3 @@ Help Options: version: --print-tag Print the tag of the current version --print-commit Print the commit of the current version - -Usage: - gitmono [OPTIONS] version [version-OPTIONS] - -Application Options: - -p= The project directory to operate on (default: .) - -v Enable verbose loggging - --dry-run Do not persist any write action - --commit-scheme= The scheme parse commit messages with (common, - conventional) (default: conventional) - --version-prefix= The prefix to prepend to version - -Help Options: - -h, --help Show this help message - -[version command options] - - version: - --print-tag Print the tag of the current version - --print-commit Print the commit of the current version