humanize (3336B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2023 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- atf_test_case one
- one_body() {
- atf_check -o "inline:1 \n" ../cmd/humanize 1
- atf_check -o "inline:1 \n" ../cmd/humanize -d 1
- atf_check -o "inline:1 B\n" ../cmd/humanize -b 1
- }
- atf_test_case two
- two_body() {
- atf_check -o "inline:12 \n" ../cmd/humanize 12
- atf_check -o "inline:12 \n" ../cmd/humanize -d 12
- atf_check -o "inline:12 B\n" ../cmd/humanize -b 12
- }
- atf_test_case three
- three_body() {
- atf_check -o "inline:123 \n" ../cmd/humanize 123
- atf_check -o "inline:123 \n" ../cmd/humanize -d 123
- atf_check -o "inline:123 B\n" ../cmd/humanize -b 123
- }
- # 1 234
- atf_test_case four
- four_body() {
- atf_check -o "inline:1.234 k\n" ../cmd/humanize 1234
- atf_check -o "inline:1.234 k\n" ../cmd/humanize -d 1234
- atf_check -o "inline:1.20508 KiB\n" ../cmd/humanize -b 1234
- }
- # 12 345
- atf_test_case five
- five_body() {
- atf_check -o "inline:12.345 k\n" ../cmd/humanize 12345
- atf_check -o "inline:12.345 k\n" ../cmd/humanize -d 12345
- atf_check -o "inline:12.0557 KiB\n" ../cmd/humanize -b 12345
- }
- # 123 456
- atf_test_case six
- six_body() {
- atf_check -o "inline:123.456 k\n" ../cmd/humanize 123456
- atf_check -o "inline:123.456 k\n" ../cmd/humanize -d 123456
- atf_check -o "inline:120.562 KiB\n" ../cmd/humanize -b 123456
- }
- # 1234 4567
- atf_test_case seven
- seven_body() {
- atf_check -o "inline:1.23457 M\n" ../cmd/humanize 1234567
- atf_check -o "inline:1.23457 M\n" ../cmd/humanize -d 1234567
- atf_check -o "inline:1.17737 MiB\n" ../cmd/humanize -b 1234567
- }
- atf_test_case noarg
- noarg_body() {
- atf_check -s exit:1 -e 'inline:Usage: humanize [-bdt] number\n' ../cmd/humanize
- }
- atf_test_case badflag
- badflag_body() {
- atf_check -s exit:1 -e "inline:humanize: Error: Unrecognised option: '-f'\n"'Usage: humanize [-bdt] number\n' ../cmd/humanize -f
- atf_check -s exit:1 -e "inline:humanize: Error: Unrecognised option: '-f'\n"'Usage: humanize [-bdt] number\n' ../cmd/humanize -f 123
- }
- atf_test_case duration
- duration_body() {
- atf_check -o "inline:1s\n" ../cmd/humanize -t 1
- atf_check -o "inline:1m \n" ../cmd/humanize -t 60
- atf_check -o "inline:1h \n" ../cmd/humanize -t 3600
- atf_check -o "inline:1日 \n" ../cmd/humanize -t 86400
- atf_check -o "inline:1月 \n" ../cmd/humanize -t 2629743
- atf_check -o "inline:1年 \n" ../cmd/humanize -t 31556926
- atf_check -o "inline:1年 1月 1日 1h 1m 1s\n" ../cmd/humanize -t 34276730
- }
- atf_test_case limits
- limits_body() {
- atf_check -o 'inline:9.22337 E\n' ../cmd/humanize 9223372036854775806
- atf_check -s exit:1 -e 'inline:humanize: 9223372036854775808 is too large\n' ../cmd/humanize 9223372036854775808
- # Not as great as it should but at least not a lie
- atf_check -o 'inline:-9.22337e+18 \n' ../cmd/humanize -- -9223372036854775807
- atf_check -s exit:1 -e 'inline:humanize: -9223372036854775809 is too small\n' ../cmd/humanize -- -9223372036854775809
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- atf_add_test_case noarg
- atf_add_test_case badflag
- atf_add_test_case limits
- atf_add_test_case one
- atf_add_test_case two
- atf_add_test_case three
- atf_add_test_case four
- atf_add_test_case five
- atf_add_test_case six
- atf_add_test_case seven
- atf_add_test_case duration
- }