basename (2331B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017-2022 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- atf_test_case noargs
- noargs_body() {
- atf_check -o "inline:.\n" ../cmd/basename
- }
- atf_test_case one_slash
- one_slash_body() {
- atf_check -o "inline:bin\n" ../cmd/basename "/usr/bin"
- }
- atf_test_case two_slash
- two_slash_body() {
- atf_check -o "inline:bin\n" ../cmd/basename "/usr//bin"
- }
- atf_test_case two_dash
- two_dash_body() {
- atf_check -o "inline:bin\n" ../cmd/basename -- "/usr//bin"
- }
- atf_test_case testopt
- testopt_body() {
- atf_check -o "inline:bin\n" ../cmd/basename "/usr//bin-test" "-test"
- }
- atf_test_case usage
- usage_body() {
- atf_check -s exit:1 -e "inline:usage: basename string [suffix]\n" ../cmd/basename 1 2 3
- }
- atf_test_case devfull
- devfull_body() {
- has_glibc && atf_expect_fail "glibc ignoring write errors for puts()"
- [ "$(uname -s)" = "NetBSD" ] && atf_expect_fail "NetBSD ignoring write errors for puts()"
- [ "$(uname -s)" = "FreeBSD" ] && atf_expect_fail "FreeBSD ignoring write errors for puts()"
- atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename >/dev/full'
- atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename "/usr/bin" >/dev/full'
- atf_check -s exit:1 -e 'inline:basename: puts: No space left on device\n' sh -c '../cmd/basename "/usr//bin-test" "-test" >/dev/full'
- }
- atf_test_case nullarg
- nullarg_body() {
- atf_check -e "inline:.\n" ../cmd/basename "$(printf '\x00')"
- atf_check -e "inline:bin\n" ../cmd/basename "/usr/bin" "$(printf '\x00')"
- }
- atf_test_case doubledash
- doubledash_body() {
- atf_check -o 'inline:-\n' -- ../cmd/basename '-'
- atf_check -o 'inline:.\n' -- ../cmd/basename '--'
- atf_check -o 'inline:--\n' -- ../cmd/basename --a a
- atf_check -o 'inline:---\n' -- ../cmd/basename '---'
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- . ../test_functions.sh
- atf_add_test_case noargs
- atf_add_test_case one_slash
- atf_add_test_case two_slash
- atf_add_test_case two_dash
- atf_add_test_case testopt
- atf_add_test_case usage
- # puts in glibc doesn't returns -1 on failure
- atf_add_test_case devfull
- # Broken behavior in ATF, might be caused by stripping out \x00
- #atf_add_test_case nullarg
- atf_add_test_case doubledash
- }