xref: /netbsd-src/tests/usr.bin/indent/t_options.sh (revision a9183f83beb7f43ae2cb193c2d288de58f4bf340)
1#! /bin/sh
2# $NetBSD: t_options.sh,v 1.11 2023/05/20 21:32:05 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# Tests for indent that focus on comparing the effects of the various command
29# line options.
30#
31# The test files contain the input to be formatted, the formatting options
32# and the output, all as close together as possible. The test files use the
33# following directives:
34#
35#	//indent input [description]
36#		Specifies the input to be formatted.
37#	//indent run [options]
38#		Runs indent on the input, using the given options.
39#	//indent end [description]
40#		Finishes an '//indent input' or '//indent run' section.
41#	//indent run-equals-input [options]
42#		Runs indent on the input, expecting unmodified output.
43#	//indent run-equals-prev-output [options]
44#		Runs indent on the input, expecting the same output as from
45#		the previous run.
46#
47# All text outside these directives is not passed to indent.
48
49srcdir=$(atf_get_srcdir)
50indent=$(atf_config_get usr.bin.indent.test_indent /usr/bin/indent)
51
52check()
53{
54	atf_check -o "file:expected.out" \
55	    env INDENT="$indent" lua "$srcdir/t_options.lua" "$srcdir/$1.c"
56}
57
58atf_init_test_cases()
59{
60	for fname in "$srcdir"/*.c; do
61		test_name=${fname##*/}
62		test_name=${test_name%.c}
63
64		atf_test_case "$test_name"
65		eval "${test_name}_body() { check '$test_name'; }"
66		atf_add_test_case "$test_name"
67	done
68}
69