logo

utils

~/.local/bin tools and git-hooks git clone https://hacktivis.me/git/utils.git

lolcat (3503B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
  4. atf_test_case allfile
  5. allfile_body() {
  6. atf_check -o file:outputs/lolcat/all_bytes ../bin/lolcat inputs/all_bytes
  7. }
  8. atf_test_case allinput
  9. allinput_body() {
  10. atf_check -o file:outputs/lolcat/all_bytes ../bin/lolcat <inputs/all_bytes
  11. }
  12. atf_test_case alldashinput
  13. alldashinput_body() {
  14. atf_check -o file:outputs/lolcat/all_bytes ../bin/lolcat - <inputs/all_bytes
  15. }
  16. atf_test_case devnull
  17. devnull_body() {
  18. if [ "$(uname -s)" = "FreeBSD" ] || [ "$(uname -s)" = "NetBSD" ]; then
  19. # FIXME
  20. atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../bin/lolcat /dev/null
  21. atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../bin/lolcat </dev/null
  22. atf_check -s exit:1 -e 'inline:\nRead error: Inappropriate ioctl for device\n' -o 'inline:' ../bin/lolcat - </dev/null
  23. else
  24. atf_check -o 'inline:' ../bin/lolcat /dev/null
  25. atf_check -o 'inline:' ../bin/lolcat </dev/null
  26. atf_check -o 'inline:' ../bin/lolcat - </dev/null
  27. fi
  28. }
  29. atf_test_case noperm cleanup
  30. noperm_body() {
  31. touch inputs/chmod_000 || atf_fail "touching chmod_000"
  32. chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
  33. # shellcheck disable=SC1112
  34. atf_check -s exit:1 -e 'inline:\nError opening ‘inputs/chmod_000’: Permission denied\n' -o 'inline:' ../bin/lolcat inputs/chmod_000
  35. }
  36. noperm_cleanup() {
  37. chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
  38. rm inputs/chmod_000 || atf_fail "rm chmod_000"
  39. }
  40. atf_test_case devfull
  41. devfull_body() {
  42. has_glibc && atf_expect_fail "glibc ignoring write errors for fputc()"
  43. [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD badly handling write errors"
  44. [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD badly handling write errors"
  45. atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/lolcat inputs/all_bytes >/dev/full'
  46. atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/lolcat <inputs/all_bytes >/dev/full'
  47. atf_check -s exit:1 -e 'inline:\nError writing: No space left on device\n' sh -c '../bin/lolcat - <inputs/all_bytes >/dev/full'
  48. }
  49. atf_test_case readslash
  50. readslash_body() {
  51. [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD allows to read directories"
  52. # shellcheck disable=SC1112
  53. atf_check -s exit:1 -e 'inline:\nRead error: Is a directory\n' -o 'inline:' ../bin/lolcat ./
  54. }
  55. atf_test_case enoent
  56. enoent_body() {
  57. # shellcheck disable=SC1112
  58. atf_check -s exit:1 -e 'inline:\nError opening ‘/var/empty/e/no/ent’: No such file or directory\n' -o 'inline:' ../bin/lolcat /var/empty/e/no/ent
  59. }
  60. atf_test_case doubledash
  61. doubledash_body() {
  62. atf_check -o file:outputs/lolcat/all_bytes -- ../bin/lolcat -- inputs/all_bytes
  63. # shellcheck disable=SC1112
  64. atf_check -s exit:1 -e 'inline:\nError opening ‘---’: No such file or directory\n' -o 'inline:' -- ../bin/lolcat --- inputs/all_bytes
  65. }
  66. atf_init_test_cases() {
  67. cd "$(atf_get_srcdir)" || exit 1
  68. . ../test_functions.sh
  69. atf_add_test_case allfile
  70. atf_add_test_case allinput
  71. atf_add_test_case alldashinput
  72. atf_add_test_case devnull
  73. atf_add_test_case noperm
  74. atf_add_test_case devfull
  75. atf_add_test_case readslash
  76. atf_add_test_case enoent
  77. atf_add_test_case doubledash
  78. }