sharness: fix the 'useful error message when adding a named pipe' test
We were removing the file before testing, ignoring the error from stat, and then grepping for `Error: Unrecognized file type for named-pipe: ` (because nothing was sent to stdout). This fix: 1. Changes our stat command to output failed to stdout on failure to ensure that bugs like this *can't* happen. 2. Checks to make sure stat actually succeeds. License: MIT Signed-off-by: Steven Allen <steven@stebalien.com>
Steven Allen committed
Jul 31, 2017 at 18:25 UTC
39197ff8d3d2a9f8197d486592b1fc7518008a5d
2 files changed
+5
-3
test/sharness/lib/test-lib.sh
+1
-1
@@ -364,7 +364,7 @@ generic_stat() {
364
_STAT="stat -f %Sp"
365
;;
366
esac
367
- $_STAT "$1"
367
+ $_STAT "$1" || echo "failed" # Avoid returning nothing.
368
}
369
370
test_check_peerid() {
test/sharness/t0040-add-and-cat.sh
+4
-2
@@ -192,8 +192,9 @@ test_add_named_pipe() {
192
test_expect_success "useful error message when adding a named pipe" '
193
mkfifo named-pipe &&
194
test_expect_code 1 ipfs add named-pipe 2>actual &&
195
+ STAT=$(generic_stat named-pipe) &&
196
rm named-pipe &&
196
- grep "Error: Unrecognized file type for named-pipe: $(generic_stat named-pipe)" actual &&
197
+ grep "Error: Unrecognized file type for named-pipe: $STAT" actual &&
198
grep USAGE actual &&
199
grep "ipfs add" actual
200
'
@@ -201,8 +202,9 @@ test_add_named_pipe() {
202
test_expect_success "useful error message when recursively adding a named pipe" '
203
mkdir -p named-pipe-dir &&
204
mkfifo named-pipe-dir/named-pipe &&
205
+ STAT=$(generic_stat named-pipe-dir/named-pipe) &&
206
test_expect_code 1 ipfs add -r named-pipe-dir 2>actual &&
205
- printf "Error:$err_prefix Unrecognized file type for named-pipe-dir/named-pipe: $(generic_stat named-pipe-dir/named-pipe)\n" >expected &&
207
+ printf "Error:$err_prefix Unrecognized file type for named-pipe-dir/named-pipe: $STAT\n" >expected &&
208
rm named-pipe-dir/named-pipe &&
209
rmdir named-pipe-dir &&
210
test_cmp expected actual