@cryptotaxi247 / kubo / commits / 531f0579a

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

License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com> sharness: Don't assume we know all things that can create garbage License: MIT Signed-off-by: Jeromy <jeromyj@gmail.com>

Tommi Virtanen committed May 11, 2015 at 10:29 UTC 531f0579a41ede15c948b9e278b154895813ae08
3 files changed +39 -5
test/ipfs-test-lib.sh
+35
@@ -62,3 +62,38 @@ docker_exec() {
62 docker_stop() {
63 docker stop "$1"
64 }
65 +
66 +# Test whether all the expected lines are included in a file. The file
67 +# can have extra lines.
68 +#
69 +# $1 - Path to file with expected lines.
70 +# $2 - Path to file with actual output.
71 +#
72 +# Examples
73 +#
74 +# test_expect_success 'foo says hello' '
75 +# echo hello >expected &&
76 +# foo >actual &&
77 +# test_cmp expected actual
78 +# '
79 +#
80 +# Returns the exit code of the command set by TEST_CMP.
81 +test_includes_lines() {
82 + sort "$1" >"$1_sorted" &&
83 + sort "$2" >"$2_sorted" &&
84 + comm -2 -3 "$1_sorted" "$2_sorted" >"$2_missing" &&
85 + [ ! -s "$2_missing" ] || test_fsh comm -2 -3 "$1_sorted" "$2_sorted"
86 +}
87 +
88 +# Depending on GNU seq availability is not nice.
89 +# Git also has test_seq but it uses Perl.
90 +test_seq() {
91 + test "$1" -le "$2" || return
92 + i="$1"
93 + j="$2"
94 + while test "$i" -le "$j"
95 + do
96 + echo "$i"
97 + i=$(expr "$i" + 1)
98 + done
99 +}
test/sharness/t0080-repo.sh
+2 -2
@@ -114,8 +114,8 @@ test_expect_success "remove direct pin" '
114 '
115
116 test_expect_success "'ipfs repo gc' removes file" '
117 - echo "removed $PATCH_ROOT" >expected7 &&
118 - echo "removed $HASH" >>expected7 &&
117 + echo "removed $HASH" >expected7 &&
118 + echo "removed $PATCH_ROOT" >>expected7 &&
119 ipfs repo gc >actual7 &&
120 test_sort_cmp expected7 actual7
121 '
test/sharness/t0081-repo-pinning.sh
+2 -3
@@ -150,8 +150,7 @@ test_expect_success "nothing is pinned directly" '
150 '
151
152 test_expect_success "'ipfs repo gc' succeeds" '
153 - ipfs repo gc >gc_out_actual &&
154 - test_must_be_empty gc_out_actual
153 + ipfs repo gc >gc_out_actual
154 '
155
156 test_expect_success "objects are still there" '
@@ -217,7 +216,7 @@ test_expect_success "'ipfs repo gc' succeeds" '
216 echo "removed $HASH_FILE3" > gc_out_exp2 &&
217 echo "removed $HASH_FILE5" >> gc_out_exp2 &&
218 echo "removed $HASH_DIR3" >> gc_out_exp2 &&
220 - test_sort_cmp gc_out_exp2 gc_out_actual2
219 + test_includes_lines gc_out_exp2 gc_out_actual2
220 '
221
222 # use object links for HASH_DIR1 here because its children