summaryrefslogtreecommitdiff
path: root/utils/lit/tests
diff options
context:
space:
mode:
authorYing Yi <maggieyi666@gmail.com>2017-11-23 12:48:41 +0000
committerYing Yi <maggieyi666@gmail.com>2017-11-23 12:48:41 +0000
commitda18ebeb4eb31f10379a83920f5a27bdc9e35d46 (patch)
tree994db0e1b655d3c62a809e8a5a27bbe3e360d44c /utils/lit/tests
parent30e25c33bc96066d1ed550e870a86b88766b97f1 (diff)
[lit] Implement non-pipelined ‘mkdir’, ‘diff’ and ‘rm’ commands internally
Summary: The internal shell already supports 'cd', ‘export’ and ‘echo’ commands. This patch adds implementation of non-pipelined ‘mkdir’, ‘diff’ and ‘rm’ commands as the internal shell builtins. Reviewers: Zachary Turner, Reid Kleckner Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D39567 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@318911 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/lit/tests')
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/check_path.py28
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/diff-error-0.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/diff-error-1.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/diff-error-2.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/diff-error-3.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/diff-error-4.txt5
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/diff-error-5.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/diff-error-6.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/mkdir-error-0.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/mkdir-error-1.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/mkdir-error-2.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/rm-error-0.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/rm-error-1.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/rm-error-2.txt3
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/rm-error-3.txt4
-rw-r--r--utils/lit/tests/Inputs/shtest-shell/valid-shell.txt83
-rw-r--r--utils/lit/tests/max-failures.py2
-rw-r--r--utils/lit/tests/shtest-shell.py117
18 files changed, 273 insertions, 2 deletions
diff --git a/utils/lit/tests/Inputs/shtest-shell/check_path.py b/utils/lit/tests/Inputs/shtest-shell/check_path.py
new file mode 100644
index 00000000000..c1d279700de
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/check_path.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+
+import os
+import sys
+
+
+def check_path(argv):
+ if len(argv) < 3:
+ print("Wrong number of args")
+ return 1
+
+ type = argv[1]
+ paths = argv[2:]
+ exit_code = 0
+
+ if type == 'dir':
+ for idx, dir in enumerate(paths):
+ print(os.path.isdir(dir))
+ elif type == 'file':
+ for idx, file in enumerate(paths):
+ print(os.path.isfile(file))
+ else:
+ print("Unrecognised type {}".format(type))
+ exit_code = 1
+ return exit_code
+
+if __name__ == '__main__':
+ sys.exit (check_path (sys.argv))
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-error-0.txt b/utils/lit/tests/Inputs/shtest-shell/diff-error-0.txt
new file mode 100644
index 00000000000..81888cf8197
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/diff-error-0.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported diff (cannot be part of a pipeline).
+#
+# RUN: diff diff-error-0.txt diff-error-0.txt | echo Output
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-error-1.txt b/utils/lit/tests/Inputs/shtest-shell/diff-error-1.txt
new file mode 100644
index 00000000000..9836e0ea9d4
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/diff-error-1.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported diff (not support the -B option).
+#
+# RUN: diff -B temp1.txt temp2.txt
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-error-2.txt b/utils/lit/tests/Inputs/shtest-shell/diff-error-2.txt
new file mode 100644
index 00000000000..9c0da6aa6f6
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/diff-error-2.txt
@@ -0,0 +1,3 @@
+# Check error on an internal shell error (missing tofile)
+#
+# RUN: diff temp.txt
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-error-3.txt b/utils/lit/tests/Inputs/shtest-shell/diff-error-3.txt
new file mode 100644
index 00000000000..31128193c01
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/diff-error-3.txt
@@ -0,0 +1,3 @@
+# Check error on an internal shell error (unable to find compared files)
+#
+# RUN: diff temp.txt temp1.txt
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-error-4.txt b/utils/lit/tests/Inputs/shtest-shell/diff-error-4.txt
new file mode 100644
index 00000000000..84e17ec3a0c
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/diff-error-4.txt
@@ -0,0 +1,5 @@
+# Check error on an internal shell error (file's contexts are different)
+#
+# RUN: echo "hello-first" > %t
+# RUN: echo "hello-second" > %t1
+# RUN: diff %t %t1
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-error-5.txt b/utils/lit/tests/Inputs/shtest-shell/diff-error-5.txt
new file mode 100644
index 00000000000..6d8d2e5c334
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/diff-error-5.txt
@@ -0,0 +1,3 @@
+# Check error on an internal shell error (missing operand)
+#
+# RUN: diff -u
diff --git a/utils/lit/tests/Inputs/shtest-shell/diff-error-6.txt b/utils/lit/tests/Inputs/shtest-shell/diff-error-6.txt
new file mode 100644
index 00000000000..cc13d13c647
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/diff-error-6.txt
@@ -0,0 +1,3 @@
+# Check error on an internal shell error (extra operand)
+#
+# RUN: diff -u a.txt b.txt c.txt
diff --git a/utils/lit/tests/Inputs/shtest-shell/mkdir-error-0.txt b/utils/lit/tests/Inputs/shtest-shell/mkdir-error-0.txt
new file mode 100644
index 00000000000..c29d4211067
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/mkdir-error-0.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported mkdir (cannot be part of a pipeline).
+#
+# RUN: mkdir -p temp | rm -rf temp
diff --git a/utils/lit/tests/Inputs/shtest-shell/mkdir-error-1.txt b/utils/lit/tests/Inputs/shtest-shell/mkdir-error-1.txt
new file mode 100644
index 00000000000..8931f3d54eb
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/mkdir-error-1.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported mkdir (only does not support -m option).
+#
+# RUN: mkdir -p -m 777 temp
diff --git a/utils/lit/tests/Inputs/shtest-shell/mkdir-error-2.txt b/utils/lit/tests/Inputs/shtest-shell/mkdir-error-2.txt
new file mode 100644
index 00000000000..401dbecf14b
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/mkdir-error-2.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported mkdir (missing operand).
+#
+# RUN: mkdir -p
diff --git a/utils/lit/tests/Inputs/shtest-shell/rm-error-0.txt b/utils/lit/tests/Inputs/shtest-shell/rm-error-0.txt
new file mode 100644
index 00000000000..52966a813c4
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/rm-error-0.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported rm. (cannot be part of a pipeline)
+#
+# RUN: rm -rf temp | echo "hello"
diff --git a/utils/lit/tests/Inputs/shtest-shell/rm-error-1.txt b/utils/lit/tests/Inputs/shtest-shell/rm-error-1.txt
new file mode 100644
index 00000000000..5065ea74420
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/rm-error-1.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported rm (only does not support -v option).
+#
+# RUN: rm -f -v temp
diff --git a/utils/lit/tests/Inputs/shtest-shell/rm-error-2.txt b/utils/lit/tests/Inputs/shtest-shell/rm-error-2.txt
new file mode 100644
index 00000000000..d638a792d57
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/rm-error-2.txt
@@ -0,0 +1,3 @@
+# Check error on a unsupported rm (only supports -f option and in combination with -r).
+#
+# RUN: rm -r hello
diff --git a/utils/lit/tests/Inputs/shtest-shell/rm-error-3.txt b/utils/lit/tests/Inputs/shtest-shell/rm-error-3.txt
new file mode 100644
index 00000000000..1bab79aad08
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/rm-error-3.txt
@@ -0,0 +1,4 @@
+# Check error on a unsupported rm (can't remove test since it is a directory).
+#
+# RUN: mkdir -p test
+# RUN: rm -f test
diff --git a/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt b/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt
new file mode 100644
index 00000000000..633098eab59
--- /dev/null
+++ b/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt
@@ -0,0 +1,83 @@
+# Check rm file operations.
+# Check force remove commands success whether the file does or doesn't exist.
+#
+# RUN: rm -f %t.write
+# RUN: "%{python}" %S/check_path.py file %t.write > %t.out
+# RUN: FileCheck --check-prefix=REMOVE-FILE < %t.out %s
+# RUN: echo "create a temp file" > %t.write
+# RUN: "%{python}" %S/check_path.py file %t.write > %t.out
+# RUN: FileCheck --check-prefix=FILE-EXIST < %t.out %s
+# RUN: rm -f %t.write
+# RUN: "%{python}" %S/check_path.py file %t.write > %t.out
+# RUN: FileCheck --check-prefix=REMOVE-FILE < %t.out %s
+#
+# REMOVE-FILE: False
+# FILE-EXIST: True
+#
+# Check mkdir and rm folder operations.
+# Check force remove commands success whether the directory does or doesn't exist.
+#
+# Check the mkdir command with -p option.
+# RUN: rm -f -r %T/test
+# RUN: "%{python}" %S/check_path.py dir %T/test > %t.out
+# RUN: FileCheck --check-prefix=REMOVE-PARENT-DIR < %t.out %s
+# RUN: mkdir -p %T/test
+# RUN: "%{python}" %S/check_path.py dir %T/test > %t.out
+# RUN: FileCheck --check-prefix=MAKE-PARENT-DIR < %t.out %s
+# RUN: rm -f -r %T/test
+# RUN: "%{python}" %S/check_path.py dir %T/test > %t.out
+# RUN: FileCheck --check-prefix=REMOVE-PARENT-DIR < %t.out %s
+#
+# MAKE-PARENT-DIR: True
+# REMOVE-PARENT-DIR: False
+#
+# Check the mkdir command without -p option.
+#
+# RUN: rm -rf %T/test1
+# RUN: mkdir %T/test1
+# RUN: "%{python}" %S/check_path.py dir %T/test1 > %t.out
+# RUN: FileCheck --check-prefix=MAKE-DIR < %t.out %s
+# RUN: cd %T/test1 && mkdir foo
+# RUN: "%{python}" %S/check_path.py dir %T/test1 > %t.out
+# RUN: FileCheck --check-prefix=MAKE-DIR < %t.out %s
+# RUN: cd %T && rm -rf %T/test1
+# RUN: "%{python}" %S/check_path.py dir %T/test1 > %t.out
+# RUN: FileCheck --check-prefix=REMOVE-DIR < %t.out %s
+#
+# MAKE-DIR: True
+# REMOVE-DIR: False
+#
+# Check creating and removing multiple folders and rm * operation.
+#
+# RUN: rm -rf %T/test
+# RUN: mkdir -p %T/test/test1 %T/test/test2
+# RUN: "%{python}" %S/check_path.py dir %T/test %T/test/test1 %T/test/test2 > %t.out
+# RUN: FileCheck --check-prefix=DIRS-EXIST < %t.out %s
+# RUN: echo "create a temp file" > %T/test/temp.write
+# RUN: echo "create a temp1 file" > %T/test/test1/temp1.write
+# RUN: echo "create a temp2 file" > %T/test/test2/temp2.write
+# RUN: "%{python}" %S/check_path.py file %T/test/temp.write %T/test/test1/temp1.write %T/test/test2/temp2.write> %t.out
+# RUN: FileCheck --check-prefix=FILES-EXIST < %t.out %s
+# RUN: rm -r -f %T/*
+# RUN: "%{python}" %S/check_path.py dir %T/test > %t.out
+# RUN: FileCheck --check-prefix=REMOVE-ALL < %t.out %s
+#
+# DIRS-EXIST: True
+# DIRS-EXIST-NEXT: True
+# DIRS-EXIST-NEXT: True
+# FILES-EXIST: True
+# FILES-EXIST-NEXT: True
+# FILES-EXIST-NEXT: True
+# REMOVE-ALL: False
+#
+# Check diff operations.
+#
+# RUN: echo "hello" > %t.stdout
+# RUN: echo "hello" > %t1.stdout
+# RUN: diff %t.stdout %t1.stdout
+# RUN: diff -u %t.stdout %t1.stdout
+#
+# RUN: mkdir -p %T/dir1 %T/dir2
+# RUN: cd %T/dir1 && echo "hello" > temp1.txt
+# RUN: cd %T/dir2 && echo "hello" > temp2.txt
+# RUN: diff temp2.txt ../dir1/temp1.txt
diff --git a/utils/lit/tests/max-failures.py b/utils/lit/tests/max-failures.py
index bc58e9a4e47..c86d7b7fbdc 100644
--- a/utils/lit/tests/max-failures.py
+++ b/utils/lit/tests/max-failures.py
@@ -8,7 +8,7 @@
#
# END.
-# CHECK: Failing Tests (3)
+# CHECK: Failing Tests (17)
# CHECK: Failing Tests (1)
# CHECK: Failing Tests (2)
# CHECK: error: Setting --max-failures to 0 does not have any effect.
diff --git a/utils/lit/tests/shtest-shell.py b/utils/lit/tests/shtest-shell.py
index 33b5ab669ea..b13a98d691a 100644
--- a/utils/lit/tests/shtest-shell.py
+++ b/utils/lit/tests/shtest-shell.py
@@ -10,6 +10,63 @@
# CHECK: -- Testing:
+
+# CHECK: FAIL: shtest-shell :: diff-error-0.txt
+# CHECK: *** TEST 'shtest-shell :: diff-error-0.txt' FAILED ***
+# CHECK: $ "diff" "diff-error-0.txt" "diff-error-0.txt"
+# CHECK: # command stderr:
+# CHECK: Unsupported: 'diff' cannot be part of a pipeline
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: diff-error-1.txt
+# CHECK: *** TEST 'shtest-shell :: diff-error-1.txt' FAILED ***
+# CHECK: $ "diff" "-B" "temp1.txt" "temp2.txt"
+# CHECK: # command stderr:
+# CHECK: Unsupported: 'diff': option -B not recognized
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: diff-error-2.txt
+# CHECK: *** TEST 'shtest-shell :: diff-error-2.txt' FAILED ***
+# CHECK: $ "diff" "temp.txt"
+# CHECK: # command stderr:
+# CHECK: Error: missing or extra operand
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: diff-error-3.txt
+# CHECK: *** TEST 'shtest-shell :: diff-error-3.txt' FAILED ***
+# CHECK: $ "diff" "temp.txt" "temp1.txt"
+# CHECK: # command stderr:
+# CHECK: Error: 'diff' command failed
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: diff-error-4.txt
+# CHECK: *** TEST 'shtest-shell :: diff-error-4.txt' FAILED ***
+# CHECK: $ "diff"
+# CHECK: # command stderr:
+# CHECK: Error: The contents of fromfile and tofile are different
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: diff-error-5.txt
+# CHECK: *** TEST 'shtest-shell :: diff-error-5.txt' FAILED ***
+# CHECK: $ "diff"
+# CHECK: # command stderr:
+# CHECK: Error: missing or extra operand
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: diff-error-6.txt
+# CHECK: *** TEST 'shtest-shell :: diff-error-6.txt' FAILED ***
+# CHECK: $ "diff"
+# CHECK: # command stderr:
+# CHECK: Error: missing or extra operand
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
# CHECK: FAIL: shtest-shell :: error-0.txt
# CHECK: *** TEST 'shtest-shell :: error-0.txt' FAILED ***
# CHECK: $ "not-a-real-command"
@@ -30,7 +87,65 @@
# CHECK: Unsupported redirect:
# CHECK: ***
+# CHECK: FAIL: shtest-shell :: mkdir-error-0.txt
+# CHECK: *** TEST 'shtest-shell :: mkdir-error-0.txt' FAILED ***
+# CHECK: $ "mkdir" "-p" "temp"
+# CHECK: # command stderr:
+# CHECK: Unsupported: 'mkdir' cannot be part of a pipeline
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: mkdir-error-1.txt
+# CHECK: *** TEST 'shtest-shell :: mkdir-error-1.txt' FAILED ***
+# CHECK: $ "mkdir" "-p" "-m" "777" "temp"
+# CHECK: # command stderr:
+# CHECK: Unsupported: 'mkdir': option -m not recognized
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: mkdir-error-2.txt
+# CHECK: *** TEST 'shtest-shell :: mkdir-error-2.txt' FAILED ***
+# CHECK: $ "mkdir" "-p"
+# CHECK: # command stderr:
+# CHECK: Error: 'mkdir' is missing an operand
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
# CHECK: PASS: shtest-shell :: redirects.txt
+
+# CHECK: FAIL: shtest-shell :: rm-error-0.txt
+# CHECK: *** TEST 'shtest-shell :: rm-error-0.txt' FAILED ***
+# CHECK: $ "rm" "-rf" "temp"
+# CHECK: # command stderr:
+# CHECK: Unsupported: 'rm' cannot be part of a pipeline
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: rm-error-1.txt
+# CHECK: *** TEST 'shtest-shell :: rm-error-1.txt' FAILED ***
+# CHECK: $ "rm" "-f" "-v" "temp"
+# CHECK: # command stderr:
+# CHECK: Unsupported: 'rm': option -v not recognized
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: rm-error-2.txt
+# CHECK: *** TEST 'shtest-shell :: rm-error-2.txt' FAILED ***
+# CHECK: $ "rm" "-r" "hello"
+# CHECK: # command stderr:
+# CHECK: Error: 'rm' command failed
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
+# CHECK: FAIL: shtest-shell :: rm-error-3.txt
+# CHECK: *** TEST 'shtest-shell :: rm-error-3.txt' FAILED ***
+# CHECK: $ "rm" "-f" "test"
+# CHECK: # command stderr:
+# CHECK: test is a directory
+# CHECK: error: command failed with exit status: 127
+# CHECK: ***
+
# CHECK: PASS: shtest-shell :: sequencing-0.txt
# CHECK: XFAIL: shtest-shell :: sequencing-1.txt
-# CHECK: Failing Tests (3)
+# CHECK: PASS: shtest-shell :: valid-shell.txt
+# CHECK: Failing Tests (17)