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]}_body() { check ${tc}; }" 57 atf_add_test_case ${tc%.[0-9]} 58} 59 60atf_test_case backup_suffix 61backup_suffix_body() 62{ 63 local argmax=$(sysctl -n kern.argmax) 64 local suffix=$(jot -b .bak -s '' $((argmax/5))) 65 local code=$'int main() {}\n' 66 67 printf "${code}" >input.c 68 69 atf_check indent input.c 70 atf_check -o inline:"${code}" cat input.c.BAK 71 72 atf_check -s exit:1 -e match:"name too long"\ 73 env SIMPLE_BACKUP_SUFFIX=${suffix} indent input.c 74} 75 76atf_init_test_cases() 77{ 78 for tc in $(find -s "${SRCDIR}" -name '*.[0-9]'); do 79 add_legacy_testcase "${tc##*/}" 80 done 81 atf_add_test_case backup_suffix 82} 83