logo

utils

Old programs, got split in utils-std and utils-extra git clone https://hacktivis.me/git/utils.git

humanize (3336B)


  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:1日 \n" ../cmd/humanize -t 86400
  65. atf_check -o "inline:1月 \n" ../cmd/humanize -t 2629743
  66. atf_check -o "inline:1年 \n" ../cmd/humanize -t 31556926
  67. atf_check -o "inline:1年 1月 1日 1h 1m 1s\n" ../cmd/humanize -t 34276730
  68. }
  69. atf_test_case limits
  70. limits_body() {
  71. atf_check -o 'inline:9.22337 E\n' ../cmd/humanize 9223372036854775806
  72. atf_check -s exit:1 -e 'inline:humanize: 9223372036854775808 is too large\n' ../cmd/humanize 9223372036854775808
  73. # Not as great as it should but at least not a lie
  74. atf_check -o 'inline:-9.22337e+18 \n' ../cmd/humanize -- -9223372036854775807
  75. atf_check -s exit:1 -e 'inline:humanize: -9223372036854775809 is too small\n' ../cmd/humanize -- -9223372036854775809
  76. }
  77. atf_init_test_cases() {
  78. cd "$(atf_get_srcdir)" || exit 1
  79. atf_add_test_case noarg
  80. atf_add_test_case badflag
  81. atf_add_test_case limits
  82. atf_add_test_case one
  83. atf_add_test_case two
  84. atf_add_test_case three
  85. atf_add_test_case four
  86. atf_add_test_case five
  87. atf_add_test_case six
  88. atf_add_test_case seven
  89. atf_add_test_case duration
  90. }