humanize (2878B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only
- atf_test_case one
- one_body() {
- atf_check -o "inline:1 \n" ../bin/humanize 1
- atf_check -o "inline:1 \n" ../bin/humanize -d 1
- atf_check -o "inline:1 B\n" ../bin/humanize -b 1
- }
- atf_test_case two
- two_body() {
- atf_check -o "inline:12 \n" ../bin/humanize 12
- atf_check -o "inline:12 \n" ../bin/humanize -d 12
- atf_check -o "inline:12 B\n" ../bin/humanize -b 12
- }
- atf_test_case three
- three_body() {
- atf_check -o "inline:123 \n" ../bin/humanize 123
- atf_check -o "inline:123 \n" ../bin/humanize -d 123
- atf_check -o "inline:123 B\n" ../bin/humanize -b 123
- }
- # 1 234
- atf_test_case four
- four_body() {
- atf_check -o "inline:1.234 k\n" ../bin/humanize 1234
- atf_check -o "inline:1.234 k\n" ../bin/humanize -d 1234
- atf_check -o "inline:1.20508 KiB\n" ../bin/humanize -b 1234
- }
- # 12 345
- atf_test_case five
- five_body() {
- atf_check -o "inline:12.345 k\n" ../bin/humanize 12345
- atf_check -o "inline:12.345 k\n" ../bin/humanize -d 12345
- atf_check -o "inline:12.0557 KiB\n" ../bin/humanize -b 12345
- }
- # 123 456
- atf_test_case six
- six_body() {
- atf_check -o "inline:123.456 k\n" ../bin/humanize 123456
- atf_check -o "inline:123.456 k\n" ../bin/humanize -d 123456
- atf_check -o "inline:120.562 KiB\n" ../bin/humanize -b 123456
- }
- # 1234 4567
- atf_test_case seven
- seven_body() {
- atf_check -o "inline:1.23457 M\n" ../bin/humanize 1234567
- atf_check -o "inline:1.23457 M\n" ../bin/humanize -d 1234567
- atf_check -o "inline:1.17737 MiB\n" ../bin/humanize -b 1234567
- }
- atf_test_case noarg
- noarg_body() {
- atf_check -s exit:1 -e 'inline:Usage: humanize [-bd] number\n' ../bin/humanize
- }
- atf_test_case badflag
- badflag_body() {
- atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../bin/humanize -f
- atf_check -s exit:1 -e "inline:Error: Unrecognised option: '-f'\n"'Usage: humanize [-bd] number\n' ../bin/humanize -f 123
- }
- atf_test_case limits
- limits_body() {
- atf_check -o 'inline:9.22337 E\n' ../bin/humanize 9223372036854775807
- atf_check -s exit:1 -e 'inline:humanize: strtonum: 9223372036854775808 is too large\n' ../bin/humanize 9223372036854775808
- # Not as great as it should but at least not a lie
- atf_check -o 'inline:-9.22337e+18 \n' ../bin/humanize -- -9223372036854775808
- atf_check -s exit:1 -e 'inline:humanize: strtonum: -9223372036854775809 is too small\n' ../bin/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
- }