Skip to content

Commit

Permalink
Fix argument test suite (#4)
Browse files Browse the repository at this point in the history
Signed-off-by: plar <[email protected]>
  • Loading branch information
plar authored Feb 26, 2024
1 parent 4b371b6 commit 38b6544
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/arg_suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (t *ArgumentTest) Test(c *check.C, cmdName string) {
c.Fatal("Name is required")
}
cmd, err := command.New(cmdName, t.Argument)
if err == nil {
if t.ExpectedErr == nil {
t.assertNoError(c, err)
} else {
t.assertError(c, err)
Expand Down
15 changes: 15 additions & 0 deletions test/arg_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,21 @@ func (s *TestRunnerWithConfig) TestArgumentTestEmptyName(c *check.C) {
c.Assert(res.Passed(), check.Equals, false)
}

// TestArgumentTestErrButReturnOK tests the ArgumentTest with an error but ArgumentTest returns no error.
func (s *TestRunnerWithConfig) TestArgumentTestErrButReturnOK(c *check.C) {
err := errors.New("test error")
cat := CustomArgumentTest{
name: "TestArgumentTestErrButReturnOK",
argErr: nil, // no error
expectedErr: err, // expected error
expectedErrMsg: "test error",
}
res := check.Run(&cat, s.cfg)
out := strings.ReplaceAll(s.out.String(), "\n", "")
c.Assert(out, check.Matches, ".*FAIL:.*CustomArgumentTest\\.Test.*test error.*")
c.Assert(res.Passed(), check.Equals, false)
}

// TestArgumentTestErr tests the ArgumentTest with an error.
func (s *TestRunnerWithConfig) TestArgumentTestErr(c *check.C) {
err := errors.New("test error")
Expand Down

0 comments on commit 38b6544

Please sign in to comment.