strings (4797B)
- #!/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 allbytes
- allbytes_body() {
- atf_check -o file:outputs/strings/all_bytes ../cmd/strings inputs/all_bytes
- atf_check -o file:outputs/strings/all_bytes ../cmd/strings <inputs/all_bytes
- atf_check -o file:outputs/strings/all_bytes ../cmd/strings - <inputs/all_bytes
- }
- atf_test_case trueelf
- trueelf_body() {
- atf_check -o file:outputs/strings/true ../cmd/strings inputs/strings/true
- atf_check -o file:outputs/strings/true ../cmd/strings <inputs/strings/true
- atf_check -o file:outputs/strings/true ../cmd/strings - <inputs/strings/true
- }
- atf_test_case true8elf
- true8elf_body() {
- atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 inputs/strings/true
- atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 <inputs/strings/true
- atf_check -o file:outputs/strings/true_8 ../cmd/strings -n 8 - <inputs/strings/true
- }
- atf_test_case devnull
- devnull_body() {
- atf_check ../cmd/strings /dev/null
- atf_check ../cmd/strings </dev/null
- atf_check ../cmd/strings - </dev/null
- }
- 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:strings: Error writing: No space left on device\n' sh -c '../cmd/strings inputs/strings/true >/dev/full'
- }
- 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:strings: Error opening ‘inputs/chmod_000’: Permission denied\n' ../cmd/strings 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 octalformat
- octalformat_body() {
- atf_check -o file:outputs/strings/all_bytes_to ../cmd/strings -to inputs/all_bytes
- atf_check ../cmd/strings -to /dev/null
- atf_check -o file:outputs/strings/true_to ../cmd/strings -to inputs/strings/true
- atf_check -o file:outputs/strings/true_8_to ../cmd/strings -to -n 8 inputs/strings/true
- }
- atf_test_case hexformat
- hexformat_body() {
- atf_check -o file:outputs/strings/all_bytes_tx ../cmd/strings -tx inputs/all_bytes
- atf_check ../cmd/strings -tx /dev/null
- atf_check -o file:outputs/strings/true_tx ../cmd/strings -tx inputs/strings/true
- atf_check -o file:outputs/strings/true_8_tx ../cmd/strings -tx -n 8 inputs/strings/true
- }
- atf_test_case decformat
- decformat_body() {
- atf_check -o file:outputs/strings/all_bytes_td ../cmd/strings -td inputs/all_bytes
- atf_check ../cmd/strings -td /dev/null
- atf_check -o file:outputs/strings/true_td ../cmd/strings -td inputs/strings/true
- atf_check -o file:outputs/strings/true_8_td ../cmd/strings -td -n 8 inputs/strings/true
- }
- atf_test_case badformat
- badformat_body() {
- usage="strings: [-a] [-t format] [-n number] [file...]\n"
- atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/all_bytes
- atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt /dev/null
- atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt inputs/strings/true
- atf_check -s exit:1 -e "inline:strings: Unknown format: t\n${usage}" ../cmd/strings -tt -n 8 inputs/strings/true
- }
- atf_test_case erange_n
- erange_n_body() {
- usage="strings: [-a] [-t format] [-n number] [file...]\n"
- atf_check -s exit:1 -e "inline:strings: Option \`-n 0\` is too small\n${usage}" -- ../cmd/strings -n 0 inputs/all_bytes
- atf_check -s exit:1 -e "inline:strings: Option \`-n 4097\` is too large\n${usage}" -- ../cmd/strings -n 4097 inputs/all_bytes
- atf_check -s exit:1 -e "inline:strings: Option \`-n f\`: Invalid argument\n${usage}" -- ../cmd/strings -n f inputs/all_bytes
- atf_check -s exit:1 -e "inline:strings: Option \`-n 42f\`: Invalid argument\n${usage}" -- ../cmd/strings -n 42f inputs/all_bytes
- }
- atf_test_case usage
- usage_body() {
- atf_check -s exit:1 -e 'inline:strings: [-a] [-t format] [-n number] [file...]\n' ../cmd/strings -t aa inputs/all_bytes
- }
- atf_init_test_cases() {
- cd "$(atf_get_srcdir)" || exit 1
- . ../test_functions.sh
- atf_add_test_case allbytes
- atf_add_test_case trueelf
- atf_add_test_case true8elf
- atf_add_test_case devnull
- atf_add_test_case devfull
- atf_add_test_case noperm
- atf_add_test_case erange_n
- atf_add_test_case octalformat
- atf_add_test_case hexformat
- atf_add_test_case decformat
- atf_add_test_case badformat
- atf_add_test_case usage
- }