Skip to content

j-keck/clic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

clic - command line interface checker

Intro

Simple tool to check basic cli tools.

Usage

clic 0.1.1

USAGE:
    clic [FLAGS] [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -q, --quiet
    -V, --version
    -v, --verbose

OPTIONS:
    -c, --cmdline <cmdline>                          Command line to execute
    -d, --dir <dir>                                  Directory with spec files to execute
        --expected-exit-code <expected-exit-code>    Expected exit code from the executed program [default: 0]
    -s, --spec <spec>                                Test spec file path
    -t, --timeout <timeout>                           [default: 1s]

clic can verify a single spec file, or it can process all files (with a .spec sufffix) in a given directory. The spec file is a simple text file, where each line contains an instruction.

Example spec file content:

# this is comment
> program input
expected output on stdout
! expected output on stderr

Lines with starts with a

  • # are comments and are ignored
  • > are program inputs
  • ! are expected output on stderr
  • anything else are expected output on stdout

If the first line of the spec file starts with # clic, this line will parsed and used as clic arguments.

Example

As an example we use the bc tool. In the spec file we define the program arguments, and the interactive session:

# clic --cmdline 'bc -q'
> 3 * 9
27
> 3 / 0
! Runtime error (func=(main), adr=5): Divide by zero
> quit

to verify the spec file, exeucte clic with the file as an argument:

clic --spec doc/examples/bc.spec
validate spec: doc/examples/bc.spec
Success

You can start clic with the --verbose flag to see what’s going on:

clic --spec doc/examples/bc.spec --verbose
validate spec: doc/examples/bc.spec
send to process stdin: 3 * 9
expect on stdout: 27
send to process stdin: 3 / 0
expect on stderr: Runtime error (func=(main), adr=5): Divide by zero
send to process stdin: quit
Success

Mismatch

If clic find’s a mismatch, it will stop the execution and print the difference.

When we run clic with this buggy spec file:

# clic --cmdline 'bc -q'
> 3 * 9
72

It will abort and displays the difference

# ignore that 'exit 0' - it's for my used doc setup
clic --spec doc/examples/bc-err.spec; exit 0
validate spec: doc/examples/bc-err.spec
Failure: Unexpected response for input: '3 * 9'
  expected: '72'
  acutal  : '27'

About

command line interface checker

Resources

Stars

Watchers

Forks

Packages

No packages published