Home | History | Annotate | Line # | Download | only in lint1
t_integration.sh revision 1.63
      1  1.63  rillig # $NetBSD: t_integration.sh,v 1.63 2021/06/27 19:41:15 rillig Exp $
      2   1.1  jruoho #
      3   1.1  jruoho # Copyright (c) 2008, 2010 The NetBSD Foundation, Inc.
      4   1.1  jruoho # All rights reserved.
      5   1.1  jruoho #
      6   1.1  jruoho # Redistribution and use in source and binary forms, with or without
      7   1.1  jruoho # modification, are permitted provided that the following conditions
      8   1.1  jruoho # are met:
      9   1.1  jruoho # 1. Redistributions of source code must retain the above copyright
     10   1.1  jruoho #    notice, this list of conditions and the following disclaimer.
     11   1.1  jruoho # 2. Redistributions in binary form must reproduce the above copyright
     12   1.1  jruoho #    notice, this list of conditions and the following disclaimer in the
     13   1.1  jruoho #    documentation and/or other materials provided with the distribution.
     14   1.1  jruoho #
     15   1.1  jruoho # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     16   1.1  jruoho # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     17   1.1  jruoho # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     18   1.1  jruoho # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     19   1.1  jruoho # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     20   1.1  jruoho # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     21   1.1  jruoho # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     22   1.1  jruoho # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     23   1.1  jruoho # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     24   1.1  jruoho # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     25   1.1  jruoho # POSSIBILITY OF SUCH DAMAGE.
     26   1.1  jruoho #
     27   1.1  jruoho 
     28  1.51  rillig lint1=/usr/libexec/lint1
     29  1.51  rillig 
     30  1.59  rillig machine_arch="$(sysctl -n hw.machine_arch)"
     31   1.1  jruoho 
     32   1.1  jruoho 
     33  1.59  rillig configure_test_case()
     34  1.25  rillig {
     35  1.59  rillig 	local awk
     36  1.25  rillig 
     37  1.25  rillig 	# shellcheck disable=SC2016
     38  1.59  rillig 	awk='
     39  1.25  rillig 		BEGIN {
     40  1.59  rillig 			machine_arch = "'"$machine_arch"'"
     41  1.25  rillig 			flags = "-g -S -w"
     42  1.59  rillig 			skip = 0
     43  1.25  rillig 		}
     44  1.25  rillig 		/^\/\* (lint1-flags|lint1-extra-flags): .*\*\/$/ {
     45  1.25  rillig 			if ($2 == "lint1-flags:")
     46  1.25  rillig 				flags = ""
     47  1.25  rillig 			for (i = 3; i < NF; i++)
     48  1.25  rillig 				flags = flags " " $i
     49  1.25  rillig 		}
     50  1.59  rillig 		/^\/\* lint1-only-on-arch: .* \*\/$/ && $3 != machine_arch {
     51  1.59  rillig 			skip = 1
     52  1.59  rillig 		}
     53  1.59  rillig 		/^\/\* lint1-not-on-arch: .* \*\/$/ && $3 == machine_arch {
     54  1.59  rillig 			skip = 1
     55  1.59  rillig 		}
     56  1.25  rillig 		END {
     57  1.59  rillig 			printf("flags='\''%s'\''\n", flags)
     58  1.59  rillig 			printf("skip=%s\n", skip ? "yes" : "no")
     59  1.25  rillig 		}
     60  1.25  rillig 	'
     61  1.25  rillig 
     62  1.59  rillig 	eval "$(awk "$awk" "$1")"
     63  1.25  rillig }
     64  1.25  rillig 
     65  1.25  rillig # shellcheck disable=SC2155
     66   1.9  rillig check_lint1()
     67   1.1  jruoho {
     68   1.6  rillig 	local src="$(atf_get_srcdir)/$1"
     69   1.6  rillig 	local exp="${src%.c}.exp"
     70  1.63  rillig 	local exp_ln="${src%.c}.exp-ln"
     71  1.43  rillig 	local wrk_ln="${1%.c}.ln"
     72  1.59  rillig 	local flags=""
     73  1.59  rillig 	local skip=""
     74   1.6  rillig 
     75  1.58  rillig 	if [ ! -f "$exp_ln" ]; then
     76  1.58  rillig 		exp_ln='/dev/null'
     77  1.51  rillig 		wrk_ln='/dev/null'
     78  1.43  rillig 	fi
     79  1.43  rillig 
     80  1.59  rillig 	configure_test_case "$src"
     81  1.59  rillig 
     82  1.59  rillig 	if [ "$skip" = "yes" ]; then
     83  1.59  rillig 		atf_check -o 'ignore' echo 'skipped'
     84  1.59  rillig 		return
     85  1.59  rillig 	fi
     86  1.59  rillig 
     87  1.51  rillig 	if [ -f "$exp" ]; then
     88  1.25  rillig 		# shellcheck disable=SC2086
     89  1.51  rillig 		atf_check -s not-exit:0 -o "file:$exp" -e empty \
     90  1.51  rillig 		    "$lint1" $flags "$src" "$wrk_ln"
     91   1.9  rillig 	else
     92  1.25  rillig 		# shellcheck disable=SC2086
     93   1.9  rillig 		atf_check -s exit:0 \
     94  1.51  rillig 		    "$lint1" $flags "$src" "$wrk_ln"
     95  1.43  rillig 	fi
     96  1.43  rillig 
     97  1.59  rillig 	if [ "$exp_ln" != '/dev/null' ]; then
     98  1.58  rillig 		atf_check -o "file:$exp_ln" cat "$wrk_ln"
     99   1.9  rillig 	fi
    100   1.1  jruoho }
    101   1.1  jruoho 
    102  1.62  rillig atf_init_test_cases()
    103   1.1  jruoho {
    104  1.62  rillig 	local src name
    105  1.18  rillig 
    106  1.62  rillig 	for src in "$(atf_get_srcdir)"/*.c; do
    107  1.62  rillig 		src=${src##*/}
    108  1.62  rillig 		name=${src%.c}
    109  1.62  rillig 
    110  1.62  rillig 		atf_test_case "$name"
    111  1.62  rillig 		eval "${name}_head() {
    112  1.62  rillig 			atf_set 'require.progs' '$lint1'
    113  1.62  rillig 		}"
    114  1.62  rillig 		eval "${name}_body() {
    115  1.62  rillig 			check_lint1 '$name.c'
    116  1.62  rillig 		}"
    117  1.51  rillig 		atf_add_test_case "$name"
    118   1.1  jruoho 	done
    119   1.1  jruoho }
    120