blob: 27b52f6c4b025e1c0b773bd184f531570bfdbb50 [file] [log] [blame]
Rob Landleyc008c742006-05-05 21:07:41 +00001#!/bin/sh
2
3# Readlink tests.
4# Copyright 2006 by Natanael Copa <n@tanael.org>
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02005# Licensed under GPLv2, see file LICENSE in this source tree.
Rob Landleyc008c742006-05-05 21:07:41 +00006
Mike Frysingercaa79402009-11-04 18:41:22 -05007. ./testing.sh
Rob Landleyc008c742006-05-05 21:07:41 +00008
9TESTDIR=readlink_testdir
10TESTFILE="$TESTDIR/testfile"
11TESTLINK="testlink"
12FAILLINK="$TESTDIR/$TESTDIR/testlink"
13
14# create the dir and test files
15mkdir -p "./$TESTDIR"
16touch "./$TESTFILE"
17ln -s "./$TESTFILE" "./$TESTLINK"
18
19testing "readlink on a file" "readlink ./$TESTFILE" "" "" ""
20testing "readlink on a link" "readlink ./$TESTLINK" "./$TESTFILE\n" "" ""
Rob Landley42bd9872006-05-05 22:22:30 +000021
22optional FEATURE_READLINK_FOLLOW
23
Denys Vlasenko69c8c692015-10-11 16:27:55 +020024# shell's $PWD may leave symlinks unresolved.
25# "pwd" may be a built-in and have the same problem.
26# External pwd _can't_ have that problem (current dir on Unix is physical).
27pwd=`which pwd`
28pwd=`$pwd`
29testing "readlink -f on a file" "readlink -f ./$TESTFILE" "$pwd/$TESTFILE\n" "" ""
30testing "readlink -f on a link" "readlink -f ./$TESTLINK" "$pwd/$TESTFILE\n" "" ""
Rob Landleyc008c742006-05-05 21:07:41 +000031testing "readlink -f on an invalid link" "readlink -f ./$FAILLINK" "" "" ""
Denys Vlasenko10ad6222017-04-17 16:13:32 +020032testing "readlink -f on a weird dir" "readlink -f $TESTDIR/../$TESTFILE" "$pwd/$TESTFILE\n" "" ""
Rob Landleyc008c742006-05-05 21:07:41 +000033
34
35# clean up
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000036rm -r "$TESTLINK" "$TESTDIR"
Dan Fandrich140ac912010-08-29 04:47:03 +020037
38exit $((FAILCOUNT <= 255 ? FAILCOUNT : 255))