Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Malton committed Apr 1, 2020
1 parent 22b6dba commit fed64f3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ func NewApp() *App {
Action: helpCommand.Action,
Compiled: compileTime(),
Writer: os.Stdout,
ErrWriter: os.Stderr,
}
}

Expand Down
31 changes: 31 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2152,3 +2152,34 @@ func newTestApp() *App {
a.Writer = ioutil.Discard
return a
}

func TestSetupInitializesBothWriters(t *testing.T) {
a := &App{}

a.Setup()

if a.ErrWriter != os.Stderr {
t.Errorf("expected a.ErrWriter to be os.Stderr")
}

if a.Writer != os.Stdout {
t.Errorf("expected a.Writer to be os.Stdout")
}
}

func TestSetupInitializesOnlyNilWriters(t *testing.T) {
wr := &bytes.Buffer{}
a := &App{
ErrWriter: wr,
}

a.Setup()

if a.ErrWriter != wr {
t.Errorf("expected a.ErrWriter to be a *bytes.Buffer instance")
}

if a.Writer != os.Stdout {
t.Errorf("expected a.Writer to be os.Stdout")
}
}

0 comments on commit fed64f3

Please sign in to comment.