Index: utils/lit/lit/TestRunner.py =================================================================== --- utils/lit/lit/TestRunner.py +++ utils/lit/lit/TestRunner.py @@ -156,7 +156,7 @@ def expand_glob(arg, cwd): if isinstance(arg, GlobItem): - return arg.resolve(cwd) + return sorted(arg.resolve(cwd)) return [arg] def expand_glob_expressions(args, cwd): @@ -745,6 +745,8 @@ stderrTempFiles = [] opened_files = [] named_temp_files = [] + builtin_commands = ['cat'] + builtin_commands_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "builtin_commands") # To avoid deadlock, we use a single stderr stream for piped # output. This is null until we have seen some output using # stderr. @@ -780,11 +782,15 @@ # Resolve the executable path ourselves. args = list(j.args) executable = None + is_builtin_cmd = False; # For paths relative to cwd, use the cwd of the shell environment. if args[0].startswith('.'): exe_in_cwd = os.path.join(cmd_shenv.cwd, args[0]) if os.path.isfile(exe_in_cwd): executable = exe_in_cwd + if not executable and args[0] in builtin_commands: + is_builtin_cmd = True + executable = "python" if not executable: executable = lit.util.which(args[0], cmd_shenv.env['PATH']) if not executable: @@ -801,6 +807,9 @@ # Expand all glob expressions args = expand_glob_expressions(args, cmd_shenv.cwd) + if is_builtin_cmd == True: + args.insert(0, executable) + args[1] = os.path.join(builtin_commands_dir ,args[1] + ".py") # On Windows, do our own command line quoting for better compatibility # with some core utility distributions. @@ -809,7 +818,7 @@ try: procs.append(subprocess.Popen(args, cwd=cmd_shenv.cwd, - executable = executable, + executable = None if is_builtin_cmd == True else executable, stdin = stdin, stdout = stdout, stderr = stderr, Index: utils/lit/lit/builtin_commands/cat.py =================================================================== --- utils/lit/lit/builtin_commands/cat.py +++ utils/lit/lit/builtin_commands/cat.py @@ -0,0 +1,22 @@ +import sys + +def main(argv): + filenames = argv[1:] + + for filename in filenames: + if filename.startswith("-"): + sys.stderr.write("Built-in 'cat' command does not support options.") + sys.exit(1) + + for filename in filenames: + try: + fileToCat = open(filename,"r") + sys.stdout.write(fileToCat.read()) + sys.stdout.flush() + fileToCat.close() + except IOError as error: + sys.stderr.write(str(error)) + sys.exit(1) + +if __name__ == "__main__": + main(sys.argv) Index: utils/lit/tests/Inputs/shtest-shell/cat-error-0.txt =================================================================== --- utils/lit/tests/Inputs/shtest-shell/cat-error-0.txt +++ utils/lit/tests/Inputs/shtest-shell/cat-error-0.txt @@ -0,0 +1,3 @@ +# Check error on a unsupported cat (Options are not supported). +# +# RUN: cat -v temp1.txt Index: utils/lit/tests/Inputs/shtest-shell/cat-error-1.txt =================================================================== --- utils/lit/tests/Inputs/shtest-shell/cat-error-1.txt +++ utils/lit/tests/Inputs/shtest-shell/cat-error-1.txt @@ -0,0 +1,3 @@ +# Check error on a unsupported cat (Unable to find input file). +# +# RUN: cat temp1.txt Index: utils/lit/tests/Inputs/shtest-shell/valid-shell.txt =================================================================== --- utils/lit/tests/Inputs/shtest-shell/valid-shell.txt +++ utils/lit/tests/Inputs/shtest-shell/valid-shell.txt @@ -85,3 +85,52 @@ # RUN: cd %T/dir1 && echo "hello" > temp1.txt # RUN: cd %T/dir2 && echo "hello" > temp2.txt # RUN: diff temp2.txt ../dir1/temp1.txt +# +# Check cat command with single file. +# +# RUN: rm -rf %T/testCat +# RUN: mkdir -p %T/testCat +# RUN: echo "abcdefgh" > %T/testCat/temp.write +# RUN: cat %T/testCat/temp.write > %T/testCat/tempcat.write +# RUN: "%{python}" %S/check_path.py file %T/testCat/tempcat.write > %T/testCat/path.out +# RUN: FileCheck --check-prefix=FILE-EXISTS < %T/testCat/path.out %s +# RUN: FileCheck --check-prefix=CAT-OUTPUT < %T/testCat/tempcat.write %s +# FILE-EXISTS: True +# CAT-OUTPUT: abcdefgh +# +# Check cat command with multiple files. +# +# RUN: rm -rf %T/testCat +# RUN: mkdir -p %T/testCat +# RUN: echo "abcdefgh" > %T/testCat/temp1.write +# RUN: echo "efghijkl" > %T/testCat/temp2.write +# RUN: echo "mnopqrst" > %T/testCat/temp3.write +# RUN: cat %T/testCat/temp1.write %T/testCat/temp2.write %T/testCat/temp3.write > %T/testCat/tempmulticat.write +# RUN: "%{python}" %S/check_path.py file %T/testCat/tempmulticat.write > %T/testCat/path.out +# RUN: FileCheck --check-prefix=MULTI-FILE-EXISTS < %T/testCat/path.out %s +# RUN: FileCheck --check-prefix=MULTI-CAT-OUTPUT < %T/testCat/tempmulticat.write %s +# MULTI-FILE-EXISTS: True +# MULTI-CAT-OUTPUT: abcdefgh +# MULTI-CAT-OUTPUT-NEXT: efghijkl +# MULTI-CAT-OUTPUT-NEXT: mnopqrst +# +# Check cat command with multiple files and piped output to FileCheck. +# +# RUN: rm -rf %T/testCat +# RUN: mkdir -p %T/testCat +# RUN: echo "abcdefgh" > %T/testCat/temp1.write +# RUN: echo "efghijkl" > %T/testCat/temp2.write +# RUN: cat %T/testCat/temp1.write %T/testCat/temp2.write | FileCheck --check-prefix=PIPED-CAT-OUTPUT %s +# PIPED-CAT-OUTPUT: abcdefgh +# PIPED-CAT-OUTPUT-NEXT: efghijkl +# +# Check cat command with multiple files and glob expressions. +# +# RUN: rm -rf %T/testCat +# RUN: mkdir -p %T/testCat +# RUN: echo "cvbnm" > %T/testCat/temp1.write +# RUN: echo "qwerty" > %T/testCat/temp2.write +# RUN: cat %T/testCat/*.write | FileCheck --check-prefix=GLOB-CAT-OUTPUT %s +# GLOB-CAT-OUTPUT: cvbnm +# GLOB-CAT-OUTPUT-NEXT: qwerty + Index: utils/lit/tests/max-failures.py =================================================================== --- utils/lit/tests/max-failures.py +++ utils/lit/tests/max-failures.py @@ -8,7 +8,7 @@ # # END. -# CHECK: Failing Tests (24) +# CHECK: Failing Tests (26) # CHECK: Failing Tests (1) # CHECK: Failing Tests (2) # CHECK: error: Setting --max-failures to 0 does not have any effect. Index: utils/lit/tests/shtest-shell.py =================================================================== --- utils/lit/tests/shtest-shell.py +++ utils/lit/tests/shtest-shell.py @@ -10,6 +10,21 @@ # CHECK: -- Testing: +# CHECK: FAIL: shtest-shell :: cat-error-0.txt +# CHECK: *** TEST 'shtest-shell :: cat-error-0.txt' FAILED *** +# CHECK: $ "cat" "-v" "temp1.txt" +# CHECK: # command stderr: +# CHECK: Built-in 'cat' command does not support options. +# CHECK: error: command failed with exit status: 1 +# CHECK: *** + +# CHECK: FAIL: shtest-shell :: cat-error-1.txt +# CHECK: *** TEST 'shtest-shell :: cat-error-1.txt' FAILED *** +# CHECK: $ "cat" "temp1.txt" +# CHECK: # command stderr: +# CHECK: [Errno 2] No such file or directory: 'temp1.txt' +# CHECK: error: command failed with exit status: 1 +# CHECK: *** # CHECK: FAIL: shtest-shell :: diff-error-0.txt # CHECK: *** TEST 'shtest-shell :: diff-error-0.txt' FAILED *** @@ -204,4 +219,4 @@ # CHECK: PASS: shtest-shell :: sequencing-0.txt # CHECK: XFAIL: shtest-shell :: sequencing-1.txt # CHECK: PASS: shtest-shell :: valid-shell.txt -# CHECK: Failing Tests (24) +# CHECK: Failing Tests (26)