• Stars
    star
    373
  • Rank 111,011 (Top 3 %)
  • Language
    Shell
  • License
    GNU General Publi...
  • Created about 13 years ago
  • Updated 28 days ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Shell library to test your tools like Git does

Sharness

Sharness is a portable shell library to write, run, and analyze automated tests for Unix programs. Since all tests output TAP, the Test Anything Protocol, they can be run with any TAP harness.

Each test is written as a shell script, for example:

#!/bin/sh

test_description='Show basic features of Sharness'

. ./sharness.sh

test_expect_success 'Success is reported like this' '
    echo hello world | grep hello
'

test_expect_success 'Commands are chained this way' '
    test x = "x" &&
    test 2 -gt 1 &&
    echo success
'

test_expect_failure 'We expect this to fail' '
    test 1 = 2
'

test_done

Running the above test script returns the following (TAP) output:

$ ./simple.t
ok 1 - Success is reported like this
ok 2 - Commands are chained this way
ok 3 - You can test for a specific exit code
not ok 4 - We expect this to fail # TODO known breakage
# still have 1 known breakage(s)
# passed all remaining 3 test(s)
1..4

Alternatively, you can run the test through prove(1):

$ prove simple.t
simple.t .. ok
All tests successful.
Files=1, Tests=4,  0 wallclock secs ( 0.02 usr +  0.00 sys =  0.02 CPU)
Result: PASS

