Skip to content

Commit

Permalink
fix(output): ensure errors go to stderr
Browse files Browse the repository at this point in the history
update integration tests to check format and input args
  • Loading branch information
evilmonkeyinc committed Jun 21, 2022
1 parent 96b7e9d commit da3abac
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
5 changes: 2 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
33 changes: 29 additions & 4 deletions test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 > <https://github.com/evilmonkeyinc|evilmonkeyinc>\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 > <https://github.com/evilmonkeyinc|evilmonkeyinc>\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) {
Expand Down Expand Up @@ -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: "<https://github.com/evilmonkeyinc|evilmonkeyinc>\n",
},
{
name: "formartFlag_inputArg",
args: []string{"--format=slack", "[evilmonkeyinc](https://github.com/evilmonkeyinc)"},
expected: "<https://github.com/evilmonkeyinc|evilmonkeyinc>\n",
},
{
name: "formartShortFlag_inputArg",
args: []string{"-f=slack", "[evilmonkeyinc](https://github.com/evilmonkeyinc)"},
expected: "<https://github.com/evilmonkeyinc|evilmonkeyinc>\n",
},
{
name: "inputArg_formartShortFlag",
args: []string{"[evilmonkeyinc](https://github.com/evilmonkeyinc)", "-f=slack"},
expected: "<https://github.com/evilmonkeyinc|evilmonkeyinc>\n",
},
{
name: "invalid_format",
args: []string{"-f=invalid"},
expected: "failed: unexpected format 'invalid', expected: (slack, http)\nexit status 1\n",
},
}

Expand Down

0 comments on commit da3abac

Please sign in to comment.