+++ /dev/null
-abcd
\ No newline at end of file
+++ /dev/null
-one
-two
-three
-four
-five
-six
-seven
-eight
-nine
-ten
+++ /dev/null
-a
-ab
-abc
-abcd
-RUN: llvm-strings -a %S/Inputs/abcd | FileCheck %s
-RUN: llvm-strings --all %S/Inputs/abcd | FileCheck %s
+## Show that the -a/--all switch is accepted. GNU strings checks specific object
+## file sections unless --all is specified. llvm-strings just looks at the entire
+## file, so this option is silently ignored.
+
+RUN: echo abcd | llvm-strings -a | FileCheck %s
+RUN: echo abcd | llvm-strings --all | FileCheck %s
CHECK: abcd
+## Show that --print-file-name prints just the archive name for an archive and
+## not the member names.
+
RUN: rm -rf %t && mkdir -p %t
-RUN: llvm-ar --format=gnu crs %t/archive.a %S/Inputs/abcd
+RUN: echo -n abcd > %t/abcd
+RUN: llvm-ar --format=gnu crs %t/archive.a %t/abcd
RUN: llvm-strings -f %t/archive.a | FileCheck %s
RUN: llvm-strings --print-file-name %t/archive.a | FileCheck %s
CHECK: archive.a: !<arch>
CHECK: archive.a: abcd/ 0 0 0 644 4 `
CHECK: archive.a: abcd
-
--- /dev/null
+## Show that llvm-strings does not print the last string in the input if it is
+## too short and no unprintable character follows it.
+
+RUN: echo -n abc | llvm-strings - | FileCheck --allow-empty %s
+CHECK-NOT: abc
--- /dev/null
+## Show that llvm-strings prints the last string in the input even if no
+## unprintable character follows it.
+
+RUN: echo -n abcdefg | llvm-strings - | FileCheck %s
+CHECK: abcdefg
-RUN: llvm-strings -f %S/Inputs/abcd | FileCheck %s
-RUN: llvm-strings --print-file-name %S/Inputs/abcd | FileCheck %s --strict-whitespace
-CHECK: {{[\\/]}}abcd: abcd
+## Show that --print-file-name prints the name of the file before each line in
+## the output.
+
+RUN: echo abcd > %t
+RUN: echo efg >> %t
+RUN: echo hijk >> %t
+RUN: llvm-strings -f %t | FileCheck %s --strict-whitespace -DFILE=%t
+RUN: llvm-strings --print-file-name %t | FileCheck %s --strict-whitespace -DFILE=%t
+CHECK: [[FILE]]: abcd
+CHECK-NEXT: [[FILE]]: hijk
-RUN: llvm-strings -h | FileCheck %s
-RUN: llvm-strings --help | FileCheck %s
+## Show that help text is printed correctly when requested.
+
+RUN: llvm-strings -h | FileCheck %s --check-prefixes=CHECK,CATEG
+RUN: llvm-strings --help | FileCheck %s --check-prefixes=CHECK,CATEG
+RUN: llvm-strings --help-list \
+RUN: | FileCheck %s --check-prefixes=CHECK,LIST
CHECK: OVERVIEW: llvm string dumper
CHECK: USAGE: llvm-strings{{(.exe)?}} [options] <input object files>{{$}}
CHECK: OPTIONS:
+CATEG: General options:
+LIST-NOT: General options:
+CATEG: Generic Options:
+LIST-NOT: Generic Options:
CHECK: @FILE
-RUN: not llvm-strings -n 0 2>&1 %S/Inputs/variable-length | FileCheck --check-prefix CHECK-0 %s
-RUN: llvm-strings -n 1 %S/Inputs/variable-length | FileCheck --check-prefix CHECK-1 %s
-RUN: llvm-strings -n 2 %S/Inputs/variable-length | FileCheck --check-prefix CHECK-2 %s
-RUN: llvm-strings %S/Inputs/variable-length | FileCheck --check-prefix CHECK-DEFAULT %s
+## Show that llvm-strings prints only strings with length of at least the
+## requested number of bytes.
-STDIN: a
-STDIN: ab
-STDIN: abc
-STDIN: abcd
+RUN: echo a > %t
+RUN: echo ab >> %t
+RUN: echo abc >> %t
+RUN: echo abcd >> %t
+RUN: echo abcde >> %t
+RUN: not llvm-strings -n 0 2>&1 %t | FileCheck --check-prefix CHECK-0 %s
+RUN: llvm-strings -n 1 %t | FileCheck --check-prefix CHECK-1 %s --implicit-check-not={{.}}
+RUN: llvm-strings -n 2 %t | FileCheck --check-prefix CHECK-2 %s --implicit-check-not={{.}}
+RUN: llvm-strings -n 4 %t | FileCheck --check-prefix CHECK-4 %s --implicit-check-not={{.}}
+RUN: llvm-strings -n 5 %t | FileCheck --check-prefix CHECK-5 %s --implicit-check-not={{.}}
+RUN: llvm-strings -n 6 %t | FileCheck %s --implicit-check-not={{.}} --allow-empty
-CHECK-DEFAULT: abcd
+## Default is equivalent to -n 4.
+RUN: llvm-strings %t | FileCheck --check-prefix CHECK-4 %s --implicit-check-not={{.}}
+
+## Show --bytes works too.
+RUN: llvm-strings --bytes 2 %t | FileCheck --check-prefix CHECK-2 %s --implicit-check-not={{.}}
+
+## Show different syntaxes work.
+RUN: llvm-strings --bytes=2 %t | FileCheck --check-prefix CHECK-2 %s --implicit-check-not={{.}}
+RUN: llvm-strings -n=2 %t | FileCheck --check-prefix CHECK-2 %s --implicit-check-not={{.}}
CHECK-0: invalid minimum string length 0
-CHECK-1: a
-CHECK-1: ab
-CHECK-1: abc
-CHECK-1: abcd
+CHECK-1: a
+CHECK-1-NEXT: ab
+CHECK-1-NEXT: abc
+CHECK-1-NEXT: abcd
+CHECK-1-NEXT: abcde
+
+CHECK-2: ab
+CHECK-2-NEXT: abc
+CHECK-2-NEXT: abcd
+CHECK-2-NEXT: abcde
+
+CHECK-4: abcd
+CHECK-4-NEXT: abcde
-CHECK-2-NOT: a
-CHECK-2: ab
-CHECK-2: abc
-CHECK-2: abcd
+CHECK-5: abcde
+## Show that a non-numeric argument is rejected.
+RUN: not llvm-strings -n foo %t 2>&1 | FileCheck %s --check-prefix=ERR
+ERR: llvm-strings{{.*}}: for the --bytes option: 'foo' value invalid for integer argument!
--- /dev/null
+## Show that llvm-strings reads every file specified on the command-line.
+## This test uses --print-file-name and --radix to show that the values are
+## updated for the second file.
+
+RUN: echo abcd > %t1
+RUN: echo 1234 >> %t1
+RUN: echo defg > %t2
+RUN: llvm-strings --print-file-name --radix=d %t1 %t2 \
+RUN: | FileCheck %s -DFILE1=%t1 -DFILE2=%t2 --implicit-check-not={{.}}
+
+CHECK: [[FILE1]]: 0 abcd
+CHECK-NEXT: [[FILE1]]: 5 1234
+CHECK-NEXT: [[FILE2]]: 0 defg
+## Show that llvm-strings can handle a negative signed char value (i.e. > 0x7f).
+## Such characters should form string delimiters like other unprintable ones.
+
# RUN: echo -e "z\0\x80\0a\0" | llvm-strings --bytes 1 - | FileCheck %s
# CHECK: z{{$}}
# CHECK-NEXT: {{^}}a
+++ /dev/null
-RUN: rm -rf %t && mkdir -p %t
-RUN: llvm-ar --format=gnu crs %t/inner.a %S/Inputs/abcd
-RUN: llvm-ar --format=gnu crs %t/outer.a %t/inner.a
-RUN: llvm-strings %t/outer.a | FileCheck %s
-
-CHECK: !<arch>
-CHECK: inner.a/ 0 0 0 644 72 `
-CHECK: !<arch>
-CHECK: abcd/ 0 0 0 644 4 `
-CHECK: abcd
-
--- /dev/null
+## Show that llvm-strings can handle grouped short options.
+
+RUN: echo abcd > %t
+RUN: llvm-strings -af %t | FileCheck %s -DFILE=%t
+
+CHECK: [[FILE]]: abcd
-RUN: llvm-strings --print-file-name %S/Inputs/numbers \
-RUN: | FileCheck %s --check-prefix CHECK-NONE
-RUN: llvm-strings --print-file-name -t d %S/Inputs/numbers \
-RUN: | FileCheck %s --check-prefix CHECK-DEC --strict-whitespace
-RUN: llvm-strings --print-file-name -t o %S/Inputs/numbers \
-RUN: | FileCheck %s --check-prefix CHECK-OCT --strict-whitespace
-RUN: llvm-strings --print-file-name -t x %S/Inputs/numbers \
-RUN: | FileCheck %s --check-prefix CHECK-HEX --strict-whitespace
+## Show that --radix combined with --print-file-name produces correct output.
-CHECK-NONE: numbers: three
-CHECK-NONE: numbers: four
-CHECK-NONE: numbers: five
-CHECK-NONE: numbers: seven
-CHECK-NONE: numbers: eight
-CHECK-NONE: numbers: nine
+RUN: echo one > %t
+RUN: echo two >> %t
+RUN: echo three >> %t
+RUN: echo four >> %t
+RUN: echo five >> %t
+RUN: echo six >> %t
+RUN: echo seven >> %t
+RUN: echo eight >> %t
+RUN: echo nine >> %t
+RUN: echo ten >> %t
-CHECK-DEC: numbers: 8 three
-CHECK-DEC: numbers: 14 four
-CHECK-DEC: numbers: 19 five
-CHECK-DEC: numbers: 28 seven
-CHECK-DEC: numbers: 34 eight
-CHECK-DEC: numbers: 40 nine
+RUN: llvm-strings --print-file-name %t \
+RUN: | FileCheck %s --check-prefix CHECK-NONE -DFILE=%t --implicit-check-not={{.}}
+RUN: llvm-strings --print-file-name -t d %t \
+RUN: | FileCheck %s --check-prefix CHECK-DEC --strict-whitespace -DFILE=%t --implicit-check-not={{.}}
+RUN: llvm-strings --print-file-name -t o %t \
+RUN: | FileCheck %s --check-prefix CHECK-OCT --strict-whitespace -DFILE=%t --implicit-check-not={{.}}
+RUN: llvm-strings --print-file-name -t x %t \
+RUN: | FileCheck %s --check-prefix CHECK-HEX --strict-whitespace -DFILE=%t --implicit-check-not={{.}}
-CHECK-OCT: numbers: 10 three
-CHECK-OCT: numbers: 16 four
-CHECK-OCT: numbers: 23 five
-CHECK-OCT: numbers: 34 seven
-CHECK-OCT: numbers: 42 eight
-CHECK-OCT: numbers: 50 nine
+CHECK-NONE: [[FILE]]: three
+CHECK-NONE: [[FILE]]: four
+CHECK-NONE: [[FILE]]: five
+CHECK-NONE: [[FILE]]: seven
+CHECK-NONE: [[FILE]]: eight
+CHECK-NONE: [[FILE]]: nine
-CHECK-HEX: numbers: 8 three
-CHECK-HEX: numbers: e four
-CHECK-HEX: numbers: 13 five
-CHECK-HEX: numbers: 1c seven
-CHECK-HEX: numbers: 22 eight
-CHECK-HEX: numbers: 28 nine
+CHECK-DEC: [[FILE]]: 8 three
+CHECK-DEC: [[FILE]]: 14 four
+CHECK-DEC: [[FILE]]: 19 five
+CHECK-DEC: [[FILE]]: 28 seven
+CHECK-DEC: [[FILE]]: 34 eight
+CHECK-DEC: [[FILE]]: 40 nine
+
+CHECK-OCT: [[FILE]]: 10 three
+CHECK-OCT: [[FILE]]: 16 four
+CHECK-OCT: [[FILE]]: 23 five
+CHECK-OCT: [[FILE]]: 34 seven
+CHECK-OCT: [[FILE]]: 42 eight
+CHECK-OCT: [[FILE]]: 50 nine
+
+CHECK-HEX: [[FILE]]: 8 three
+CHECK-HEX: [[FILE]]: e four
+CHECK-HEX: [[FILE]]: 13 five
+CHECK-HEX: [[FILE]]: 1c seven
+CHECK-HEX: [[FILE]]: 22 eight
+CHECK-HEX: [[FILE]]: 28 nine
-RUN: llvm-strings %S/Inputs/numbers | FileCheck %s -check-prefix CHECK-NONE
-RUN: llvm-strings -t d %S/Inputs/numbers | FileCheck %s -check-prefix CHECK-DEC --strict-whitespace
-RUN: llvm-strings -t o %S/Inputs/numbers | FileCheck %s -check-prefix CHECK-OCT --strict-whitespace
-RUN: llvm-strings -t x %S/Inputs/numbers | FileCheck %s -check-prefix CHECK-HEX --strict-whitespace
+## Show that llvm-strings can handle the -t/--radix switch properly.
+
+RUN: echo one > %t
+RUN: echo two >> %t
+RUN: echo three >> %t
+RUN: echo four >> %t
+RUN: echo five >> %t
+RUN: echo six >> %t
+RUN: echo seven >> %t
+RUN: echo eight >> %t
+RUN: echo nine >> %t
+RUN: echo ten >> %t
+
+RUN: llvm-strings %t | FileCheck %s -check-prefix CHECK-NONE --implicit-check-not={{.}}
+RUN: llvm-strings -t d %t | FileCheck %s -check-prefix CHECK-DEC --strict-whitespace --implicit-check-not={{.}}
+RUN: llvm-strings -t o %t | FileCheck %s -check-prefix CHECK-OCT --strict-whitespace --implicit-check-not={{.}}
+RUN: llvm-strings -t x %t | FileCheck %s -check-prefix CHECK-HEX --strict-whitespace --implicit-check-not={{.}}
+
+## Show --radix works too.
+RUN: llvm-strings --radix d %t | FileCheck %s -check-prefix CHECK-DEC --strict-whitespace
+RUN: llvm-strings --radix o %t | FileCheck %s -check-prefix CHECK-OCT --strict-whitespace
+RUN: llvm-strings --radix x %t | FileCheck %s -check-prefix CHECK-HEX --strict-whitespace
+
+## Show different syntaxes work.
+RUN: llvm-strings --radix=d %t | FileCheck %s -check-prefix CHECK-DEC --strict-whitespace
+RUN: llvm-strings -t=d %t | FileCheck %s -check-prefix CHECK-DEC --strict-whitespace
CHECK-NONE: {{^}}three
CHECK-NONE: {{^}}four
CHECK-HEX: {{^}} 1c seven
CHECK-HEX: {{^}} 22 eight
CHECK-HEX: {{^}} 28 nine
+
+## Show that an invalid value is rejected.
+RUN: not llvm-strings --radix z %t 2>&1 | FileCheck %s --check-prefix=INVALID
+INVALID: llvm-strings{{.*}}: for the --radix option: Cannot find option named 'z'!
--- /dev/null
+## Show that llvm-strings can consume a response file.
+
+RUN: echo abcd > %t
+RUN: echo --print-file-name %t > %t.rsp
+RUN: llvm-strings --radix=d @%t.rsp | FileCheck %s -DFILE=%t
+
+CHECK: [[FILE]]: 0 abcd
+## Show that --print-file-name works when the input is standard input.
+
RUN: echo abcd | llvm-strings -f - | FileCheck %s
+RUN: echo abcd | llvm-strings -f | FileCheck %s
RUN: echo abcd | llvm-strings --print-file-name - | FileCheck %s
+RUN: echo abcd | llvm-strings --print-file-name | FileCheck %s
CHECK: {standard input}: abcd
--- /dev/null
+## Show that llvm-strings can handle stdin input properly.
+
+## Case 1: output with single string.
+RUN: echo -n "abcdefg" | llvm-strings - | FileCheck %s --check-prefix=CASE1 --implicit-check-not={{.}}
+CASE1: abcdefg
+
+## Case 2: output too short for string.
+RUN: echo -n "abc" | llvm-strings - | FileCheck %s --implicit-check-not={{.}} --allow-empty
+
+## Case 3: output with new line.
+RUN: echo -e "abcd\nefgh" | llvm-strings - | FileCheck %s --check-prefix=CASE3 --implicit-check-not={{.}}
+CASE3: abcd
+CASE3-NEXT: efgh
+
+## Case 4: output containing unprintable characters.
+RUN: echo -e "abcd\x00ef\x1fghij\x7fklmn" | llvm-strings - | FileCheck %s --check-prefix=CASE4 --implicit-check-not={{.}}
+CASE4: abcd
+CASE4-NEXT: ghij
+CASE4-NEXT: klmn
+
+## Case 5: no file name specified is equivalent to explicitly requesting stdin.
+RUN: echo -n "abcdefg" | llvm-strings | FileCheck %s --check-prefix=CASE1 --implicit-check-not={{.}}
+++ /dev/null
-RUN: echo -n abc | llvm-strings - | FileCheck -allow-empty %s
-CHECK-NOT: abc
+++ /dev/null
-RUN: echo -n abcdefg | llvm-strings - | FileCheck %s
-CHECK: abcdefg
--- /dev/null
+## Show that --version works for llvm-strings.
+
+RUN: llvm-strings --version | FileCheck %s
+CHECK: version
-RUN: echo -n abcd | llvm-strings - | FileCheck %s --strict-whitespace
+## Show that the default output format matches GNU strings.
+RUN: echo -n abcd | llvm-strings - | FileCheck %s --strict-whitespace --implicit-check-not={{.}}
CHECK: {{^}}abcd{{$}}