logo

utils-std

Collection of commonly available Unix tools

strings (4771B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. atf_test_case allbytes
  5. allbytes_body() {
  6. atf_check -o file:outputs/strings/all_bytes ../cmd/strings inputs/all_bytes
  7. atf_check -o file:outputs/strings/all_bytes ../cmd/strings <inputs/all_bytes
  8. atf_check -o file:outputs/strings/all_bytes ../cmd/strings - <inputs/all_bytes
  9. }
  10. atf_test_case trueelf
  11. trueelf_body() {
  12. atf_check -o file:outputs/strings/true ../cmd/strings inputs/strings/true
  13. atf_check -o file:outputs/strings/true ../cmd/strings <inputs/strings/true
  14. atf_check -o file:outputs/strings/true ../cmd/strings - <inputs/strings/true
  15. }
  16. atf_test_case true8elf
  17. true8elf_body() {
  18. atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 inputs/strings/true
  19. atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 <inputs/strings/true
  20. atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 - <inputs/strings/true
  21. }
  22. atf_test_case devnull
  23. devnull_body() {
  24. atf_check ../cmd/strings /dev/null
  25. atf_check ../cmd/strings </dev/null
  26. atf_check ../cmd/strings - </dev/null
  27. }
  28. atf_test_case devfull
  29. devfull_body() {
  30. has_glibc && atf_skip "glibc ignoring write errors for puts()"
  31. [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD ignoring write errors for puts()"
  32. [ "$(uname -s)" = "FreeBSD" ] && atf_skip "FreeBSD ignoring write errors for puts()"
  33. atf_check -s exit:1 -e 'inline:strings: Error writing: No space left on device\n' sh -c '../cmd/strings inputs/strings/true >/dev/full'
  34. }
  35. atf_test_case noperm cleanup
  36. noperm_body() {
  37. touch inputs/chmod_000 || atf_fail "touching chmod_000"
  38. chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
  39. # shellcheck disable=SC1112
  40. atf_check -s exit:1 -e 'inline:strings: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/strings inputs/chmod_000
  41. }
  42. noperm_cleanup() {
  43. chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
  44. rm inputs/chmod_000 || atf_fail "rm chmod_000"
  45. }
  46. atf_test_case octalformat
  47. octalformat_body() {
  48. atf_check -o file:outputs/strings/all_bytes_to ../cmd/strings -to inputs/all_bytes
  49. atf_check ../cmd/strings -to /dev/null
  50. atf_check -o file:outputs/strings/true_to ../cmd/strings -to inputs/strings/true
  51. atf_check -o file:outputs/strings/true_8_to ../cmd/strings -to -n 8 inputs/strings/true
  52. }
  53. atf_test_case hexformat
  54. hexformat_body() {
  55. atf_check -o file:outputs/strings/all_bytes_tx ../cmd/strings -tx inputs/all_bytes
  56. atf_check ../cmd/strings -tx /dev/null
  57. atf_check -o file:outputs/strings/true_tx ../cmd/strings -tx inputs/strings/true
  58. atf_check -o file:outputs/strings/true_8_tx ../cmd/strings -tx -n 8 inputs/strings/true
  59. }
  60. atf_test_case decformat
  61. decformat_body() {
  62. atf_check -o file:outputs/strings/all_bytes_td ../cmd/strings -td inputs/all_bytes
  63. atf_check ../cmd/strings -td /dev/null
  64. atf_check -o file:outputs/strings/true_td ../cmd/strings -td inputs/strings/true
  65. atf_check -o file:outputs/strings/true_8_td ../cmd/strings -td -n 8 inputs/strings/true
  66. }
  67. atf_test_case badformat
  68. badformat_body() {
  69. usage="strings: [-a] [-t format] [-n number] [file...]\n"
  70. atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/all_bytes
  71. atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt /dev/null
  72. atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/strings/true
  73. atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt -n 8 inputs/strings/true
  74. }
  75. atf_test_case erange_n
  76. erange_n_body() {
  77. usage="strings: [-a] [-t format] [-n number] [file...]\n"
  78. atf_check -s exit:1 -e "inline:strings: Option \`-n 0\` is too small\n${usage}" -- ../cmd/strings -n 0 inputs/all_bytes
  79. atf_check -s exit:1 -e "inline:strings: Option \`-n 4097\` is too large\n${usage}" -- ../cmd/strings -n 4097 inputs/all_bytes
  80. atf_check -s exit:1 -e "inline:strings: Option \`-n f\`: Invalid argument\n${usage}" -- ../cmd/strings -n f inputs/all_bytes
  81. atf_check -s exit:1 -e "inline:strings: Option \`-n 42f\`: Invalid argument\n${usage}" -- ../cmd/strings -n 42f inputs/all_bytes
  82. }
  83. atf_test_case usage
  84. usage_body() {
  85. atf_check -s exit:1 -e 'inline:strings: [-a] [-t format] [-n number] [file...]\n' ../cmd/strings -t aa inputs/all_bytes
  86. }
  87. atf_init_test_cases() {
  88. cd "$(atf_get_srcdir)" || exit 1
  89. . ../test_functions.sh
  90. atf_add_test_case allbytes
  91. atf_add_test_case trueelf
  92. atf_add_test_case true8elf
  93. atf_add_test_case devnull
  94. atf_add_test_case devfull
  95. atf_add_test_case noperm
  96. atf_add_test_case erange_n
  97. atf_add_test_case octalformat
  98. atf_add_test_case hexformat
  99. atf_add_test_case decformat
  100. atf_add_test_case badformat
  101. atf_add_test_case usage
  102. }