diff options
Diffstat (limited to 'tests/ln')
-rwxr-xr-x | tests/ln/backup-1.sh | 30 | ||||
-rwxr-xr-x | tests/ln/hard-backup.sh | 32 | ||||
-rwxr-xr-x | tests/ln/hard-to-sym.sh | 83 | ||||
-rwxr-xr-x | tests/ln/misc.sh | 124 | ||||
-rwxr-xr-x | tests/ln/relative.sh | 53 | ||||
-rwxr-xr-x | tests/ln/sf-1.sh | 49 | ||||
-rwxr-xr-x | tests/ln/slash-decorated-nonexistent-dest.sh | 29 | ||||
-rwxr-xr-x | tests/ln/target-1.sh | 30 |
8 files changed, 430 insertions, 0 deletions
diff --git a/tests/ln/backup-1.sh b/tests/ln/backup-1.sh new file mode 100755 index 0000000..e325fd8 --- /dev/null +++ b/tests/ln/backup-1.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Try to create a symlink with backup where the destination file exists +# and the backup file name is a hard link to the destination file. + +# Copyright (C) 1999-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Based on a problem report from Jamie Lokier. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + +touch a b || framework_failure_ + +ln b b~ || fail=1 +ln -f --b=simple a b || fail=1 + +Exit $fail diff --git a/tests/ln/hard-backup.sh b/tests/ln/hard-backup.sh new file mode 100755 index 0000000..3dd602f --- /dev/null +++ b/tests/ln/hard-backup.sh @@ -0,0 +1,32 @@ +#!/bin/sh +# Ensure that 'ln --backup F F' gives a proper diagnostic. + +# Copyright (C) 2006-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + +touch f || framework_failure_ + + +ln --backup f f 2> out && fail=1 +cat <<\EOF > exp || framework_failure_ +ln: 'f' and 'f' are the same file +EOF + +compare exp out || fail=1 + +Exit $fail diff --git a/tests/ln/hard-to-sym.sh b/tests/ln/hard-to-sym.sh new file mode 100755 index 0000000..98b5deb --- /dev/null +++ b/tests/ln/hard-to-sym.sh @@ -0,0 +1,83 @@ +#!/bin/sh +# Tests for ln -L/-P. + +# Copyright (C) 2009-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + + +# =================================================== +# ensure -s silently overrides -L, -P +touch a || framework_failure_ +ln -L -s a symlink1 || fail=1 +ln -P -s symlink1 symlink2 || fail=1 +ln -s -L -P symlink2 symlink3 || fail=1 + +# =================================================== +# ensure that -L follows symlinks, and overrides -P +if ln -P -L symlink3 hard-to-a; then + ls=$(ls -lG hard-to-a)x + case "$ls" in + *'hard-to-ax') ;; + *'hard-to-a -> '*x) fail=1 ;; + *) framework_failure_ ;; + esac +else + fail=1 +fi + +# =================================================== +# ensure that -P links (or at least duplicates) symlinks, and overrides -L +if ln -L -P symlink3 hard-to-3; then + ls=$(ls -lG hard-to-3)x + case "$ls" in + *'hard-to-3 -> symlink2x') ;; + *'hard-to-3x') fail=1 ;; + *'hard-to-3 -> '*x) fail=1 ;; + *) framework_failure_ ;; + esac +else + fail=1 +fi + +# =================================================== +# Create a hard link to a dangling symlink. +ln -s /no-such-dir || framework_failure_ +ln -L no-such-dir hard-to-dangle 2>err && fail=1 +case $(cat err) in + *" failed to access 'no-such-dir'":*) ;; + *) fail=1 ;; +esac +ln -P no-such-dir hard-to-dangle || fail=1 + +# =================================================== +# Create a hard link to a symlink to a directory. +mkdir d || framework_failure_ +ln -s d link-to-dir || framework_failure_ +ln -L link-to-dir hard-to-dir-link 2>err && fail=1 +case $(cat err) in + *": link-to-dir: hard link not allowed for directory"*) ;; + *) fail=1 ;; +esac +ln -P link-to-dir/ hard-to-dir-link 2>err && fail=1 +case $(cat err) in + *": link-to-dir/: hard link not allowed for directory"*) ;; + *) fail=1 ;; +esac +ln -P link-to-dir hard-to-dir-link || fail=1 + +Exit $fail diff --git a/tests/ln/misc.sh b/tests/ln/misc.sh new file mode 100755 index 0000000..118cc93 --- /dev/null +++ b/tests/ln/misc.sh @@ -0,0 +1,124 @@ +#!/bin/sh +# Miscellaneous tests for "ln". + +# Copyright (C) 1998-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + +t=tln-symlink +d=tln-subdir +ld=tln-symlink-to-subdir +f=tln-file + +# Create a simple symlink with both source and destination files +# in current directory. +touch $f || framework_failure_ +rm -f $t || framework_failure_ +ln -s $f $t || fail=1 +test -f $t || fail=1 +rm $t $f + +# Create a symlink with source file and explicit destination directory/file. +touch $f || framework_failure_ +rm -rf $d || framework_failure_ +mkdir $d || framework_failure_ +ln -s ../$f $d/$t || fail=1 +test -f $d/$t || fail=1 +rm -rf $d $f + +# Create a symlink with source file and destination directory. +touch $f || framework_failure_ +rm -rf $d || framework_failure_ +mkdir $d || framework_failure_ +ln -s ../$f $d || fail=1 +test -f $d/$f || fail=1 +rm -rf $d $f + +# See whether a trailing slash is followed too far. +touch $f || framework_failure_ +rm -rf $d || framework_failure_ +mkdir $d $d/$f || framework_failure_ +returns_ 1 ln $f $d/ 2> /dev/null || fail=1 +returns_ 1 ln -s $f $d/ 2> /dev/null || fail=1 +rm -rf $d $f + +# Make sure we get a failure with existing dest without -f option +touch $t || framework_failure_ +# FIXME: don't ignore the error message but rather test +# it to make sure it's the right one. +returns_ 1 ln -s $t $t 2> /dev/null || fail=1 +rm $t + +# Make sure -sf fails when src and dest are the same +touch $t || framework_failure_ +returns_ 1 ln -sf $t $t 2> /dev/null || fail=1 +rm $t + +# Create a symlink with source file and no explicit directory +rm -rf $d || framework_failure_ +mkdir $d || framework_failure_ +touch $d/$f || framework_failure_ +ln -s $d/$f || fail=1 +test -f $f || fail=1 +rm -rf $d $f + +# Create a symlink with source file and destination symlink-to-directory. +rm -rf $d $f $ld || framework_failure_ +touch $f || framework_failure_ +mkdir $d || framework_failure_ +ln -s $d $ld +ln -s ../$f $ld || fail=1 +test -f $d/$f || fail=1 +rm -rf $d $f $ld + +# Create a symlink with source file and destination symlink-to-directory. +# BUT use the new --no-dereference option. +rm -rf $d $f $ld || framework_failure_ +touch $f || framework_failure_ +mkdir $d || framework_failure_ +ln -s $d $ld +af=$(pwd)/$f +ln --no-dereference -fs "$af" $ld || fail=1 +test -f $ld || fail=1 +rm -rf $d $f $ld + +# Try to create a symlink with backup where the destination file exists +# and the backup file name is a hard link to the destination file. +touch a b || framework_failure_ +ln b b~ || framework_failure_ +ln -f --b=simple a b || fail=1 + +# =================================================== + +# Make sure ln can make simple backups. +# This was fixed in 4.0.34. Broken in 4.0r. +for cmd in ln cp mv ginstall; do + rm -rf a x a.orig + touch a x || framework_failure_ + $cmd --backup=simple --suffix=.orig x a || fail=1 + test -f a.orig || fail=1 +done + +# =================================================== +# With coreutils-5.2.1, this would mistakenly access argv[1][-1]. +# I'm including it here, in case some day programs like valgrind detect that. +# Purify probably would have done so. +ln foo '' 2> /dev/null + +# =================================================== + +Exit $fail diff --git a/tests/ln/relative.sh b/tests/ln/relative.sh new file mode 100755 index 0000000..3b603a0 --- /dev/null +++ b/tests/ln/relative.sh @@ -0,0 +1,53 @@ +#!/bin/sh +# Test "ln --relative". + +# Copyright (C) 2012-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + +mkdir -p usr/bin || framework_failure_ +mkdir -p usr/lib/foo || framework_failure_ +touch usr/lib/foo/foo || framework_failure_ + +ln -sr usr/lib/foo/foo usr/bin/foo +test $(readlink usr/bin/foo) = '../lib/foo/foo' || fail=1 + +ln -sr usr/bin/foo usr/lib/foo/link-to-foo +test $(readlink usr/lib/foo/link-to-foo) = 'foo' || fail=1 + +# Correctly update an existing link, which was broken in <= 8.21 +ln -s dir1/dir2/f existing_link +ln -srf here existing_link +test $(readlink existing_link) = 'here' || fail=1 + +# Demonstrate resolved symlinks used to generate relative links +# so here, 'web/latest' will not be linked to the intermediate 'latest' link. +# You'd probably want to use realpath(1) in conjunction +# with ln(1) without --relative to give greater control. +ln -s release1 alpha +ln -s release2 beta +ln -s beta latest +mkdir web +ln -sr latest web/latest +test $(readlink web/latest) = '../release2' || fail=1 + +# Expect this to fail with exit status 1, or to succeed quietly (freebsd). +# Prior to coreutils-8.23, it would segfault. +ln -sr '' F +case $? in [01]) ;; *) fail=1;; esac + +Exit $fail diff --git a/tests/ln/sf-1.sh b/tests/ln/sf-1.sh new file mode 100755 index 0000000..cb1629a --- /dev/null +++ b/tests/ln/sf-1.sh @@ -0,0 +1,49 @@ +#!/bin/sh +# Test "ln -sf". + +# Copyright (C) 1997-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + +echo foo > a || framework_failure_ + +# Check that a target directory of '.' is supported +# and that indirectly specifying the same target and link name +# through that is detected. +ln -s . b || framework_failure_ +ln -sf a b > err 2>&1 && fail=1 +case $(cat err) in + *'are the same file') ;; + *) fail=1 ;; +esac + +# Ensure we replace symlinks that don't or can't link to an existing target. +# coreutils-8.22 would fail to replace {ENOTDIR,ELOOP,ENAMETOOLONG}_link below. +# We apply a limit since AIX returns 2^32-1 which would trigger resource issues. +name_max=$(stat -f -c %l .) && test "$name_max" -lt $((1024*1024)) || + name_max=1 # skip this portion of the test +name_max_plus1=$(expr $name_max + 1) +long_name=$(printf '%*s' $name_max_plus1 | tr ' ' '0') + +for f in '' f; do + ln -s$f missing ENOENT_link || fail=1 + ln -s$f a/b ENOTDIR_link || fail=1 + ln -s$f ELOOP_link ELOOP_link || fail=1 + ln -s$f "$long_name" ENAMETOOLONG_link || fail=1 +done + +Exit $fail diff --git a/tests/ln/slash-decorated-nonexistent-dest.sh b/tests/ln/slash-decorated-nonexistent-dest.sh new file mode 100755 index 0000000..156e65c --- /dev/null +++ b/tests/ln/slash-decorated-nonexistent-dest.sh @@ -0,0 +1,29 @@ +#!/bin/sh +# ensure that touch f; ln -T f no-such-file/ does not mistakenly succeed + +# Copyright (C) 2009-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + +touch f || framework_failure_ + + +# Before coreutils-7.6, this would succeed on Solaris 10 +returns_ 1 ln -T f no-such-file/ || fail=1 +test -e no-such-file && fail=1 + +Exit $fail diff --git a/tests/ln/target-1.sh b/tests/ln/target-1.sh new file mode 100755 index 0000000..327dec6 --- /dev/null +++ b/tests/ln/target-1.sh @@ -0,0 +1,30 @@ +#!/bin/sh +# Test "ln --target-dir" with one file. + +# Copyright (C) 2002-2018 Free Software Foundation, Inc. + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <https://www.gnu.org/licenses/>. + +# Before coreutils-4.5.3, --target-dir didn't work with one file. +# It would create the desired link, but would fail with a diagnosis like this: +# ln: 'd/.': cannot overwrite directory +# Based on a test case from Dmitry V. Levin. + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ ln + +mkdir d || framework_failure_ +ln -s --target-dir=d ../f || fail=1 + +Exit $fail |