Skip to content

Commit e425290

Browse files
committed
Add Sharness support files
1 parent 14308a4 commit e425290

File tree

4 files changed

+162
-0
lines changed

4 files changed

+162
-0
lines changed

tests/sharness/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib/sharness/
2+
test-results/
3+
trash directory.*.sh/

tests/sharness/Makefile

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Run sharness tests
2+
#
3+
# Copyright (c) 2014 Christian Couder
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
# NOTE: run with TEST_VERBOSE=1 for verbose sharness tests.
7+
8+
T = $(sort $(wildcard t[0-9][0-9][0-9][0-9]-*.sh))
9+
LIBDIR = lib
10+
SHARNESSDIR = sharness
11+
AGGREGATE = $(LIBDIR)/$(SHARNESSDIR)/aggregate-results.sh
12+
13+
14+
# Add below the binaries that this project generates or needs.
15+
# For example:
16+
# BINS = bin/ipfs
17+
BINS =
18+
19+
all: aggregate
20+
21+
clean: clean-test-results
22+
@echo "*** $@ ***"
23+
# Clean binaries below.
24+
# For example:
25+
# -rm -rf bin/ipfs
26+
27+
clean-test-results:
28+
@echo "*** $@ ***"
29+
-rm -rf test-results
30+
31+
$(T): clean-test-results deps
32+
@echo "*** $@ ***"
33+
./$@
34+
35+
aggregate: clean-test-results $(T)
36+
@echo "*** $@ ***"
37+
ls test-results/t*-*.sh.*.counts | $(AGGREGATE)
38+
39+
# Add below some needed dependencies.
40+
# For example:
41+
# deps: sharness $(BINS) curl
42+
deps: sharness $(BINS)
43+
44+
sharness:
45+
@echo "*** checking $@ ***"
46+
lib/install-sharness.sh
47+
48+
# Add below other targets like:
49+
# - the targets needed to build binaries,
50+
# - targets using special compile flags,
51+
# - targets to check or install dependencies.
52+
#
53+
# For example:
54+
#
55+
# GOFLAGS =
56+
#
57+
# bin/%: FORCE
58+
# cd .. && make GOFLAGS=$(GOFLAGS) $@
59+
#
60+
# race:
61+
# make GOFLAGS=-race all
62+
#
63+
# curl:
64+
# @which curl >/dev/null || (echo "Please install curl!" && false)
65+
66+
.PHONY: all clean clean-test-results $(T) aggregate deps sharness FORCE
67+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/sh
2+
# install-sharness.sh
3+
#
4+
# Copyright (c) 2014 Juan Batiz-Benet
5+
# Copyright (c) 2015 Christian Couder
6+
# MIT Licensed; see the LICENSE file in this repository.
7+
#
8+
# This script checks that Sharness is installed in:
9+
#
10+
# $(pwd)/$clonedir/$sharnessdir/
11+
#
12+
# where $clonedir and $sharnessdir are configured below.
13+
#
14+
# If Sharness is not installed, this script will clone it
15+
# from $urlprefix (defined below).
16+
#
17+
# If Sharness is not uptodate with $version (defined below),
18+
# this script will fetch and will update the installed
19+
# version to $version.
20+
#
21+
22+
# settings
23+
version=2298d6a491f43da26a89175173b6b56edd4313dd
24+
urlprefix=https://github.com/mlafeldt/sharness.git
25+
clonedir=lib
26+
sharnessdir=sharness
27+
28+
if test -f "$clonedir/$sharnessdir/SHARNESS_VERSION_$version"
29+
then
30+
# There is the right version file. Great, we are done!
31+
exit 0
32+
fi
33+
34+
die() {
35+
echo >&2 "$@"
36+
exit 1
37+
}
38+
39+
checkout_version() {
40+
git checkout "$version" || die "Could not checkout '$version'"
41+
rm -f SHARNESS_VERSION_* || die "Could not remove 'SHARNESS_VERSION_*'"
42+
touch "SHARNESS_VERSION_$version" || die "Could not create 'SHARNESS_VERSION_$version'"
43+
echo "Sharness version $version is checked out!"
44+
}
45+
46+
if test -d "$clonedir/$sharnessdir/.git"
47+
then
48+
# We need to update sharness!
49+
cd "$clonedir/$sharnessdir" || die "Could not cd into '$clonedir/$sharnessdir' directory"
50+
git fetch || die "Could not fetch to update sharness"
51+
else
52+
# We need to clone sharness!
53+
mkdir -p "$clonedir" || die "Could not create '$clonedir' directory"
54+
cd "$clonedir" || die "Could not cd into '$clonedir' directory"
55+
56+
git clone "$urlprefix" || die "Could not clone '$urlprefix'"
57+
cd "$sharnessdir" || die "Could not cd into '$sharnessdir' directory"
58+
fi
59+
60+
checkout_version

tests/sharness/t0000-sharness.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/sh
2+
3+
test_description="Show basic features of Sharness"
4+
5+
. ./lib/sharness/sharness.sh
6+
7+
test_expect_success "Success is reported like this" "
8+
echo hello world | grep hello
9+
"
10+
11+
test_expect_success "Commands are chained this way" "
12+
test x = 'x' &&
13+
test 2 -gt 1 &&
14+
echo success
15+
"
16+
17+
return_42() {
18+
echo "Will return soon"
19+
return 42
20+
}
21+
22+
test_expect_success "You can test for a specific exit code" "
23+
test_expect_code 42 return_42
24+
"
25+
26+
test_expect_failure "We expect this to fail" "
27+
test 1 = 2
28+
"
29+
30+
test_done
31+
32+
# vi: set ft=sh :

0 commit comments

Comments
 (0)