From 9aa39ab5f09902f5393545c17d3d0be452eb6df1 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 1 Aug 2021 14:27:47 -0500 Subject: [PATCH] First guess at realpath tests. --- tests/realpath.test | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 tests/realpath.test diff --git a/tests/realpath.test b/tests/realpath.test new file mode 100755 index 00000000..e4423eda --- /dev/null +++ b/tests/realpath.test @@ -0,0 +1,39 @@ +#!/bin/bash + +[ -f testing.sh ] && . testing.sh + +#testing "name" "command" "result" "infile" "stdin" + +TOP="$(readlink -f .)" + +testcmd '' '.' "$TOP\n" '' '' +testcmd '-z' '-z . | tr "\0" X' "${TOP}X" '' '' +touch file +testcmd 'file' 'file' "$TOP/file\n" '' '' +mkdir -p one/two/three +testcmd 'dir' 'one/two/three' "$TOP/one/two/three\n" '' '' +testcmd '--relative-to' '. --relative-to=one/two/three' '../../..\n' '' '' +testcmd '--relative-base' 'one one/two one/two/three --relative-base=one/two' \ + "$TOP/one\n.\nthree\n" '' '' +testcmd '--relative-base stomps --relative-to' \ + '--relative-to=.. --relative-base=one/two one' "$TOP/one\n" '' '' +testcmd 'missing defaults to -m' 'missing' "$TOP/missing\n" '' '' +testcmd 'missing -e' '-e missing 2>/dev/null || echo ok' 'ok\n' '' '' + +# The -s tests use $PWD instead of $TOP because symlinks in path _to_ here +# should not be resolved either. The shell exports $PWD: use it. +ln -s ./one uno +testcmd '-s' '-s uno/two' "$PWD/uno/two\n" '' '' +ln -s one/two dos +testcmd '-s link/..' '-es dos/three' "$PWD/dos/three\n" '' '' +testcmd '-s .. eats symlink' '-s dos/..' "$PWD\n" '' '' +# In toybox this test is consistent with the previous one +toyonly testing '-s .. eats symlink in $PWD' \ + 'cd dos && realpath -s ..' "$PWD\n" '' '' +# Logically -es means the _symlink_ should exist, but match behavior... +ln -s missing dangling +testcmd '-es dangling symlink' '-es dangling 2>/dev/null || echo ok' \ + 'ok\n' '' '' +testcmd '-ms' '-ms dangling/../dos/../one/two' "$PWD/one/two\n" '' '' +ln -s ../two/.. one/two/ichi +testcmd '-es' '-es one/two/ichi/two/ichi/two' "$PWD/one/two/ichi/two/ichi/two\n" '' '' -- 2.39.2