[llvm] [llvm-lit][test] Precommit tests for lit's built-in cat command (PR #101530)

Paul Kirth via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 2 14:07:02 PDT 2024


================
@@ -0,0 +1,27 @@
+## Test the cat command
+
+# RUN: not %{lit} -a -v %{inputs}/shtest-cat \
+# RUN: | FileCheck -match-full-lines %s
+#
+# END.
+
+# CHECK: FAIL: shtest-cat :: cat-e.txt ({{[^)]*}})
+# CHECK: cat -e {{.+}}/allchars | FileCheck {{.*}}
+# CHECK: # executed command: cat -e {{.*}}
+# CHECK: # | Unsupported: 'cat':  option -e not recognized
+# CHECK: # error: command failed with exit status: {{.*}}
+# CHECK: # executed command: FileCheck {{.*}}
+# CHECK: # error: command failed with exit status: {{.*}}
+
+# CHECK: PASS: shtest-cat :: cat-v.txt ({{[^)]*}})
+# CHECK: cat -v {{.+}}/allchars | FileCheck {{.*}}
+# CHECK: # executed command: cat -v {{.*}}
----------------
ilovepi wrote:

For these, I think you know at least part of the path, right? It should be `{{.+}}allchars`, right? It's not too much of a problem, but it could match on another `cat -v` since there are several, right? Whenever possible, prefer matches that cannot be mistaken for other lines coming later. That can be a challenge when writing these tests, as often output has a particular, repeating structure, but you're only spot checking particular bits. 

If these lines are expected to be one after the next, then `CHECK-NEXT:` is also a better choice, since that avoids some of the issues I described above.

You could also use substitution. see https://llvm.org/docs/CommandGuide/FileCheck.html#filecheck-string-substitution-blocks. the `env-calls-env` test under `shtest-env` uses that off the top of my head. I can point you at other examples if needed.

https://github.com/llvm/llvm-project/pull/101530


More information about the llvm-commits mailing list