logo

utils-extra

Collection of extra tools for Unixes git clone https://anongit.hacktivis.me/git/utils-extra.git/

humanize (2821B)


  1. #!/usr/bin/env atf-sh
  2. # SPDX-FileCopyrightText: 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
  3. # SPDX-License-Identifier: MPL-2.0
  4. atf_test_case one
  5. one_body() {
  6. atf_check -o "inline:1 \n" ../cmd/humanize 1
  7. atf_check -o "inline:1 \n" ../cmd/humanize -d 1
  8. atf_check -o "inline:1 B\n" ../cmd/humanize -b 1
  9. }
  10. atf_test_case two
  11. two_body() {
  12. atf_check -o "inline:12 \n" ../cmd/humanize 12
  13. atf_check -o "inline:12 \n" ../cmd/humanize -d 12
  14. atf_check -o "inline:12 B\n" ../cmd/humanize -b 12
  15. }
  16. atf_test_case three
  17. three_body() {
  18. atf_check -o "inline:123 \n" ../cmd/humanize 123
  19. atf_check -o "inline:123 \n" ../cmd/humanize -d 123
  20. atf_check -o "inline:123 B\n" ../cmd/humanize -b 123
  21. }
  22. # 1 234
  23. atf_test_case four
  24. four_body() {
  25. atf_check -o "inline:1.234 k\n" ../cmd/humanize 1234
  26. atf_check -o "inline:1.234 k\n" ../cmd/humanize -d 1234
  27. atf_check -o "inline:1.20508 KiB\n" ../cmd/humanize -b 1234
  28. }
  29. # 12 345
  30. atf_test_case five
  31. five_body() {
  32. atf_check -o "inline:12.345 k\n" ../cmd/humanize 12345
  33. atf_check -o "inline:12.345 k\n" ../cmd/humanize -d 12345
  34. atf_check -o "inline:12.0557 KiB\n" ../cmd/humanize -b 12345
  35. }
  36. # 123 456
  37. atf_test_case six
  38. six_body() {
  39. atf_check -o "inline:123.456 k\n" ../cmd/humanize 123456
  40. atf_check -o "inline:123.456 k\n" ../cmd/humanize -d 123456
  41. atf_check -o "inline:120.562 KiB\n" ../cmd/humanize -b 123456
  42. }
  43. # 1234 4567
  44. atf_test_case seven
  45. seven_body() {
  46. atf_check -o "inline:1.23457 M\n" ../cmd/humanize 1234567
  47. atf_check -o "inline:1.23457 M\n" ../cmd/humanize -d 1234567
  48. atf_check -o "inline:1.17737 MiB\n" ../cmd/humanize -b 1234567
  49. }
  50. atf_test_case noarg
  51. noarg_body() {
  52. atf_check -s exit:1 -e 'inline:Usage: humanize [-bdt] number\n' ../cmd/humanize
  53. }
  54. atf_test_case badflag
  55. badflag_body() {
  56. atf_check -s exit:1 -e "inline:humanize: Error: Unrecognised option: '-f'\n"'Usage: humanize [-bdt] number\n' ../cmd/humanize -f
  57. atf_check -s exit:1 -e "inline:humanize: Error: Unrecognised option: '-f'\n"'Usage: humanize [-bdt] number\n' ../cmd/humanize -f 123
  58. }
  59. atf_test_case duration
  60. duration_body() {
  61. atf_check -o "inline:1s\n" ../cmd/humanize -t 1
  62. atf_check -o "inline:1m \n" ../cmd/humanize -t 60
  63. atf_check -o "inline:1h \n" ../cmd/humanize -t 3600
  64. atf_check -o "inline:1D \n" ../cmd/humanize -t 86400
  65. atf_check -o "inline:1M \n" ../cmd/humanize -t 2629743
  66. atf_check -o "inline:1Y \n" ../cmd/humanize -t 31556926
  67. atf_check -o "inline:1Y 1M 1D 1h 1m 1s\n" ../cmd/humanize -t 34276730
  68. }
  69. atf_init_test_cases() {
  70. cd "$(atf_get_srcdir)" || exit 1
  71. atf_add_test_case noarg
  72. atf_add_test_case badflag
  73. atf_add_test_case one
  74. atf_add_test_case two
  75. atf_add_test_case three
  76. atf_add_test_case four
  77. atf_add_test_case five
  78. atf_add_test_case six
  79. atf_add_test_case seven
  80. atf_add_test_case duration
  81. }