[llvm] [llvm-strings] Add --encoding={s,S,u} option (PR #221794)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 01:14:38 PDT 2026
================
@@ -0,0 +1,28 @@
+## Show that llvm-strings uses the specified encoding.
+
+RUN: echo a > %t
+RUN: echo ab >> %t
+RUN: echo abc >> %t
+RUN: echo abcd >> %t
+RUN: echo abcd€ >> %t
+
+# Check that long form options work.
+RUN: llvm-strings --encoding s 2>&1 %t | FileCheck --check-prefixes CHECK,CHECK-ASCII %s
+RUN: llvm-strings --encoding S 2>&1 %t | FileCheck %s
+RUN: llvm-strings --encoding u 2>&1 %t | FileCheck --check-prefixes CHECK,CHECK-UTF8 %s
+RUN: not llvm-strings --encoding x 2>&1 %t | FileCheck --check-prefixes CHECK-ERROR %s
+
+# Check that short form options work.
+RUN: llvm-strings -e s 2>&1 %t | FileCheck --check-prefixes CHECK,CHECK-ASCII %s
+RUN: llvm-strings -e S 2>&1 %t | FileCheck %s
+RUN: llvm-strings -e u 2>&1 %t | FileCheck --check-prefixes CHECK,CHECK-UTF8 %s
+
+CHECK: abcd
+CHECK-ASCII-NOT: abcd€
+CHECK-UTF8: abcd€
----------------
jh7370 wrote:
Related to my earlier comment about the check prefix, I don't think this set of checks is sufficient for testing what you want to test. A simple way of demoing is by adding the `-n` option to a value of 1. In this case, you'd expect to print out every character in the file pretty much (possibly except the Euro in the ASCII case), so `a`, `ab` etc would be in the output as separate lines. However, none of your tests would fail.
Given the nature of the tool, there are lots of possibilities for the output to get corrupted due to additional characters being printed before or after the expected output. I'd therefore consider using `--implicit-check-not={{.}}`, which will cause FileCheck to fail if anything appears in the output that isn't explicitly checked for.
Also, similar to my above comment about using `printf` for the Euro sign, I'd be concerned about the encoding of the Euro in the checks. I don't have a good suggestion for this, but maybe the FileCheck regex system allows \u sequences or even \x sequences and you could use that? It'll require some investigation (test by saving the file in one encoding and then running the test under a different locale).
https://github.com/llvm/llvm-project/pull/221794
More information about the llvm-commits
mailing list