Add a littlcheck glob test

We have some glob tests in fish_tests.cpp, but they are hard to follow.
Begin migrating them
This commit is contained in:
ridiculousfish 2020-12-28 13:09:28 -08:00
parent df73964ced
commit 6c08141682

79
tests/checks/glob.fish Normal file
View File

@ -0,0 +1,79 @@
# RUN: %fish %s
cd (mktemp -d)
set tmpdir (pwd -P)
# Hidden files are only matched with explicit dot.
touch .hidden visible
string join \n * | sort
# CHECK: visible
string join \n .* | sort
# CHECK: .hidden
rm -Rf .hidden visible
# Trailing slash matches only directories.
touch abc1
mkdir abc2
string join \n * | sort
# CHECK: abc1
# CHECK: abc2
string join \n */ | sort
# CHECK: abc2/
rm -Rf *
# Symlinks are descended into independently.
# Here dir2/link2 is symlinked to dir1/child1.
# The contents of dir2 will be explored twice.
mkdir -p dir1/child1
touch dir1/child1/anyfile
mkdir dir2
ln -s ../dir1/child1 dir2/link2
string join \n **/anyfile | sort
# CHECK: dir1/child1/anyfile
# CHECK: dir2/link2/anyfile
# But symlink loops only get explored once.
mkdir -p dir1/child2/grandchild1
touch dir1/child2/grandchild1/differentfile
ln -s ../../child2/grandchild1 dir1/child2/grandchild1/link2
echo **/differentfile
# CHECK: dir1/child2/grandchild1/differentfile
rm -Rf *
# Recursive globs handling.
mkdir -p dir_a1/dir_a2/dir_a3
touch dir_a1/dir_a2/dir_a3/file_a
mkdir -p dir_b1/dir_b2/dir_b3
touch dir_b1/dir_b2/dir_b3/file_b
string join \n **/file_* | sort
# CHECK: dir_a1/dir_a2/dir_a3/file_a
# CHECK: dir_b1/dir_b2/dir_b3/file_b
string join \n **a3/file_* | sort
# CHECK: dir_a1/dir_a2/dir_a3/file_a
string join \n ** | sort
# CHECK: dir_a1
# CHECK: dir_a1/dir_a2
# CHECK: dir_a1/dir_a2/dir_a3
# CHECK: dir_a1/dir_a2/dir_a3/file_a
# CHECK: dir_b1
# CHECK: dir_b1/dir_b2
# CHECK: dir_b1/dir_b2/dir_b3
# CHECK: dir_b1/dir_b2/dir_b3/file_b
string join \n **/ | sort
# CHECK: dir_a1/
# CHECK: dir_a1/dir_a2/
# CHECK: dir_a1/dir_a2/dir_a3/
# CHECK: dir_b1/
# CHECK: dir_b1/dir_b2/
# CHECK: dir_b1/dir_b2/dir_b3/
string join \n **a2/** | sort
# CHECK: dir_a1/dir_a2/dir_a3
# CHECK: dir_a1/dir_a2/dir_a3/file_a
# Clean up.
cd $HOME
rm -Rf $tmpdir