From f21db281c2a83f17dd161e179d28e7e8777a4dca Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 20 Apr 2013 18:30:09 -0600 Subject: [PATCH] better testing of the help printing on CLIs --- packer/environment_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packer/environment_test.go b/packer/environment_test.go index 5c171d682..87744724a 100644 --- a/packer/environment_test.go +++ b/packer/environment_test.go @@ -4,6 +4,7 @@ import ( "bytes" "cgl.tideland.biz/asserts" "os" + "strings" "testing" ) @@ -63,9 +64,21 @@ func TestEnvironment_DefaultCli_Help(t *testing.T) { defaultEnv := testEnvironment() - // Test the basic version options + // A little lambda to help us test the output actually contains help + testOutput := func() { + buffer := defaultEnv.Ui().(*ReaderWriterUi).Writer.(*bytes.Buffer) + output := buffer.String() + buffer.Reset() + assert.True(strings.Contains(output, "usage: packer"), "should print help") + } + + // Test "--help" assert.Equal(defaultEnv.Cli([]string{"--help"}), 1, "--help should print") + testOutput() + + // Test "-h" assert.Equal(defaultEnv.Cli([]string{"-h"}), 1, "--help should print") + testOutput() } func TestEnvironment_DefaultCli_Version(t *testing.T) {