Skip to content
This repository was archived by the owner on Oct 1, 2021. It is now read-only.

Commit 6649ea4

Browse files
committed
Adding basic sharness tests
1 parent 991fadf commit 6649ea4

File tree

7 files changed

+207
-0
lines changed

7 files changed

+207
-0
lines changed

src/cli.js

100644100755
File mode changed.

test/sharness/.gitignore

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

test/sharness/Makefile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Run sharness tests
2+
#
3+
# Copyright (c) 2016 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+
BINS = ../bin/jsipfs-migrations
15+
16+
all: aggregate
17+
18+
help:
19+
@echo "- use 'make' or 'make all' to run all the tests"
20+
@echo "- use 'make deps' to create an 'ipfs' executable in ../bin"
21+
@echo "- to run tests manually, make sure to include ../bin in your PATH"
22+
23+
clean: clean-test-results
24+
@echo "*** $@ ***"
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+
deps: sharness $(BINS) curl
40+
41+
sharness:
42+
@echo "*** checking $@ ***"
43+
lib/install-sharness.sh
44+
45+
../bin/jsipfs-migrations:
46+
mkdir -p bin
47+
-ln -s ../../../src/cli.js ./bin/jsipfs-migrations
48+
49+
curl:
50+
@which curl >/dev/null || (echo "Please install curl!" && false)
51+
52+
.PHONY: all help clean clean-test-results $(T) aggregate deps sharness
53+

test/sharness/lib/install-sharness.sh

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=ecba410b0b58400dd6517cfa6594fdac243d9056
24+
urlprefix=https://github.com/chriscool/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

test/sharness/lib/test-lib.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Test framework for go-ipfs
2+
#
3+
# Copyright (c) 2014 Christian Couder
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
# We are using sharness (https://github.com/chriscool/sharness)
7+
# which was extracted from the Git test framework.
8+
9+
# add current directory to path.
10+
BIN=$(echo `pwd`/bin)
11+
PATH=${BIN}:${PATH}
12+
13+
# assert the `jsipfs-migrations` we're using is the right one.
14+
if [[ $(which jsipfs-migrations) != ${BIN}/jsipfs-migrations ]]; then
15+
echo >&2 "Cannot find the test's local jsipfs-migrations tool."
16+
echo >&2 "Please check test and ipfs tool installation."
17+
JS_BIN=$(dirname $(dirname "${BIN}"))"/src/cli.js"
18+
echo >&2 "For jsipfs-migrations, look for a symlink from '${BIN}/jsipfs-migrations' to '${JS_BIN}'."
19+
echo >&2 "Use 'make' or 'make deps' as it should install this symlink."
20+
exit 1
21+
fi
22+
23+
# set sharness verbosity. we set the env var directly as
24+
# it's too late to pass in --verbose, and --verbose is harder
25+
# to pass through in some cases.
26+
test "$TEST_VERBOSE" = 1 && verbose=t
27+
28+
SHARNESS_LIB="lib/sharness/sharness.sh"
29+
30+
. "$SHARNESS_LIB" || {
31+
echo >&2 "Cannot source: $SHARNESS_LIB"
32+
echo >&2 "Please check Sharness installation."
33+
exit 1
34+
}

test/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 :

test/sharness/t0010-basic-commands.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2014 Christian Couder
4+
# MIT Licensed; see the LICENSE file in this repository.
5+
#
6+
7+
test_description="Test installation and some basic commands"
8+
9+
. lib/test-lib.sh
10+
11+
test_expect_success "current dir is writable" '
12+
echo "It works!" > test.txt
13+
'
14+
15+
test_expect_success "jsipfs-migrations version succeeds" '
16+
jsipfs-migrations --version > version.txt
17+
'
18+
19+
test_expect_success "jsipfs-migrations help succeeds" '
20+
jsipfs-migrations --help > help.txt
21+
'
22+
23+
test_done

0 commit comments

Comments
 (0)