Skip to content

Commit b6c596f

Browse files
committed
Merge branch 'cg/t3903-modernize'
Test modernization. * cg/t3903-modernize: tests: make the code more readable tests: allow testing if a path is truly a file or a directory t/t3903-stash.sh: replace test [-d|-f] with test_path_is_*
2 parents 715d08a + cc143f1 commit b6c596f

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

t/t3903-stash.sh

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -390,21 +390,23 @@ test_expect_success SYMLINKS 'stash file to symlink' '
390390
rm file &&
391391
ln -s file2 file &&
392392
git stash save "file to symlink" &&
393-
test -f file &&
393+
test_path_is_file_not_symlink file &&
394394
test bar = "$(cat file)" &&
395395
git stash apply &&
396-
case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
396+
test_path_is_symlink file &&
397+
test "$(test_readlink file)" = file2
397398
'
398399

399400
test_expect_success SYMLINKS 'stash file to symlink (stage rm)' '
400401
git reset --hard &&
401402
git rm file &&
402403
ln -s file2 file &&
403404
git stash save "file to symlink (stage rm)" &&
404-
test -f file &&
405+
test_path_is_file_not_symlink file &&
405406
test bar = "$(cat file)" &&
406407
git stash apply &&
407-
case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
408+
test_path_is_symlink file &&
409+
test "$(test_readlink file)" = file2
408410
'
409411

410412
test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
@@ -413,10 +415,11 @@ test_expect_success SYMLINKS 'stash file to symlink (full stage)' '
413415
ln -s file2 file &&
414416
git add file &&
415417
git stash save "file to symlink (full stage)" &&
416-
test -f file &&
418+
test_path_is_file_not_symlink file &&
417419
test bar = "$(cat file)" &&
418420
git stash apply &&
419-
case "$(ls -l file)" in *" file -> file2") :;; *) false;; esac
421+
test_path_is_symlink file &&
422+
test "$(test_readlink file)" = file2
420423
'
421424

422425
# This test creates a commit with a symlink used for the following tests
@@ -487,7 +490,7 @@ test_expect_failure 'stash directory to file' '
487490
rm -fr dir &&
488491
echo bar >dir &&
489492
git stash save "directory to file" &&
490-
test -d dir &&
493+
test_path_is_dir dir &&
491494
test foo = "$(cat dir/file)" &&
492495
test_must_fail git stash apply &&
493496
test bar = "$(cat dir)" &&
@@ -500,10 +503,10 @@ test_expect_failure 'stash file to directory' '
500503
mkdir file &&
501504
echo foo >file/file &&
502505
git stash save "file to directory" &&
503-
test -f file &&
506+
test_path_is_file file &&
504507
test bar = "$(cat file)" &&
505508
git stash apply &&
506-
test -f file/file &&
509+
test_path_is_file file/file &&
507510
test foo = "$(cat file/file)"
508511
'
509512

t/test-lib-functions.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,16 @@ test_path_is_file () {
856856
fi
857857
}
858858

859+
test_path_is_file_not_symlink () {
860+
test "$#" -ne 1 && BUG "1 param"
861+
test_path_is_file "$1" &&
862+
if test -h "$1"
863+
then
864+
echo "$1 shouldn't be a symbolic link"
865+
false
866+
fi
867+
}
868+
859869
test_path_is_dir () {
860870
test "$#" -ne 1 && BUG "1 param"
861871
if ! test -d "$1"
@@ -865,6 +875,16 @@ test_path_is_dir () {
865875
fi
866876
}
867877

878+
test_path_is_dir_not_symlink () {
879+
test "$#" -ne 1 && BUG "1 param"
880+
test_path_is_dir "$1" &&
881+
if test -h "$1"
882+
then
883+
echo "$1 shouldn't be a symbolic link"
884+
false
885+
fi
886+
}
887+
868888
test_path_exists () {
869889
test "$#" -ne 1 && BUG "1 param"
870890
if ! test -e "$1"
@@ -874,6 +894,15 @@ test_path_exists () {
874894
fi
875895
}
876896

897+
test_path_is_symlink () {
898+
test "$#" -ne 1 && BUG "1 param"
899+
if ! test -h "$1"
900+
then
901+
echo "Symbolic link $1 doesn't exist"
902+
false
903+
fi
904+
}
905+
877906
# Check if the directory exists and is empty as expected, barf otherwise.
878907
test_dir_is_empty () {
879908
test "$#" -ne 1 && BUG "1 param"

0 commit comments

Comments
 (0)