base64 (5217B)
- #!/usr/bin/env atf-sh
- # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
- # SPDX-License-Identifier: MPL-2.0
- atf_test_case allbytes
- allbytes_body() {
- atf_check -o file:outputs/base64/all_bytes ../cmd/base64 inputs/all_bytes
- atf_check -o file:outputs/base64/all_bytes ../cmd/base64 <inputs/all_bytes
- atf_check -o file:outputs/base64/all_bytes ../cmd/base64 - <inputs/all_bytes
- }
- atf_test_case devnull
- devnull_body() {
- atf_check ../cmd/base64 /dev/null
- atf_check ../cmd/base64 </dev/null
- atf_check ../cmd/base64 - </dev/null
- }
- # Test vectors from RFC4648
- atf_test_case rfc4648_encode
- rfc4648_encode_body() {
- atf_check -o 'inline:' sh -c 'printf "" | ../cmd/base64'
- atf_check -o 'inline:Zg==\n' sh -c 'printf "f" | ../cmd/base64'
- atf_check -o 'inline:Zm8=\n' sh -c 'printf "fo" | ../cmd/base64'
- atf_check -o 'inline:Zm9v\n' sh -c 'printf "foo" | ../cmd/base64'
- atf_check -o 'inline:Zm9vYg==\n' sh -c 'printf "foob" | ../cmd/base64'
- atf_check -o 'inline:Zm9vYmE=\n' sh -c 'printf "fooba" | ../cmd/base64'
- atf_check -o 'inline:Zm9vYmFy\n' sh -c 'printf "foobar" | ../cmd/base64'
- }
- atf_test_case rfc4648_decode
- rfc4648_decode_body() {
- atf_check -o 'inline:' sh -c 'printf "" | ../cmd/base64 -d'
- atf_check -o 'inline:f' sh -c 'printf "Zg==\n" | ../cmd/base64 -d'
- atf_check -o 'inline:fo' sh -c 'printf "Zm8=\n" | ../cmd/base64 -d'
- atf_check -o 'inline:foo' sh -c 'printf "Zm9v\n" | ../cmd/base64 -d'
- atf_check -o 'inline:foob' sh -c 'printf "Zm9vYg==\n" | ../cmd/base64 -d'
- atf_check -o 'inline:fooba' sh -c 'printf "Zm9vYmE=\n" | ../cmd/base64 -d'
- atf_check -o 'inline:foobar' sh -c 'printf "Zm9vYmFy\n" | ../cmd/base64 -d'
- }
- atf_test_case multiliner_encode
- multiliner_encode_body() {
- atf_check -o file:inputs/base64/true_w76 ../cmd/base64 outputs/base64/true
- atf_check -o file:inputs/base64/true_w76 ../cmd/base64 <outputs/base64/true
- atf_check -o file:inputs/base64/true_w76 ../cmd/base64 - <outputs/base64/true
- }
- atf_test_case multiliner_decode
- multiliner_decode_body() {
- atf_check -o file:outputs/base64/true ../cmd/base64 -d inputs/base64/true_w76
- atf_check -o file:outputs/base64/true ../cmd/base64 -d <inputs/base64/true_w76
- atf_check -o file:outputs/base64/true ../cmd/base64 -d - <inputs/base64/true_w76
- }
- atf_test_case oneliner_encode
- oneliner_encode_body() {
- atf_check -o file:inputs/base64/true_w0 ../cmd/base64 -w0 outputs/base64/true
- atf_check -o file:inputs/base64/true_w0 ../cmd/base64 -w0 <outputs/base64/true
- atf_check -o file:inputs/base64/true_w0 ../cmd/base64 -w0 - <outputs/base64/true
- }
- atf_test_case oneliner_decode
- oneliner_decode_body() {
- atf_check -o file:outputs/base64/true ../cmd/base64 -d inputs/base64/true_w0
- atf_check -o file:outputs/base64/true ../cmd/base64 -d <inputs/base64/true_w0
- atf_check -o file:outputs/base64/true ../cmd/base64 -d - <inputs/base64/true_w0
- }
- atf_test_case noperm cleanup
- noperm_body() {
- touch inputs/chmod_000 || atf_fail "touching chmod_000"
- chmod 0000 inputs/chmod_000 || atf_fail "chmod 0000 chmod_000"
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:base64: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/base64 inputs/chmod_000
- }
- noperm_cleanup() {
- chmod 0600 inputs/chmod_000 || atf_fail "chmod 0600 chmod_000"
- rm inputs/chmod_000 || atf_fail "rm chmod_000"
- }
- atf_test_case devfull
- devfull_body() {
- error='inline:base64: Error writing: No space left on device\n'
- [ "$(uname -s)" = "NetBSD" ] && error='inline:base64: Error writing: Inappropriate ioctl for device\n'
- [ "$(uname -s)" = "FreeBSD" ] && error='inline:base64: Error writing: Inappropriate ioctl for device\n'
- atf_check -s exit:1 -e "$error" sh -c '../cmd/base64 inputs/all_bytes >/dev/full'
- atf_check -s exit:1 -e "$error" sh -c '../cmd/base64 <inputs/all_bytes >/dev/full'
- atf_check -s exit:1 -e "$error" sh -c '../cmd/base64 - <inputs/all_bytes >/dev/full'
- }
- atf_test_case readslash
- readslash_body() {
- [ "$(uname -s)" = "NetBSD" ] && atf_skip "NetBSD allows to read directories"
- atf_check -s exit:1 -e "inline:base64: Error reading ‘/’: Is a directory\n" ../cmd/base64 /
- }
- atf_test_case enoent
- enoent_body() {
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e 'inline:base64: Error opening ‘/var/empty/e/no/ent’: No such file or directory\n' ../cmd/base64 /var/empty/e/no/ent
- }
- atf_test_case doubledash
- doubledash_body() {
- atf_check -o file:outputs/base64/all_bytes -- ../cmd/base64 -- inputs/all_bytes
- # shellcheck disable=SC1112
- atf_check -s exit:1 -e "inline:base64: Error: Unrecognised option: ‘--’\n" -o empty -- ../cmd/base64 --- inputs/all_bytes
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- atf_add_test_case rfc4648_encode
- atf_add_test_case rfc4648_decode
- atf_add_test_case multiliner_encode
- atf_add_test_case multiliner_decode
- atf_add_test_case oneliner_encode
- atf_add_test_case oneliner_decode
- atf_add_test_case allbytes
- atf_add_test_case devnull
- atf_add_test_case noperm
- atf_add_test_case devfull
- # Somehow you can fopen directories…
- #atf_add_test_case readslash
- atf_add_test_case enoent
- atf_add_test_case doubledash
- }