cliassert

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2019 License: MIT Imports: 13 Imported by: 0

README

cliassert

Description

Simple command line assertion tool.

Synopsis

cliassert [ -assertion-case value ] command

Examples

You can test the result of command execution.

% cliassert -stdout-contain ok echo case-is-ok
% echo $?
0

If the test fails, details will be displayed on stderr.

% cliassert -stdout-contain ok echo case-is-ng
[failure] stdout should contain ok.
% echo $?
1

Multiple tests can be set. If the -v option is added, the details of the success case will also be displayed.

% cliassert -v -stdout-contain case -stdout-contain ok echo case-is-ng
[exit-status] 0

[stdout]
case-is-ng

[stderr]

---
[success] stdout should contain case.
[failure] stdout should contain ok.

2 cases, 1 failures.

You can pass the standard output of a command to standard output using the pass option.

% cliassert -pass -exit-status 0 echo pass
pass

You can also use pipe.

% echo pipe | cliassert -stdout-contain pipe
pass

Options

-exit-status value
      String equal to exit-status
-pass
      Pass stdout of command to stdout
-stderr-contain value
      String contained in stderr
-stderr-match value
      Regex matching stderr
-stderr-not-contain value
      String not contained in stderr
-stderr-not-match value
      Regex not matching stderr
-stdout-contain value
      String contained in stdout
-stdout-match value
      Regex matching stdout
-stdout-not-contain value
      String not contained in stdout
-stdout-not-match value
      Regex not matching stdout
-v    Show verbose

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AssertCase

type AssertCase interface {
	Assert(input string) bool
	Describe() string
}

AssertCase represents one assertion case. It can examine and describe the assertion.

func NewContainCase

func NewContainCase(substr string) AssertCase

NewContainCase creates a case to inspect a given string.

func NewEqualCase

func NewEqualCase(want string) AssertCase

NewEqualCase creates a case to inspect a given string.

func NewNotContainCase

func NewNotContainCase(substr string) AssertCase

NewNotContainCase creates a case to inspect a given string.

func NewNotRegexCase

func NewNotRegexCase(pattern string) AssertCase

NewNotRegexCase creates a case to inspect a given string.

func NewRegexCase

func NewRegexCase(pattern string) AssertCase

NewRegexCase creates a case to inspect a given string.

type Assertion

type Assertion struct {
	// contains filtered or unexported fields
}

Assertion is the struct that assert the command execution result.

func (*Assertion) Assert

func (a *Assertion) Assert() (bool, *Result)

Assert asserts various command execution results.

type AssertionBuilder

type AssertionBuilder struct {
	// contains filtered or unexported fields
}

AssertionBuilder is the builder that build assertion object. Add a test case to this object to build an assertion.

func (*AssertionBuilder) AppendExitStatusCases

func (a *AssertionBuilder) AppendExitStatusCases(cases []AssertCase)

AppendExitStatusCases append assertion cases to check the exit status code.

func (*AssertionBuilder) AppendStderrCases

func (a *AssertionBuilder) AppendStderrCases(cases []AssertCase)

AppendStderrCases append assertion cases to check the stderr.

func (*AssertionBuilder) AppendStdoutCases

func (a *AssertionBuilder) AppendStdoutCases(cases []AssertCase)

AppendStdoutCases append assertion cases to check the stdout.

func (*AssertionBuilder) BuildWithCommand

func (a *AssertionBuilder) BuildWithCommand(args []string) (*Assertion, error)

BuildWithCommand built assertion form command result.

func (*AssertionBuilder) BuildWithStdin

func (a *AssertionBuilder) BuildWithStdin(stdin string) (*Assertion, error)

BuildWithStdin built assertion form stdin.

type CLI

type CLI struct {
	InStream             *os.File
	OutStream, ErrStream io.Writer
}

CLI is the struct that handles cli application.

func (*CLI) Run

func (c *CLI) Run(args []string) int

Run the cliassert.

type ContainCase

type ContainCase struct {
	// contains filtered or unexported fields
}

ContainCase represents one assertion case. It checks if the input contains strings.

func (*ContainCase) Assert

func (c *ContainCase) Assert(input string) bool

Assert inspects case assertion.

func (*ContainCase) Describe

func (c *ContainCase) Describe() string

Describe Describes the case.

type EqualCase

type EqualCase struct {
	// contains filtered or unexported fields
}

EqualCase represents one assertion case. It checks that the input and the string are the same.

func (*EqualCase) Assert

func (c *EqualCase) Assert(input string) bool

Assert inspects case assertion.

func (*EqualCase) Describe

func (c *EqualCase) Describe() string

Describe Describes the case.

type NotContainCase

type NotContainCase struct {
	// contains filtered or unexported fields
}

NotContainCase represents one assertion case. It checks that the input does not contain strings.

func (*NotContainCase) Assert

func (c *NotContainCase) Assert(input string) bool

Assert inspects case assertion.

func (*NotContainCase) Describe

func (c *NotContainCase) Describe() string

Describe Describes the case.

type NotRegexCase

type NotRegexCase struct {
	// contains filtered or unexported fields
}

NotRegexCase represents one assertion case. It checks that the input does not match regex pattern.

func (*NotRegexCase) Assert

func (c *NotRegexCase) Assert(input string) bool

Assert inspects case assertion.

func (*NotRegexCase) Describe

func (c *NotRegexCase) Describe() string

Describe Describes the case.

type RegexCase

type RegexCase struct {
	// contains filtered or unexported fields
}

RegexCase represents one assertion case. It checks if the input match regex pattern.

func (*RegexCase) Assert

func (c *RegexCase) Assert(input string) bool

Assert inspects case assertion.

func (*RegexCase) Describe

func (c *RegexCase) Describe() string

Describe Describes the case.

type Result

type Result struct {
	// contains filtered or unexported fields
}

Result is the struct that shows assertion result.

func (*Result) Show

func (r *Result) Show() (string, error)

Show shows the standard result.

func (*Result) ShowDetails

func (r *Result) ShowDetails() (string, error)

ShowDetails shows the detailed result.

func (*Result) Stdout

func (r *Result) Stdout() string

Stdout returns the stdout of the result.

Directories

Path Synopsis
cmd
cliassert command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL