humanize (2821B)
- #!/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:1D \n" ../cmd/humanize -t 86400
- atf_check -o "inline:1M \n" ../cmd/humanize -t 2629743
- atf_check -o "inline:1Y \n" ../cmd/humanize -t 31556926
- atf_check -o "inline:1Y 1M 1D 1h 1m 1s\n" ../cmd/humanize -t 34276730
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- atf_add_test_case noarg
- atf_add_test_case badflag
- 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
- }