1#- 2# SPDX-License-Identifier: BSD-2-Clause 3# 4# Copyright 2016 Dell EMC 5# All rights reserved. 6# Copyright (c) 2025 Klara, Inc. 7# 8# Redistribution and use in source and binary forms, with or without 9# modification, are permitted provided that the following conditions are 10# met: 11# 12# * Redistributions of source code must retain the above copyright 13# notice, this list of conditions and the following disclaimer. 14# * Redistributions in binary form must reproduce the above copyright 15# notice, this list of conditions and the following disclaimer in the 16# documentation and/or other materials provided with the distribution. 17# 18# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29# 30 31SRCDIR=$(atf_get_srcdir) 32 33check() 34{ 35 local tc=${1} 36 local profile_flag 37 38 cp "${SRCDIR}/${tc%.[0-9]}".* . 39 40 if [ -f "${tc}.pro" ]; then 41 profile_flag="-P${tc}.pro" 42 else 43 # Make sure we don't implicitly use ~/.indent.pro from the test 44 # host, for determinism purposes. 45 profile_flag="-npro" 46 fi 47 atf_check -s exit:${tc##*.} -o file:"${tc}.stdout" \ 48 indent ${profile_flag} < "${tc}" 49} 50 51add_legacy_testcase() 52{ 53 local tc=${1} 54 55 atf_test_case ${tc%.[0-9]} 56 eval "${tc%.[0-9]}_head() { atf_set \"require.progs\" indent; }" 57 eval "${tc%.[0-9]}_body() { check ${tc}; }" 58 atf_add_test_case ${tc%.[0-9]} 59} 60 61atf_test_case backup_suffix 62backup_suffix_head() 63{ 64 atf_set "require.progs" indent 65} 66backup_suffix_body() 67{ 68 local argmax=$(sysctl -n kern.argmax) 69 local suffix=$(jot -b .bak -s '' $((argmax/5))) 70 local code=$'int main() {}\n' 71 72 printf "${code}" >input.c 73 74 atf_check indent input.c 75 atf_check -o inline:"${code}" cat input.c.BAK 76 77 atf_check -s exit:1 -e match:"name too long"\ 78 env SIMPLE_BACKUP_SUFFIX=${suffix} indent input.c 79} 80 81atf_init_test_cases() 82{ 83 for tc in $(find -s "${SRCDIR}" -name '*.[0-9]'); do 84 add_legacy_testcase "${tc##*/}" 85 done 86 atf_add_test_case backup_suffix 87} 88