diff --git a/llvm/utils/lit/lit/TestRunner.py b/llvm/utils/lit/lit/TestRunner.py index f8e1c58d7671f..9ae8ac75bee08 100644 --- a/llvm/utils/lit/lit/TestRunner.py +++ b/llvm/utils/lit/lit/TestRunner.py @@ -516,7 +516,9 @@ def on_rm_error(func, path, exc_info): if force and not os.path.exists(path): continue try: - if os.path.isdir(path): + if os.path.islink(path): + os.remove(path) + elif os.path.isdir(path): if not recursive: stderr.write("Error: %s is a directory\n" % path) exitCode = 1 diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/lit.cfg new file mode 100644 index 0000000000000..eab06f08b688c --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/lit.cfg @@ -0,0 +1,7 @@ +import lit.formats + +config.name = "shtest-shell" +config.suffixes = [".txt"] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/rm-symlink-dir.txt b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/rm-symlink-dir.txt new file mode 100644 index 0000000000000..a44a07c13e4ae --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-shell-symlinks/rm-symlink-dir.txt @@ -0,0 +1,5 @@ +# Check that we can delete a symlink to a folder without -r +# +# RUN: mkdir %t.dir +# RUN: ln -s %t.dir %t.symlink +# RUN: rm %t.symlink diff --git a/llvm/utils/lit/tests/shtest-shell-symlinks.py b/llvm/utils/lit/tests/shtest-shell-symlinks.py new file mode 100644 index 0000000000000..cfd72a01b6d94 --- /dev/null +++ b/llvm/utils/lit/tests/shtest-shell-symlinks.py @@ -0,0 +1,9 @@ +# Check that the internal shell builtins correctly handle cases involving +# symlinks. + +# REQUIRES: symlinks +# RUN: echo test +# RUN: %{lit} -v %{inputs}/shtest-shell-symlinks | FileCheck %s + +# CHECK: -- Testing: 1 test{{.*}} +# CHECK: PASS: shtest-shell :: rm-symlink-dir.txt