From 946a035ab58e6f2df9c205499795160eb40b8240 Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Wed, 7 Aug 2024 20:30:26 +0000 Subject: [PATCH 1/5] [llvm-lit][test][NFC] Moved cat command tests into separate lit test file This patch separates the lit tests that check for the functionality of lit's built-in cat command into its own test file and folder. --- .../cat-error-0.txt | 0 .../cat-error-1.txt | 0 .../utils/lit/tests/Inputs/shtest-cat/cat.txt | 83 +++++++++++++++++ .../cat_nonprinting.bin | Bin .../lit/tests/Inputs/shtest-cat/check_path.py | 31 +++++++ .../utils/lit/tests/Inputs/shtest-cat/lit.cfg | 8 ++ .../tests/Inputs/shtest-shell/valid-shell.txt | 84 ------------------ llvm/utils/lit/tests/shtest-cat.py | 20 +++++ llvm/utils/lit/tests/shtest-shell.py | 18 +--- 9 files changed, 143 insertions(+), 101 deletions(-) rename llvm/utils/lit/tests/Inputs/{shtest-shell => shtest-cat}/cat-error-0.txt (100%) rename llvm/utils/lit/tests/Inputs/{shtest-shell => shtest-cat}/cat-error-1.txt (100%) create mode 100644 llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt rename llvm/utils/lit/tests/Inputs/{shtest-shell => shtest-cat}/cat_nonprinting.bin (100%) create mode 100644 llvm/utils/lit/tests/Inputs/shtest-cat/check_path.py create mode 100644 llvm/utils/lit/tests/Inputs/shtest-cat/lit.cfg create mode 100644 llvm/utils/lit/tests/shtest-cat.py diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell/cat-error-0.txt b/llvm/utils/lit/tests/Inputs/shtest-cat/cat-error-0.txt similarity index 100% rename from llvm/utils/lit/tests/Inputs/shtest-shell/cat-error-0.txt rename to llvm/utils/lit/tests/Inputs/shtest-cat/cat-error-0.txt diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell/cat-error-1.txt b/llvm/utils/lit/tests/Inputs/shtest-cat/cat-error-1.txt similarity index 100% rename from llvm/utils/lit/tests/Inputs/shtest-shell/cat-error-1.txt rename to llvm/utils/lit/tests/Inputs/shtest-cat/cat-error-1.txt diff --git a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt new file mode 100644 index 0000000000000..a69b5f5aa8f66 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt @@ -0,0 +1,83 @@ +# 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 +# +# Check cat command with -v option +# +# RUN: cat -v %S/cat_nonprinting.bin | FileCheck --check-prefix=NP-CAT-OUTPUT %s +# NP-CAT-OUTPUT: ^@^A^B^C^D^E^F^G ^H +# NP-CAT-OUTPUT-NEXT: ^K^L^M^N^O^P^Q^R^S +# NP-CAT-OUTPUT-NEXT: ^T^U^V^W^X^Y^Z^[^\^]^^^_ !"#$%&' +# NP-CAT-OUTPUT-NEXT: ()*+,-./0123456789:; +# NP-CAT-OUTPUT-NEXT: <=>?@ABCDEFGHIJKLMNO +# NP-CAT-OUTPUT-NEXT: PQRSTUVWXYZ[\]^_`abc +# NP-CAT-OUTPUT-NEXT: defghijklmnopqrstuvw +# NP-CAT-OUTPUT-NEXT: xyz{|}~^?M-^@M-^AM-^BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^K +# NP-CAT-OUTPUT-NEXT: M-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^VM-^WM-^XM-^YM-^ZM-^[M-^\M-^]M-^^M-^_ +# NP-CAT-OUTPUT-NEXT: M- M-!M-"M-#M-$M-%M-&M-'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3 +# NP-CAT-OUTPUT-NEXT: M-4M-5M-6M-7M-8M-9M-:M-;M-M-?M-@M-AM-BM-CM-DM-EM-FM-G +# NP-CAT-OUTPUT-NEXT: M-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[ +# NP-CAT-OUTPUT-NEXT: M-\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-o +# NP-CAT-OUTPUT-NEXT: M-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^? +# +# Check cat command with -show-nonprinting option +# +# RUN: cat --show-nonprinting %S/cat_nonprinting.bin | FileCheck --check-prefix=NPLONG-CAT-OUTPUT %s +# NPLONG-CAT-OUTPUT: ^@^A^B^C^D^E^F^G ^H +# NPLONG-CAT-OUTPUT-NEXT: ^K^L^M^N^O^P^Q^R^S +# NPLONG-CAT-OUTPUT-NEXT: ^T^U^V^W^X^Y^Z^[^\^]^^^_ !"#$%&' +# NPLONG-CAT-OUTPUT-NEXT: ()*+,-./0123456789:; +# NPLONG-CAT-OUTPUT-NEXT: <=>?@ABCDEFGHIJKLMNO +# NPLONG-CAT-OUTPUT-NEXT: PQRSTUVWXYZ[\]^_`abc +# NPLONG-CAT-OUTPUT-NEXT: defghijklmnopqrstuvw +# NPLONG-CAT-OUTPUT-NEXT: xyz{|}~^?M-^@M-^AM-^BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^K +# NPLONG-CAT-OUTPUT-NEXT: M-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^VM-^WM-^XM-^YM-^ZM-^[M-^\M-^]M-^^M-^_ +# NPLONG-CAT-OUTPUT-NEXT: M- M-!M-"M-#M-$M-%M-&M-'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3 +# NPLONG-CAT-OUTPUT-NEXT: M-4M-5M-6M-7M-8M-9M-:M-;M-M-?M-@M-AM-BM-CM-DM-EM-FM-G +# NPLONG-CAT-OUTPUT-NEXT: M-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[ +# NPLONG-CAT-OUTPUT-NEXT: M-\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-o +# NPLONG-CAT-OUTPUT-NEXT: M-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^? diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell/cat_nonprinting.bin b/llvm/utils/lit/tests/Inputs/shtest-cat/cat_nonprinting.bin similarity index 100% rename from llvm/utils/lit/tests/Inputs/shtest-shell/cat_nonprinting.bin rename to llvm/utils/lit/tests/Inputs/shtest-cat/cat_nonprinting.bin diff --git a/llvm/utils/lit/tests/Inputs/shtest-cat/check_path.py b/llvm/utils/lit/tests/Inputs/shtest-cat/check_path.py new file mode 100644 index 0000000000000..62c906846fbb5 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-cat/check_path.py @@ -0,0 +1,31 @@ +#!/usr/bin/env python + +from __future__ import print_function + +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/llvm/utils/lit/tests/Inputs/shtest-cat/lit.cfg b/llvm/utils/lit/tests/Inputs/shtest-cat/lit.cfg new file mode 100644 index 0000000000000..8f197946e28b5 --- /dev/null +++ b/llvm/utils/lit/tests/Inputs/shtest-cat/lit.cfg @@ -0,0 +1,8 @@ +import lit.formats + +config.name = "shtest-cat" +config.suffixes = [".txt"] +config.test_format = lit.formats.ShTest() +config.test_source_root = None +config.test_exec_root = None +config.substitutions.append(("%{python}", '"%s"' % (sys.executable))) diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt b/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt index 7267b9b9ef5ab..ba8f9ff1f8d03 100644 --- a/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt +++ b/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt @@ -85,87 +85,3 @@ # 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 -# -# Check cat command with -v option -# -# RUN: cat -v %S/cat_nonprinting.bin | FileCheck --check-prefix=NP-CAT-OUTPUT %s -# NP-CAT-OUTPUT: ^@^A^B^C^D^E^F^G ^H -# NP-CAT-OUTPUT-NEXT: ^K^L^M^N^O^P^Q^R^S -# NP-CAT-OUTPUT-NEXT: ^T^U^V^W^X^Y^Z^[^\^]^^^_ !"#$%&' -# NP-CAT-OUTPUT-NEXT: ()*+,-./0123456789:; -# NP-CAT-OUTPUT-NEXT: <=>?@ABCDEFGHIJKLMNO -# NP-CAT-OUTPUT-NEXT: PQRSTUVWXYZ[\]^_`abc -# NP-CAT-OUTPUT-NEXT: defghijklmnopqrstuvw -# NP-CAT-OUTPUT-NEXT: xyz{|}~^?M-^@M-^AM-^BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^K -# NP-CAT-OUTPUT-NEXT: M-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^VM-^WM-^XM-^YM-^ZM-^[M-^\M-^]M-^^M-^_ -# NP-CAT-OUTPUT-NEXT: M- M-!M-"M-#M-$M-%M-&M-'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3 -# NP-CAT-OUTPUT-NEXT: M-4M-5M-6M-7M-8M-9M-:M-;M-M-?M-@M-AM-BM-CM-DM-EM-FM-G -# NP-CAT-OUTPUT-NEXT: M-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[ -# NP-CAT-OUTPUT-NEXT: M-\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-o -# NP-CAT-OUTPUT-NEXT: M-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^? -# -# Check cat command with -show-nonprinting option -# -# RUN: cat --show-nonprinting %S/cat_nonprinting.bin | FileCheck --check-prefix=NPLONG-CAT-OUTPUT %s -# NPLONG-CAT-OUTPUT: ^@^A^B^C^D^E^F^G ^H -# NPLONG-CAT-OUTPUT-NEXT: ^K^L^M^N^O^P^Q^R^S -# NPLONG-CAT-OUTPUT-NEXT: ^T^U^V^W^X^Y^Z^[^\^]^^^_ !"#$%&' -# NPLONG-CAT-OUTPUT-NEXT: ()*+,-./0123456789:; -# NPLONG-CAT-OUTPUT-NEXT: <=>?@ABCDEFGHIJKLMNO -# NPLONG-CAT-OUTPUT-NEXT: PQRSTUVWXYZ[\]^_`abc -# NPLONG-CAT-OUTPUT-NEXT: defghijklmnopqrstuvw -# NPLONG-CAT-OUTPUT-NEXT: xyz{|}~^?M-^@M-^AM-^BM-^CM-^DM-^EM-^FM-^GM-^HM-^IM-^JM-^K -# NPLONG-CAT-OUTPUT-NEXT: M-^LM-^MM-^NM-^OM-^PM-^QM-^RM-^SM-^TM-^UM-^VM-^WM-^XM-^YM-^ZM-^[M-^\M-^]M-^^M-^_ -# NPLONG-CAT-OUTPUT-NEXT: M- M-!M-"M-#M-$M-%M-&M-'M-(M-)M-*M-+M-,M--M-.M-/M-0M-1M-2M-3 -# NPLONG-CAT-OUTPUT-NEXT: M-4M-5M-6M-7M-8M-9M-:M-;M-M-?M-@M-AM-BM-CM-DM-EM-FM-G -# NPLONG-CAT-OUTPUT-NEXT: M-HM-IM-JM-KM-LM-MM-NM-OM-PM-QM-RM-SM-TM-UM-VM-WM-XM-YM-ZM-[ -# NPLONG-CAT-OUTPUT-NEXT: M-\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-o -# NPLONG-CAT-OUTPUT-NEXT: M-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^? diff --git a/llvm/utils/lit/tests/shtest-cat.py b/llvm/utils/lit/tests/shtest-cat.py new file mode 100644 index 0000000000000..d12f5c8bebf49 --- /dev/null +++ b/llvm/utils/lit/tests/shtest-cat.py @@ -0,0 +1,20 @@ +## Check the cat command. +# +# RUN: not %{lit} -a -v %{inputs}/shtest-cat \ +# RUN: | FileCheck -match-full-lines %s +# +# END. + +# CHECK: FAIL: shtest-cat :: cat-error-0.txt ({{[^)]*}}) +# CHECK: cat -b temp1.txt +# CHECK: # .---command stderr{{-*}} +# CHECK: # | Unsupported: 'cat': option -b not recognized +# CHECK: # error: command failed with exit status: 1 + +# CHECK: FAIL: shtest-cat :: cat-error-1.txt ({{[^)]*}}) +# 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: PASS: shtest-cat :: cat.txt ({{[^)]*}}) \ No newline at end of file diff --git a/llvm/utils/lit/tests/shtest-shell.py b/llvm/utils/lit/tests/shtest-shell.py index 8685119488062..8f2b865f333a5 100644 --- a/llvm/utils/lit/tests/shtest-shell.py +++ b/llvm/utils/lit/tests/shtest-shell.py @@ -18,22 +18,6 @@ # CHECK: -- Testing: -# CHECK: FAIL: shtest-shell :: cat-error-0.txt -# CHECK: *** TEST 'shtest-shell :: cat-error-0.txt' FAILED *** -# CHECK: cat -b temp1.txt -# CHECK: # .---command stderr{{-*}} -# CHECK: # | Unsupported: 'cat': option -b not recognized -# 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 :: colon-error.txt # CHECK: *** TEST 'shtest-shell :: colon-error.txt' FAILED *** # CHECK: : @@ -651,4 +635,4 @@ # CHECK: PASS: shtest-shell :: valid-shell.txt # CHECK: Unresolved Tests (1) -# CHECK: Failed Tests (38) +# CHECK: Failed Tests (36) From 712515e8de44c9f7be7f6ae82a498957c818f06b Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Thu, 8 Aug 2024 17:35:57 +0000 Subject: [PATCH 2/5] [llvm-lit][test][NFC] Moved check_path.py to be used by multiple directories This patch moves check_path.py into the main Inputs directory so that it can be used by both shtest-cat and shtest-shell. --- .../Inputs/{shtest-cat => }/check_path.py | 0 .../utils/lit/tests/Inputs/shtest-cat/cat.txt | 4 +-- .../tests/Inputs/shtest-shell/check_path.py | 31 ------------------- .../tests/Inputs/shtest-shell/valid-shell.txt | 24 +++++++------- 4 files changed, 14 insertions(+), 45 deletions(-) rename llvm/utils/lit/tests/Inputs/{shtest-cat => }/check_path.py (100%) delete mode 100644 llvm/utils/lit/tests/Inputs/shtest-shell/check_path.py diff --git a/llvm/utils/lit/tests/Inputs/shtest-cat/check_path.py b/llvm/utils/lit/tests/Inputs/check_path.py similarity index 100% rename from llvm/utils/lit/tests/Inputs/shtest-cat/check_path.py rename to llvm/utils/lit/tests/Inputs/check_path.py diff --git a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt index a69b5f5aa8f66..02998f7e3aa5e 100644 --- a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt +++ b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt @@ -4,7 +4,7 @@ # 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: %{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 @@ -18,7 +18,7 @@ # 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: %{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 diff --git a/llvm/utils/lit/tests/Inputs/shtest-shell/check_path.py b/llvm/utils/lit/tests/Inputs/shtest-shell/check_path.py deleted file mode 100644 index 62c906846fbb5..0000000000000 --- a/llvm/utils/lit/tests/Inputs/shtest-shell/check_path.py +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env python - -from __future__ import print_function - -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/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt b/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt index ba8f9ff1f8d03..75ce8b7733ad7 100644 --- a/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt +++ b/llvm/utils/lit/tests/Inputs/shtest-shell/valid-shell.txt @@ -2,13 +2,13 @@ # 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: %{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: %{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: %{python} %S/../check_path.py file %t.write > %t.out # RUN: FileCheck --check-prefix=REMOVE-FILE < %t.out %s # # REMOVE-FILE: False @@ -19,14 +19,14 @@ # # 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: %{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: %{python} %S/../check_path.py dir %T/test > %t.out # RUN: FileCheck --check-prefix=MAKE-PARENT-DIR < %t.out %s # RUN: rm -f %T/test || true # RUN: rm -f -r %T/test -# RUN: %{python} %S/check_path.py dir %T/test > %t.out +# 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 @@ -36,13 +36,13 @@ # # RUN: rm -rf %T/test1 # RUN: mkdir %T/test1 -# RUN: %{python} %S/check_path.py dir %T/test1 > %t.out +# 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: %{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: %{python} %S/../check_path.py dir %T/test1 > %t.out # RUN: FileCheck --check-prefix=REMOVE-DIR < %t.out %s # # MAKE-DIR: True @@ -52,16 +52,16 @@ # # 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: %{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: mkdir %T/test || true # 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: %{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: %{python} %S/../check_path.py dir %T/test > %t.out # RUN: FileCheck --check-prefix=REMOVE-ALL < %t.out %s # # DIRS-EXIST: True From 0910b5bb589fc52a0ef2f6487fcbbe190f8163b1 Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Fri, 9 Aug 2024 17:58:00 +0000 Subject: [PATCH 3/5] [llvm-lit][test][NFC] Added pass/fail summary to cat testing --- llvm/utils/lit/tests/shtest-cat.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm/utils/lit/tests/shtest-cat.py b/llvm/utils/lit/tests/shtest-cat.py index d12f5c8bebf49..b154f05dae98c 100644 --- a/llvm/utils/lit/tests/shtest-cat.py +++ b/llvm/utils/lit/tests/shtest-cat.py @@ -17,4 +17,8 @@ # CHECK: # | [Errno 2] No such file or directory: 'temp1.txt' # CHECK: # error: command failed with exit status: 1 -# CHECK: PASS: shtest-cat :: cat.txt ({{[^)]*}}) \ No newline at end of file +# CHECK: PASS: shtest-cat :: cat.txt ({{[^)]*}}) + +# CHECK: Total Discovered Tests: 3 +# CHECK: Passed: 1 {{\([0-9]*\.[0-9]*%\)}} +# CHECK: Failed: 2 {{\([0-9]*\.[0-9]*%\)}} From 8898b99e6c9d31704ddff0bbd0b49d903d5d7f91 Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Mon, 12 Aug 2024 16:01:27 +0000 Subject: [PATCH 4/5] [llvm-lit] Made syntax changes --- llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt | 12 ++++++------ llvm/utils/lit/tests/shtest-cat.py | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt index 02998f7e3aa5e..7375a7497e5be 100644 --- a/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt +++ b/llvm/utils/lit/tests/Inputs/shtest-cat/cat.txt @@ -1,4 +1,4 @@ -# Check cat command with single file. +## Test cat command with a single file. # # RUN: rm -rf %T/testCat # RUN: mkdir -p %T/testCat @@ -10,7 +10,7 @@ # FILE-EXISTS: True # CAT-OUTPUT: abcdefgh # -# Check cat command with multiple files. +## Test cat command with multiple files. # # RUN: rm -rf %T/testCat # RUN: mkdir -p %T/testCat @@ -26,7 +26,7 @@ # MULTI-CAT-OUTPUT-NEXT: efghijkl # MULTI-CAT-OUTPUT-NEXT: mnopqrst # -# Check cat command with multiple files and piped output to FileCheck. +## Test cat command with multiple files and piped output to FileCheck. # # RUN: rm -rf %T/testCat # RUN: mkdir -p %T/testCat @@ -36,7 +36,7 @@ # PIPED-CAT-OUTPUT: abcdefgh # PIPED-CAT-OUTPUT-NEXT: efghijkl # -# Check cat command with multiple files and glob expressions. +## Test cat command with multiple files and glob expressions. # # RUN: rm -rf %T/testCat # RUN: mkdir -p %T/testCat @@ -46,7 +46,7 @@ # GLOB-CAT-OUTPUT: cvbnm # GLOB-CAT-OUTPUT-NEXT: qwerty # -# Check cat command with -v option +## Test cat command with -v option # # RUN: cat -v %S/cat_nonprinting.bin | FileCheck --check-prefix=NP-CAT-OUTPUT %s # NP-CAT-OUTPUT: ^@^A^B^C^D^E^F^G ^H @@ -64,7 +64,7 @@ # NP-CAT-OUTPUT-NEXT: M-\M-]M-^M-_M-`M-aM-bM-cM-dM-eM-fM-gM-hM-iM-jM-kM-lM-mM-nM-o # NP-CAT-OUTPUT-NEXT: M-pM-qM-rM-sM-tM-uM-vM-wM-xM-yM-zM-{M-|M-}M-~M-^? # -# Check cat command with -show-nonprinting option +## Test cat command with -show-nonprinting option # # RUN: cat --show-nonprinting %S/cat_nonprinting.bin | FileCheck --check-prefix=NPLONG-CAT-OUTPUT %s # NPLONG-CAT-OUTPUT: ^@^A^B^C^D^E^F^G ^H diff --git a/llvm/utils/lit/tests/shtest-cat.py b/llvm/utils/lit/tests/shtest-cat.py index b154f05dae98c..2fac8ee8fb953 100644 --- a/llvm/utils/lit/tests/shtest-cat.py +++ b/llvm/utils/lit/tests/shtest-cat.py @@ -8,13 +8,13 @@ # CHECK: FAIL: shtest-cat :: cat-error-0.txt ({{[^)]*}}) # CHECK: cat -b temp1.txt # CHECK: # .---command stderr{{-*}} -# CHECK: # | Unsupported: 'cat': option -b not recognized +# CHECK-NEXT: # | Unsupported: 'cat': option -b not recognized # CHECK: # error: command failed with exit status: 1 # CHECK: FAIL: shtest-cat :: cat-error-1.txt ({{[^)]*}}) # CHECK: cat temp1.txt # CHECK: # .---command stderr{{-*}} -# CHECK: # | [Errno 2] No such file or directory: 'temp1.txt' +# CHECK-NEXT: # | [Errno 2] No such file or directory: 'temp1.txt' # CHECK: # error: command failed with exit status: 1 # CHECK: PASS: shtest-cat :: cat.txt ({{[^)]*}}) From 1d23cf699166bf0b1a2d93830b5422bd0e481612 Mon Sep 17 00:00:00 2001 From: Connie Zhu Date: Mon, 12 Aug 2024 17:13:25 +0000 Subject: [PATCH 5/5] Modified CHECK directive syntax --- llvm/utils/lit/tests/shtest-cat.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/llvm/utils/lit/tests/shtest-cat.py b/llvm/utils/lit/tests/shtest-cat.py index 2fac8ee8fb953..5efe25c41684a 100644 --- a/llvm/utils/lit/tests/shtest-cat.py +++ b/llvm/utils/lit/tests/shtest-cat.py @@ -1,8 +1,7 @@ -## Check the cat command. +## Test the cat command. # # RUN: not %{lit} -a -v %{inputs}/shtest-cat \ # RUN: | FileCheck -match-full-lines %s -# # END. # CHECK: FAIL: shtest-cat :: cat-error-0.txt ({{[^)]*}}) @@ -20,5 +19,5 @@ # CHECK: PASS: shtest-cat :: cat.txt ({{[^)]*}}) # CHECK: Total Discovered Tests: 3 -# CHECK: Passed: 1 {{\([0-9]*\.[0-9]*%\)}} -# CHECK: Failed: 2 {{\([0-9]*\.[0-9]*%\)}} +# CHECK-NEXT: Passed: 1 {{\([0-9]*\.[0-9]*%\)}} +# CHECK-NEXT: Failed: 2 {{\([0-9]*\.[0-9]*%\)}}