diff --git a/cmd/main.go b/cmd/main.go index 6e4b92a..151dc74 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -68,11 +68,10 @@ func printHelp(writer *os.File, flagset *flag.FlagSet) { } func outputError(err error) { - fmt.Printf("failed: %s\n", err.Error()) + fmt.Fprintf(os.Stderr, "failed: %s\n", err.Error()) os.Exit(1) } -// TODO : integration tests to verify flags vs args is done right and the same each time func main() { var format, input, output string @@ -97,7 +96,7 @@ func main() { printHelp(os.Stdout, flagset) return case cmdVersion: - fmt.Printf("version %s %s/%s\n", Version, OS, Arch) + fmt.Fprintf(os.Stdout, "version %s %s/%s\n", Version, OS, Arch) return default: break diff --git a/test/integration_test.go b/test/integration_test.go index 48ffa8e..dc54106 100644 --- a/test/integration_test.go +++ b/test/integration_test.go @@ -9,7 +9,7 @@ import ( ) const ( - helpText string = "markdownconverter is a tool for converting markdown to other formats\n\nUsage:\n\n markdownconverter [format] [input] [output]\n\nExample:\n\n markdownconverter slack \"[evilmonkeyinc](https://github.com/evilmonkeyinc)\"\n > \n\nOptions:\n\n -f, --format string The output format\n -i, --input string The input source file\n -o, --output string The output destination file. optional\n" + sampleHelpText string = "markdownconverter is a tool for converting markdown to other formats\n\nUsage:\n\n markdownconverter [format] [input] [output]\n\nExample:\n\n markdownconverter slack \"[evilmonkeyinc](https://github.com/evilmonkeyinc)\"\n > \n\nOptions:\n\n -f, --format string The output format\n -i, --input string The input source file\n -o, --output string The output destination file. optional\n" ) func runCommand(arg ...string) (string, error) { @@ -62,17 +62,42 @@ func Test_IntegrationTests(t *testing.T) { { name: "exec_help", args: []string{"help"}, - expected: helpText, + expected: sampleHelpText, }, { name: "exec_help_flag", args: []string{"--help"}, - expected: helpText, + expected: sampleHelpText, }, { name: "exec_h_flag", args: []string{"-h"}, - expected: helpText, + expected: sampleHelpText, + }, + { + name: "formartArg_inputArg", + args: []string{"slack", "[evilmonkeyinc](https://github.com/evilmonkeyinc)"}, + expected: "\n", + }, + { + name: "formartFlag_inputArg", + args: []string{"--format=slack", "[evilmonkeyinc](https://github.com/evilmonkeyinc)"}, + expected: "\n", + }, + { + name: "formartShortFlag_inputArg", + args: []string{"-f=slack", "[evilmonkeyinc](https://github.com/evilmonkeyinc)"}, + expected: "\n", + }, + { + name: "inputArg_formartShortFlag", + args: []string{"[evilmonkeyinc](https://github.com/evilmonkeyinc)", "-f=slack"}, + expected: "\n", + }, + { + name: "invalid_format", + args: []string{"-f=invalid"}, + expected: "failed: unexpected format 'invalid', expected: (slack, http)\nexit status 1\n", }, }