From e29a81efc3df88b451a4a9464724a952d97b4115 Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Tue, 5 Jun 2018 21:02:35 +0200 Subject: main: make prefixOArgs errors testable By returning an error instead of calling os.Exit, error cases can be tested easily. Error cases were not tested until now. --- tests/cli/cli_test.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests/cli') diff --git a/tests/cli/cli_test.go b/tests/cli/cli_test.go index 24bb029..8808742 100644 --- a/tests/cli/cli_test.go +++ b/tests/cli/cli_test.go @@ -448,3 +448,15 @@ func TestMultipleOperationFlags(t *testing.T) { } } } + +// Test that a missing argument to "-o" triggers exit code 1. +// See also cli_args_test.go for comprehensive tests of "-o" parsing. +func TestMissingOArg(t *testing.T) { + cmd := exec.Command(test_helpers.GocryptfsBinary, "foo", "bar", "-o") + err := cmd.Run() + exitCode := test_helpers.ExtractCmdExitCode(err) + if exitCode != exitcodes.Usage { + t.Fatalf("this should have failed with code %d, but returned %d", + exitcodes.Usage, exitCode) + } +} -- cgit v1.2.3