toybox/tests/realpath.test
<<
>>
Prefs
   1#!/bin/bash
   2
   3[ -f testing.sh ] && . testing.sh
   4
   5#testing "name" "command" "result" "infile" "stdin"
   6
   7TOP="$(readlink -f .)"
   8
   9testcmd '' '.' "$TOP\n" '' ''
  10#testcmd '-z' '-z . | tr "\0" X' "${TOP}X" '' ''
  11touch file
  12testcmd 'file' 'file' "$TOP/file\n" '' ''
  13mkdir -p one/two/three
  14testcmd 'dir' 'one/two/three' "$TOP/one/two/three\n" '' ''
  15#testcmd '--relative-to' '. --relative-to=one/two/three' '../../..\n' '' ''
  16#testcmd '--relative-base' 'one one/two one/two/three --relative-base=one/two' \
  17#  "$TOP/one\n.\nthree\n" '' ''
  18#testcmd '--relative-base stomps --relative-to' \
  19#  '--relative-to=.. --relative-base=one/two one' "$TOP/one\n" '' ''
  20testcmd 'missing defaults to -m' 'missing' "$TOP/missing\n" '' ''
  21testcmd 'missing -e' '-e missing 2>/dev/null || echo ok' 'ok\n' '' ''
  22
  23# The -s tests use $PWD instead of $TOP because symlinks in path _to_ here
  24# should not be resolved either. The shell exports $PWD: use it.
  25ln -s ./one uno
  26#testcmd '-s' '-s uno/two' "$PWD/uno/two\n" '' ''
  27ln -s one/two dos
  28#testcmd '-s link/..' '-es dos/three' "$PWD/dos/three\n" '' ''
  29#testcmd '-s .. eats symlink' '-s dos/..' "$PWD\n" '' ''
  30# In toybox this test is consistent with the previous one
  31#toyonly testing '-s .. eats symlink in $PWD' \
  32#  'cd dos && realpath -s ..' "$PWD\n" '' ''
  33# Logically -es means the _symlink_ should exist, but match behavior...
  34ln -s missing dangling
  35#testcmd '-es dangling symlink' '-es dangling 2>/dev/null || echo ok' \
  36#  'ok\n' '' ''
  37#testcmd '-ms' '-ms dangling/../dos/../one/two' "$PWD/one/two\n" '' ''
  38ln -s ../two/.. one/two/ichi
  39#testcmd '-es' '-es one/two/ichi/two/ichi/two' "$PWD/one/two/ichi/two/ichi/two\n" '' ''
  40