t_misc.sh revision 1.2
1#! /bin/sh 2# $NetBSD: t_misc.sh,v 1.2 2021/10/14 18:55:41 rillig Exp $ 3# 4# Copyright (c) 2021 The NetBSD Foundation, Inc. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26# POSSIBILITY OF SUCH DAMAGE. 27# 28# $FreeBSD$ 29 30# Tests for indent that do not follow the input-profile-output scheme that is 31# used in t_indent. 32 33indent=$(atf_config_get usr.bin.indent.test_indent /usr/bin/indent) 34nl=' 35' 36 37atf_test_case 'in_place' 38in_place_body() 39{ 40 cat <<-\EOF > code.c 41 int decl; 42 EOF 43 cat <<-\EOF > code.c.exp 44 int decl; 45 EOF 46 cp code.c code.c.orig 47 48 atf_check \ 49 env SIMPLE_BACKUP_SUFFIX=".bak" "$indent" code.c 50 atf_check -o 'file:code.c.exp' \ 51 cat code.c 52 atf_check -o 'file:code.c.orig' \ 53 cat code.c.bak 54} 55 56atf_test_case 'verbose_profile' 57verbose_profile_body() 58{ 59 cat <<-\EOF > .indent.pro 60 -/* comment */bacc 61 -v 62 -fc1 63 EOF 64 cat <<-\EOF > before.c 65 int decl; 66 EOF 67 cat <<-\EOF > after.c.exp 68 int decl; 69 EOF 70 cat <<-\EOF > stdout.exp 71 profile: -fc1 72 profile: -bacc 73 profile: -v 74 profile: -fc1 75 There were 1 output lines and 0 comments 76 (Lines with comments)/(Lines with code): 0.000 77 EOF 78 79 # The code in args.c function set_profile suggests that options from 80 # profile files are echoed to stdout during startup. But since the 81 # command line options are handled after the profile files, a '-v' in 82 # the command line has no effect. That's why '-bacc' is not listed 83 # in stdout, but '-fc1' is. The second round of '-bacc', '-v', '-fc1' 84 # is listed because when running ATF, $HOME equals $PWD. 85 86 atf_check \ 87 -o 'file:stdout.exp' \ 88 "$indent" -v before.c after.c 89 atf_check \ 90 -o 'file:after.c.exp' \ 91 cat after.c 92} 93 94atf_init_test_cases() 95{ 96 atf_add_test_case 'in_place' 97 atf_add_test_case 'verbose_profile' 98} 99