Commit 531f0579 authored by Tommi Virtanen's avatar Tommi Virtanen Committed by Jeromy

sharness: Don't assume we know all things that can create garbage

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>

sharness: Don't assume we know all things that can create garbage

License: MIT
Signed-off-by: default avatarJeromy <jeromyj@gmail.com>
parent fb589a81
......@@ -62,3 +62,38 @@ docker_exec() {
docker_stop() {
docker stop "$1"
}
# Test whether all the expected lines are included in a file. The file
# can have extra lines.
#
# $1 - Path to file with expected lines.
# $2 - Path to file with actual output.
#
# Examples
#
# test_expect_success 'foo says hello' '
# echo hello >expected &&
# foo >actual &&
# test_cmp expected actual
# '
#
# Returns the exit code of the command set by TEST_CMP.
test_includes_lines() {
sort "$1" >"$1_sorted" &&
sort "$2" >"$2_sorted" &&
comm -2 -3 "$1_sorted" "$2_sorted" >"$2_missing" &&
[ ! -s "$2_missing" ] || test_fsh comm -2 -3 "$1_sorted" "$2_sorted"
}
# Depending on GNU seq availability is not nice.
# Git also has test_seq but it uses Perl.
test_seq() {
test "$1" -le "$2" || return
i="$1"
j="$2"
while test "$i" -le "$j"
do
echo "$i"
i=$(expr "$i" + 1)
done
}
......@@ -114,8 +114,8 @@ test_expect_success "remove direct pin" '
'
test_expect_success "'ipfs repo gc' removes file" '
echo "removed $PATCH_ROOT" >expected7 &&
echo "removed $HASH" >>expected7 &&
echo "removed $HASH" >expected7 &&
echo "removed $PATCH_ROOT" >>expected7 &&
ipfs repo gc >actual7 &&
test_sort_cmp expected7 actual7
'
......
......@@ -150,8 +150,7 @@ test_expect_success "nothing is pinned directly" '
'
test_expect_success "'ipfs repo gc' succeeds" '
ipfs repo gc >gc_out_actual &&
test_must_be_empty gc_out_actual
ipfs repo gc >gc_out_actual
'
test_expect_success "objects are still there" '
......@@ -217,7 +216,7 @@ test_expect_success "'ipfs repo gc' succeeds" '
echo "removed $HASH_FILE3" > gc_out_exp2 &&
echo "removed $HASH_FILE5" >> gc_out_exp2 &&
echo "removed $HASH_DIR3" >> gc_out_exp2 &&
test_sort_cmp gc_out_exp2 gc_out_actual2
test_includes_lines gc_out_exp2 gc_out_actual2
'
# use object links for HASH_DIR1 here because its children
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment