logo

utils

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

humanize (2878B)


  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 one
  5. one_body() {
  6. atf_check -o "inline:1 \n" ../bin/humanize 1
  7. atf_check -o "inline:1 \n" ../bin/humanize -d 1
  8. atf_check -o "inline:1 B\n" ../bin/humanize -b 1
  9. }
  10. atf_test_case two
  11. two_body() {
  12. atf_check -o "inline:12 \n" ../bin/humanize 12
  13. atf_check -o "inline:12 \n" ../bin/humanize -d 12
  14. atf_check -o "inline:12 B\n" ../bin/humanize -b 12
  15. }
  16. atf_test_case three
  17. three_body() {
  18. atf_check -o "inline:123 \n" ../bin/humanize 123
  19. atf_check -o "inline:123 \n" ../bin/humanize -d 123
  20. atf_check -o "inline:123 B\n" ../bin/humanize -b 123
  21. }
  22. # 1 234
  23. atf_test_case four
  24. four_body() {
  25. atf_check -o "inline:1.234 k\n" ../bin/humanize 1234
  26. atf_check -o "inline:1.234 k\n" ../bin/humanize -d 1234
  27. atf_check -o "inline:1.20508 KiB\n" ../bin/humanize -b 1234
  28. }
  29. # 12 345
  30. atf_test_case five
  31. five_body() {
  32. atf_check -o "inline:12.345 k\n" ../bin/humanize 12345
  33. atf_check -o "inline:12.345 k\n" ../bin/humanize -d 12345
  34. atf_check -o "inline:12.0557 KiB\n" ../bin/humanize -b 12345
  35. }
  36. # 123 456
  37. atf_test_case six
  38. six_body() {
  39. atf_check -o "inline:123.456 k\n" ../bin/humanize 123456
  40. atf_check -o "inline:123.456 k\n" ../bin/humanize -d 123456
  41. atf_check -o "inline:120.562 KiB\n" ../bin/humanize -b 123456
  42. }
  43. # 1234 4567
  44. atf_test_case seven
  45. seven_body() {
  46. atf_check -o "inline:1.23457 M\n" ../bin/humanize 1234567
  47. atf_check -o "inline:1.23457 M\n" ../bin/humanize -d 1234567
  48. atf_check -o "inline:1.17737 MiB\n" ../bin/humanize -b 1234567
  49. }
  50. atf_test_case noarg
  51. noarg_body() {
  52. atf_check -s exit:1 -e 'inline:Usage: humanize [-bd] number\n' ../bin/humanize
  53. }
  54. atf_test_case badflag
  55. badflag_body() {
  56. atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../bin/humanize -f
  57. atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../bin/humanize -f 123
  58. }
  59. atf_test_case limits
  60. limits_body() {
  61. atf_check -o 'inline:9.22337 E\n' ../bin/humanize 9223372036854775807
  62. atf_check -s exit:1 -e 'inline:humanize: strtonum: 9223372036854775808 is too large\n' ../bin/humanize 9223372036854775808
  63. # Not as great as it should but at least not a lie
  64. atf_check -o 'inline:-9.22337e+18 \n' ../bin/humanize -- -9223372036854775808
  65. atf_check -s exit:1 -e 'inline:humanize: strtonum: -9223372036854775809 is too small\n' ../bin/humanize -- -9223372036854775809
  66. }
  67. atf_init_test_cases() {
  68. cd "$(atf_get_srcdir)" || exit 1
  69. atf_add_test_case noarg
  70. atf_add_test_case badflag
  71. atf_add_test_case limits
  72. atf_add_test_case one
  73. atf_add_test_case two
  74. atf_add_test_case three
  75. atf_add_test_case four
  76. atf_add_test_case five
  77. atf_add_test_case six
  78. atf_add_test_case seven
  79. }