Mercurial > hg > toybox
view tests/readlink.test @ 1572:da1bf31ed322 draft
Tweak the "ignoring return value" fortify workaround for readlinkat.
We zero the buffer and if the link read fails that's left alone, so
it's ok for the symlink not to be there. Unfortunately, typecasting the
return value to (void) doesn't shut up gcc, and having an if(); with the
semicolon on the same line doesn't shut up llvm. (The semicolon on a new
line would, but C does not have significant whitespace and I'm not going
to humor llvm if it plans to start.)
So far, empty curly brackets consistently get the warning to shut up.
author | Rob Landley <rob@landley.net> |
---|---|
date | Mon, 24 Nov 2014 17:23:23 -0600 |
parents | 8700cbe1cb29 |
children |
line wrap: on
line source
#!/bin/bash [ -f testing.sh ] && . testing.sh #testing "name" "command" "result" "infile" "stdin" APWD="$(pwd -P)" testing "readlink missing" "readlink notfound || echo yes" "yes\n" "" "" # simple tests on a file touch file testing "readlink file" "readlink file || echo yes" "yes\n" "" "" testing "readlink -f dir" "readlink -f ." "$APWD\n" "" "" testing "readlink -f missing" "readlink -f notfound" "$APWD/notfound\n" "" "" ln -sf notfound link testing "readlink link" "readlink link" "notfound\n" "" "" testing "readlink link->missing" "readlink -f link" "$APWD/notfound\n" "" "" ln -sf ../../ link testing "readlink stays relative" "readlink link" "../../\n" "" "" rm link ln -sf file link testing "readlink -f link->file" "readlink -f link" "$APWD/file\n" "" "" ln -sf . link testing "readlink -f link->dir" "readlink -f link" "$APWD\n" "" "" ln -snf link link testing "readlink link->link (recursive)" "readlink link" "link\n" "" "" testing "readlink -f link->link (recursive)" \ "readlink -f link 2>/dev/null || echo yes" "yes\n" "" "" testing "readlink -q notlink" "readlink -q file || echo yes" "yes\n" "" "" testing "readlink -q link" "readlink -q link && echo yes" "yes\n" "" "" testing "readlink -q notfound" "readlink -q notfound || echo yes" "yes\n" "" "" testing "readlink -e found" "readlink -e file" "$APWD/file\n" "" "" testing "readlink -e notfound" \ "readlink -e notfound 2>/dev/null || echo yes" "yes\n" "" "" testing "readlink -nf ." "readlink -nf ." "$APWD" "" "" mkdir sub && ln -s . here && ln -s ./sub dir && touch sub/bang || exit 1 testing "readlink -f multi" "readlink -f dir/../here/dir/bang" \ "$APWD/sub/bang\n" "" "" testing "readlink -f link/missing" "readlink -f dir/boing" \ "$APWD/sub/boing\n" "" "" testing "readlink -f /dev/null/file" \ "readlink -f /dev/null/file 2>/dev/null || echo yes" "yes\n" "" "" ln -sf / link || exit 1 testing "readlink -f link->/" "readlink -e link/dev" "/dev\n" "" "" testing "readlink -f /dev/null/.." \ "readlink -f link/null/.. 2>/dev/null || echo yes" "yes\n" "" "" rm -f link && ln -sf link link || exit 1 testing "readlink recurse" "readlink link" "link\n" "" "" rm file link sub/bang dir here rmdir sub # Make sure circular links don't run away. ln -s link1 link2 ln -s link2 link1 testing "readlink follow recursive2" "readlink -f link1 || echo yes" \ "yes\n" "" "" rm link1 link2