Every test is run in a temporary trash directory, so you are free to create as many files as you want, even files in the home directory, because $HOME is set to that temporary trash directory. At the end of the test, that directory is removed (unless there's a failure).

Sharness was derived from the Git project - see README.git for the original documentation.

Installation

First, clone the Git repository:

$ git clone git://github.com/felipec/sharness.git

Then choose an installation method that works best for you:

Per-project installation

If you like to add Sharness to the sources of a project you want to use it for, simply copy the files sharness.sh and example/Makefile to a folder named test inside that project, and source sharness.sh in your test files.

Another way is to use Sharnessify.

Alternatively, you can also add Sharness as a Git submodule to your project.

In per-project installation, Sharness will optionally load extensions from sharness.d/*.sh if a sharness.d directory is found in the same directory as sharness.sh. This allows per-project extensions and enhancements to be added to the test library without requiring modification of sharness.sh.

Per-user installation

$ cd sharness
$ make install

This will install Sharness to $HOME/share/sharness, and its documentation and examples to $HOME/share/doc/sharness.

System-wide installation

$ cd sharness
# make install prefix=/usr/local

This will install Sharness to /usr/local/share/sharness, and its documentation and examples to /usr/local/share/doc/sharness.

Of course, you can change the prefix parameter to install Sharness to any other location.

Usage

The only essential file to Sharness is sharness.sh, which is the core shell library providing test functionality. It's meant to be sourced from test scripts, but not executed.

The following files are optional:

  • example/Makefile - test driver. The default target runs the complete testsuite.
  • lib-sharness/functions.sh - extra functions. These are functions that are nice to have, but not necessary.
  • tools/aggregate-results.sh - tool to show results. Aggregates all the results in test-results. It's meant to be called inside the Makefile after all the tests finish.

To see an explanation of all the functions, see the separate API documentation.

To learn how to write and run actual test scripts based on sharness.sh, please read README.git until I come up with more documentation myself.

Command-line options

The *.t test scripts have the following options (again, read README.git for details) :

  • --debug, -d: helps debugging
  • --immediate, -i: stop execution after the first failing test
  • --long-tests, -l: run tests marked with prereq EXPENSIVE
  • --interactive-tests: run tests marked with prereq INTERACTIVE
  • --help, -h: show test description
  • --verbose, -v: show additional debug output
  • --quiet, -q: show less output
  • --chain-lint/--no-chain-lint: check &&-chains in scripts
  • --no-color: don't color the output
  • --tee: also write output to a file
  • --verbose-log: write output to a file, but not on stdout
  • --root=<dir>: create trash directories in <dir> instead of current directory.

Projects using Sharness

See how Sharness is used in real-world projects:

Furthermore, as Sharness was derived from Git, Git's test suite is worth examining as well, especially if you're interested in managing a big number of tests.

Alternatives

Here is a list of other shell testing libraries (sorted alphabetically):

License

Sharness is licensed under the terms of the GNU General Public License version 2 or higher. See file COPYING for full license text.

Contributing

Contributions are welcome, see file CONTRIBUTING for details.

Authors

Sharness was created in April 2011 and maintained until June 2016 by Mathias Lafeldt. The library is derived from the Git project's test-lib.sh. It was maintained by Christian Couder from June 2016 to August 2019, thanks to sponsorship from Protocol Labs. It is currently maintained by Felipe Contreras.

See Github's "contributors" page for a list of developers.

A complete list of authors should include Git contributors to test-lib.sh too.

More Repositories

1

git-remote-hg

Transparent bidirectional bridge between Git and Mercurial for Git
Shell
360
star
2

notmuch-vim

Text-based mail user agent in vim using notmuch.
Vim Script
85
star
3

git-remote-bzr

Transparent bidirectional bridge between Git and Bazaar for Git
Python
75
star
4

git-related

Find related people and commits on a set of changes
Shell
68
star
5

vim-felipec

Vim color scheme: dark, bright, simple.
Vim Script
50
star
6

finit

Simple init system
Ruby
50
star
7

soap4r

SOAP4R is an implementation of SOAP 1.1 (W3C Note) for Ruby
Ruby
47
star
8

msn-pecan

MSN Messenger library in C
C
41
star
9

libpurple-mini

libpurple separate from pidgin.
C
33
star
10

git-completion

Git completion stuff
Shell
32
star
11

gst-openmax

GStreamer OpenMAX IL plug-in
C
31
star
12

libomxil-bellagio

Bellagio OpenMAX IL
C
29
star
13

vim-sanegx

Makes gx work correctly.
Vim Script
25
star
14

git-reintegrate

Tool that allows the regeneration of integration branches
Shell
22
star
15

gst-dsp

GStreamer elements for TI's OMAP DSP
C
21
star
16

gst-player

Simple media player using GStreamer
C
16
star
17

gst-av

Some wrappers for libav
C
15
star
18

maemo-scrobbler

Maemo scrobbler
C
13
star
19

xz-min

Minimal setup to trigger the xz backdoor
C
12
star
20

xfce-config-helper

Helper to manage Xfce configurations
Ruby
12
star
21

dotfiles

My config files
Ruby
12
star
22

good-taste

An illustration of good taste in code
SCSS
9
star
23

git-smartlist

Shell
8
star
24

ripary

Codeswarm rewrite in ruby
Ruby
8
star
25

dsp-dummy

A dummy dsp node; good example of how to write one
C
6
star
26

gst-transcode

GStreamer tools to help transcoding
6
star
27

git-send-series

A tool to help maintain patch series
Shell
5
star
28

dsp-tools

Miscellaneous utilities for TI's C64x+ DSP
C
5
star
29

math-notepad

Very simple math.js editor
JavaScript
5
star
30

libmsn-pecan

Library for MSN instant messaging protocol
C
4
star
31

gst-omapfb

GStreamer plug-in for omapfb rendering.
C
4
star
32

libomxil-g

Experimental OpenMAX IL implementation.
4
star
33

pidgin-git-import

Scripts to convert pidgin's mtn repo to git
Ruby
4
star
34

hexclock

A visualization of a hexclock (a true binary clock)
JavaScript
3
star
35

dot-team

Distributed collaborative dotfiles
Shell
3
star
36

libmtag

Simple yet useful tagging library for music.
C++
3
star
37

telepathy-msn-pecan

Telepathy CM using libmsn-pecan
C
2
star
38

ruby-parseopt

A simple yet powerful option parser
Ruby
2
star
39

dot-tools

Tools for managing dotfiles using git
Shell
2
star
40

gst-maemo-xiph

Parsers for ogg/flac, used for Maemo
C
2
star
41

twitter-client

Simple twitter client using twitter-glib
C
2
star
42

liblzma

Simple build system for liblzma
Makefile
2
star
43

purple-msn-pecan

A libpurple plug-in that uses libmsn-pecan.
1
star
44

libmtag-ruby

Ruby bindings for mtag.
C
1
star
45

gst-xssim

Efficient SSIM element
C
1
star
46

milaatu

Simple test framework
Python
1
star
47

libproxy-simple

Simple replacement for libproxy
C
1
star
48

libtidsp

Library for tidspbridge
C
1
star
49

libmtag-python

Python bindings for mtag.
C
1
star
50

libgmsn

An asynchronous library designed to handle communication using the MSN protocol using GObject.
C
1
star
51

notmuch-tools

My notmuch tools
Ruby
1
star
52

xz-hack-refactor

An attempt to simplify the xz backdoor to understand what it does
LLVM
1
star
53

ace-list

Examples of the best ways to write linked lists
Go
1
star